2
votes

I'm working on cloud code in my parse.com account to send SMS messages thru a Twilio account. I am using the integrated Twilio cloud module provided by Parse. The call to sendSMS is successful if I do not include a StatusCallback param in the call. I am saving the message in Parse on the send response and would like to use the callback to update the msg status to sent or fail. The callback URL I am using is another cloud function on my parse account. I have used the Parse format for the URL which includes my App key and JS key between the https:// and the api URL:

https://appID:javascript-key=jsKey@api.parse.com/1/functions/callbackSMS
(where appID, and jsKey are the keys provided for by Parse)

When I include this URL as the StatusCallback param for my call to sendSMS, the Twilio server rejects the call. The response identifies error 21609, invalid URL. However, I can call the URL manually using CURL with success. And, the exact same URL format works fine when configured as the Messaging Request URL for the number. This is entered using the Twilio website for the number associated w/ my account.

Anyone else using Parse/Twilio module in a Cloud Function w/ advice? How to call sendSMS from Parse cloud code and supply the StatusCallback URL to receive an update at another Parse cloud function to update the msg status once the SMS is sent by Twilio? My sendSMS cloud code included for completeness:

client.sendSms({ 
    to:'+12223334444', 
    from:'+1222333555', 
    body:'msg body from db', 
    StatusCallback:'https://appID:[email protected]/1/functions/callbackSMS' 
    }, function (err, responseData) { 
        if (err) { 
            console.log(err); 
            response.error(err); 
        } else { 
            var SMSLog = Parse.Object.extend("Message"); 
            var smsLog = new SMSLog(); 

            smsLog.save({ 
                messageId: responseData['sid'], 
                dateCreated: responseData['dateCreated'], 
                dateUpdated: responseData['dateUpdated'], 
                dateSent: responseData['dateSent'], 
                accountSid: responseData['accountSid'], 
                to: responseData['to'], 
                from: responseData['from'], 
                body: responseData['body'], 
                status: responseData['status'] 
            }, { 
            success: function (smsLog) { 
                response.success(responseData); 
            }, 
            error: function (smsLog, error) { 
                response.error("failed to save sms msg"); 
            } 
            }); 
        } 
    });
1
Hi Jeff, I'm seeing the same error... Did you ever figure out how to solve this? Thanks! Mikeuser1066409
I've not found a solution to this... Seems the Twilio callback will not handle the format of the StatusCallback required by Parse. I have fallen back to polling the status of all outstanding messages in a Background Job... If anyone figures out how to make the StatusCallback work it would be great to hear from you. Thanks!user1066409

1 Answers

2
votes

Parse.com used a custom module, since the hosted cloud code solution was not actually running Node and could not use the public node module.

Now, you can run Parse Server on your own server / localhost / cloud provider, and use the official public Twilio npm module.

Check out the Parse Server repository here: https://github.com/parseplatform/parse-server

And the twilio npm module: https://www.npmjs.com/package/twilio