Skip to content

Instantly share code, notes, and snippets.

@dannyrandall
Created February 11, 2021 03:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dannyrandall/196c16469175323bef2af335cbed046e to your computer and use it in GitHub Desktop.
Save dannyrandall/196c16469175323bef2af335cbed046e to your computer and use it in GitHub Desktop.
ruleset twilio {
meta {
name "Twilio"
author "Daniel Randall"
configure using
accountSID = ""
authToken = ""
provides sendSMS, messages
}
global {
baseURL = <<https://api.twilio.com/2010-04-01/Accounts/#{accountSID}>>
sendSMS = defaction(from, to, message) {
http:post((baseURL+"/Messages.json").klog("url"), auth = {
"username": accountSID,
"password": authToken
}.klog("auth"), form = {
"From": from,
"To": to,
"Body": message
}.klog("form")) setting(resp)
return resp{"content"}.decode()
}
messages = function(from, to, pageSize) {
qs = {
"From": from,
"To": to,
"PageSize": pageSize
}
resp = http:get((baseURL+"/Messages.json").klog("url"), auth = {
"username": accountSID,
"password": authToken
}.klog("auth"), qs = qs.filter(function(v, k) {v}).klog("query"))
resp{"content"}.decode()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment