forked from Enabling/CloudengineScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SMS - lovebot sample
47 lines (39 loc) · 1.76 KB
/
SMS - lovebot sample
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# _____ _ _ _____ _____ _____ _____
#| ___|| \\ | |/ __ \\| _ | |_ _|| _ |
#| |__ | \\| || / \\/| | | | | | | | | |
#| __| | . ` || | | | | | | | | | | |
#| |___ | |\\ || \\__/\\\\ \\_/ / _ _| |_ \\ \\_/ /
#\\____/ \\_| \\_/ \\____/ \\___/ (_) \\___/ \\___/
#__________________Generated script by enco.io
# Example of a very simple conversational bot using only SMS
# Requires that you have a SMS keywords or dedicated short/long number associated to your EnCo account
# Please contact EnCo support for pricing information on keywords and dedicated numbers
# Entrypoint
function run(object data, object tags, string asset) {
string smsMessage = data[\"message\"];
object regex = create(\"Regex\", \"LOVEBOT\\\\s(\\\\S+)\\\\s(\\\\S+)\", smsMessage);
object found = regex.find();
if(!found) {
object dispatchError = create(\"SMS\", data[\"senderAddress\"], \"Wrong syntax, send: LOVEBOT NAME1 NAME2\");
dispatchError.send();
} else {
string name1 = regex.group(1);
string name2 = regex.group(2);
object kv = create(\"KeyValue\");
object cached = kv.get(name1+name2);
string pct;
if(cached == null) {
object math = create(\"Math\");
double random = math.random();
random = random * 100;
random = math.round(random);
kv.put(name1+name2, random);
pct = random;
} else {
pct = cached;
}
string loveMessage = name1 + \" loves \" + name2 + \" for \" + pct + \"%\";
object dispatchSMS0 = create(\"SMS\", data[\"senderAddress\"], loveMessage);
dispatchSMS0.send();
}
}