Hi Guys,
I have made this and for my project, I’d like to share it so that one can use it as reference.
Replace " with " in url part
`//agent
// Infromation of plivo service
const PLIVO_AUTH_ID = “YOUR AUTH ID”;
const PLIVO_AUTH_TOKEN = “YOUR AUTH TOKEN”;
const destination_number = “9186****70”;
const src_number = “14154847489”;
//function to send SMS on event using PLIVO service
function plivo_SMS(message)
{
local status;
if(message == 0)
{
status = "led off";
}
else
{
status = "led on";
}
local url = format("https://api.plivo.com/v1/Account/%s/Message/",PLIVO_AUTH_ID);
server.log("url: "+url); //debug print
local headers = {
"Content-Type": "application/json"
"Authorization" : "Basic " + http.base64encode(PLIVO_AUTH_ID + ":" + PLIVO_AUTH_TOKEN)
};
server.log("headers: "+headers); //debug print
local body = http.jsonencode({src=src_number, dst=destination_number, text=status});
server.log("body: "+body); //debug print
local req = http.post(url,headers, body);
local res = req.sendsync();
if(res.statuscode != 202)
{
server.error("error sending message: "+res.body);
}
else
{
server.log(res.body);
}
}
device.on(“SMS”, plivo_SMS);
`