Twilio Whatsapp: Send Location not working

69 Views Asked by At

I'm using the FUNCTION Widget in Twilio Studio.

I need to send location inside a message in whatsapp.

I've tried this peice of code inside a function in Twilio:


// This is your new function. To start, set the name and path on the left.

exports.handler = function(context, event, callback) {
  // The pre-initialized Twilio Client is available from the `context` object
  const twilioClient = context.getTwilioClient();

  // Determine message details from the incoming event, with fallback values
  const from = event.From || 'whatsapp:+14155238886';
  const to = event.To || 'whatsapp:+556181584246';
  const body = event.Body || 'Ahoy, World!';
  const persistentAction = 'geo:-1.232453, 36.878987';



  twilioClient.messages
    .create({to, body, from, persistentAction})
    .then((result) => {
      console.log('Created message using callback');
      console.log(result);
      console.log(result.sid);
      return callback();
    })
    .catch((error) => {
      console.error(error);
      return callback(error);
    });

};
1

There are 1 best solutions below

0
Luis Leao On

Try removing the + sign from the numbers in both fields.

If you are receiving an error, please also add the callback function as a parameter.

The final code should be like this:

exports.handler = function(context, event, callback) {
    // The pre-initialized Twilio Client is available from the `context` object
    const twilioClient = context.getTwilioClient();

    // Determine message details from the incoming event, with fallback values
    const from = 'whatsapp:[NUMBER_WITHOUT_PLUS]';
    const to = 'whatsapp:[NUMBER_WITHOUT_PLUS]';
    const body = 'Ahoy, World!';
    const persistentAction = 'geo:-1.232453, 36.878987';

    twilioClient.messages
        .create({to, body, from, persistentAction}, (err, result) => {
            if (!err) {
                console.log('Created message using callback');
                console.log(result);
                console.log(result.sid);
                return callback();
            }
        })
}