-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathio.picolabs.twilio.sms.krl
63 lines (51 loc) · 1.67 KB
/
io.picolabs.twilio.sms.krl
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
ruleset io.picolabs.twilio.sms {
meta {
name "Twilio Module for SMS only"
description "Utility methods for sending SMS with Twilio"
author "Phil Windley"
version "0.1.0"
provides send_sms
shares show_configuration
configure using from_number = "801-555-1212"
account_sid = ""
auth_token = ""
}
global {
show_configuration = function() {
return {"account_sid": ent:account_sid,
"auth_token": ent:auth_token,
"from_number": ent:from_number}
}
// from_number = from_number || show_configuration(){["from_number"]}
// account_sid = account_sid || show_configuration(){["account_sid"]}
// auth_token = auth_token || show_configuration(["auth_token"] )
base_url = <<https://#{account_sid}:#{auth_token}@api.twilio.com/2010-04-01/Accounts/#{account_sid}/>>
//outgoing actions
send_sms = defaction(message, to, from=from_number){
http:post(base_url + "Messages.json",
form = {
"From":from,
"To":to,
"Body":message
});
};
}
rule save_config {
select when sensor configuration
pre {
auth_token = event:attr("twilio_auth_token")
account_sid = event:attr("twilio_account_sid")
from_number = event:attr("twilio_from_number")
}
if not (auth_token.isnull()
|| account_sid.isnull()
|| from_number.isnull()
) then noop()
fired {
log info "Configuring twilio";
ent:account_sid := account_sid;
ent:auth_token := auth_token;
ent:from_number := from_number;
}
}
}