Ad

Twilio Response Object Undefined But No Errors?

- 1 answer

I am working on an implementation of Twilio in a basic meteor app. I have set up client-side code to call the server-side method below (in this case, on login).

The method is called without issue and no error is produced in the server logs. However if I log out my response data, it is undefined. Is this a timing issue? My impression was that the function containing the response or error is called when a response is received.

Any input would be appreciated, thanks in advance!

Meteor.methods({
twilioTest:function () {

console.log("Twilio Test Called!");

    ACCOUNT_SID = "xxxxxxxxxxxxxxxxxxxxxxxxxxx";
    AUTH_TOKEN = "xxxxxxxxxxxxxxxxxxxxxxxxxxx";

    twilio = Twilio(ACCOUNT_SID, AUTH_TOKEN);
    twilio.sendSms({
        to:'+xxx-xxx-xxxx', // Any number Twilio can deliver to
        from: '+xxx-xxx-xxxx', // A number you bought from Twilio and can use for outbound communication
        body: 'Greetings!' // body of the SMS message
    },function(err, responseData) { //this function is executed when a response is received from Twilio
        console.log(responseData); // log out response object
        if (!err) { // "err" is an error received during the request, if any
            // "responseData" is a JavaScript object containing data received from Twilio.
            // A sample response from sending an SMS message is here (click "JSON" to see how the data appears in JavaScript):
            // http://www.twilio.com/docs/api/rest/sending-sms#example-1
            console.log(responseData.from); // outputs outbound number
            console.log(responseData.body); // outputs message body
        }
    });

}
Ad

Answer

As John Hascall pointed out, I should have been logging out the error object instead of the response object. This revealed that my target phone number was invalid and allowed me to correct the issue.

Ad
source: stackoverflow.com
Ad