Hi @rickkas7. I tried following the tutorial. But have hit a hurdle. I explained the general background to what I am trying to do in my first post. I have various debug events and variables that I am pretty sure the rest of the code is OK. The problem is just in the parsing of my data using mustache templatesisnt occurring.
Any help appreciated. Thanks.
After reading your tutorial, this is what I have:
Event/data code in Photon:
Particle.publish("GetToken","",60,PRIVATE);
delay(10000); //Wait for token to be received.
if (token.length() > 0) {
String message = "{\"SMSTokString\": \"Bearer ";
message.concat(token); \\token is returned from remote server, its a long string. Remote server expects this returned in form "Bearer <token>"
message.concat("\" \"body\": \"");
message.concat(body);\\this is the variable message body according to status of real world
message.concat("\"}");
//Particle.publish("message", message);
Particle.publish("SendSMS",message,60,PRIVATE); //Create new event linked to webhook to send SMS via Telstra server
The webhook JSON text file I use to create the SendSMS webhook looks like this:
{
"event": "SendSMS",
"url": "http://requestb.in/zgsys5zg",
"requestType": "POST",
"headers": {
"Authorization": "{{SMSTokString}}"
},
"json": {
"to": "my cell number",
"body": "{{body}}"
},
"mydevices": true,
"noDefaults": true
}
The webhook creates OK at the CLI with this response:
Sending webhook request { uri: '/v1/webhooks',
method: 'POST',
json:
{ event: 'SendSMS',
url: 'http://requestb.in/zgsys5zg',
deviceid: undefined,
requestType: 'POST',
mydevices: true,
headers: { Authorization: '{{SMSTokString}}' },
json: { to: 'my cell number', body: '{{body}}' },
noDefaults: true },
headers: { Authorization: 'Bearer e8cdlongtokenstringbf2d319c7f' } }
Successfully created webhook with ID 57cb6.........c49d690
This just with URL to requestb.in for debugging - not to eventual target server.
At run time I get no errors or issues.
At requestb.in, it looks like (there is no parsing of my “Authorization” string into the field:
http://requestb.in
POST /zgsys5zg application/json
29 bytes 1m ago
From 54.236.213.127, 173.245.56.170
FORM/POST PARAMETERS
None
HEADERS
Content-Type: application/json
Accept-Encoding: gzip
Host: requestb.in
Via: 1.1 vegur
Cf-Visitor: {"scheme":"http"}
User-Agent: ParticleBot/1.1 (https://docs.particle.io/webhooks)
Authorization:
X-Request-Id: ea61e29d-284d-46a4-b101-3a76ffdd5b08
Cf-Connecting-Ip: 54.236.213.127
Accept: application/json
Connection: close
Connect-Time: 1
Cf-Ipcountry: US
Content-Length: 29
Total-Route-Time: 0
Cf-Ray: 2dcd66c53227241a-IAD
RAW BODY
{"body":"","to":"my cell number"}