We saw how easy it is to create a complete responsive application using point and click/drag and drop methodologies in this blog, and we saw that we get a lot of built-in services here. But you may ask, “what do you do when one service does not exist yet or you need to integrate with a third party?”
First, obtain the following from your Twilio account:
- Account SID
- Auth Token
Second we go into the object definition of the destination object and create a new trigger of type "Object Script". We need to specify the following:
- Under which condition we want to send the SMS .In our case, we will specify "on any update of the Rating field."
- We code some JavaScript to:
- Limit sending an SMS for rating less or equal to 2
- Call Twilio Rest API
1.
if
( {!Rating} <= 2 ) {
2.
rbv_api.println(
"rating is low - sending sms"
);
3.
var
url=
"https://<yourAccoundSID>:<yourAuthToken>@api.twilio.com/2010-04-01/Accounts/<yourAccountSID>/SMS/Messages"
;
4.
var
params= {
"Body"
:
"Low rating on {!city}"
,
"To"
:
"+<countryCode><phoneNumber1>"
,
"From"
:
"+<countryCode><phoneNumber2>"
};
5.
var
finalResponse = rbv_api.sendHttpPost(url, params,
null
);
6.
rbv_api.println(finalResponse);
7.
}
Note, at line 4, how the SMS text will contain the destination city name ("Low rating on {!city}"). The key point here is that we have access to all the data of the Destination object and its related objects.
In conclusion, integrating with additional services and a third party is a breeze. It’s programmed using JavaScript making the solution standard and portable; there is no vendor lock-in.
Thierry Ciot
Thierry Ciot is a Software Architect on the Corticon Business Rule Management System. Ciot has gained broad experience in the development of products ranging from development tools to production monitoring systems. He is now focusing on bringing Business Rule Management to Javascript and in particular to the serverless world where Corticon will shine. He holds two patents in the memory management space.