NAME
perl-SMS-Send-Adapter-Node-Red.psgi - SMS::Send Adapter to Node-RED JSON HTTP request PSGI Script
DESCRIPTION
A PSGI application to control SMS::Send with a web service.
API
The script is called over HTTP with a JSON Object payload.
POST http://127.0.0.1:5000/
{
"driver" : "VoIP::MS",
"to" : "7035551212",
"text" : "Text Message",
"options" : { "this" : "or", "that" : "and" }
}
There are many SMS::Send drivers available on CPAN. I use VoIP::MS in examples since that is the provider that I use for my home automation notifications. My other notiable drivers are Kannel::SMSbox and NANP::Twilio.
Return is a JSON Object.
200 OK
{
"sent" : true,
"input" : {...},
}
Return on error.
400|500|502 ...
{
"sent": false,
"input": {...},
"error": "error string to help point you in the correct direction"
}
Node-Red Integration
Use four nodes: inject, function, http request, and debug.
In the function node
Set the "payload" to a JSON Object with the keys "driver", "to" and "text" and any extra "options" needed for SMS::Send objects not built on SMS::Send::Driver::WebService.
my_text = msg.payload; msg.payload = { "driver" : "VoIP::MS", "text" : my_text, "to" : "7035551212", "options" : {"key" : "value"}, }; return msg;
In the http request node
Set the "Method" to POST
Set the "URL" to http://127.0.0.1:5000/
Set the "Return" to a parsed JSON Object
In the debug node
Set the "Output" to msg.payload.sent which returns boolean true or false
Node Red Example
[{"id":"3313f548.d53dba","type":"inject","z":"bbbcee28.8891c","name":"Inject","topic":"","payload":"My SMS Text","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":1540,"wires":[["5cb3e4eb.f6d34c"]]},{"id":"3a6aed54.d74342","type":"debug","z":"bbbcee28.8891c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.sent","targetType":"msg","x":710,"y":1540,"wires":[]},{"id":"a9dfd541.a3b3f8","type":"http request","z":"bbbcee28.8891c","name":"SMS::Send","method":"POST","ret":"obj","paytoqs":false,"url":"http://127.0.0.1:5000/","tls":"","persist":false,"proxy":"","authType":"","x":490,"y":1540,"wires":[["3a6aed54.d74342","aec87ffa.ec17f"]]},{"id":"aec87ffa.ec17f","type":"debug","z":"bbbcee28.8891c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"statusCode","targetType":"msg","x":700,"y":1500,"wires":[]},{"id":"707cfb7e.11b714","type":"debug","z":"bbbcee28.8891c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":490,"y":1500,"wires":[]},{"id":"5cb3e4eb.f6d34c","type":"function","z":"bbbcee28.8891c","name":"payload formatter","func":"my_text = msg.payload;\nmsg.payload = {\n \"driver\" : \"VoIP::MS\",\n \"text\" : my_text,\n \"to\" : \"7035551212\",\n \"options\" : {\"key\" : \"value\"},\n };\nreturn msg;","outputs":1,"noerr":0,"x":270,"y":1540,"wires":[["707cfb7e.11b714","a9dfd541.a3b3f8"]]}]