1

I see documentation of a new feature in Twilio (send location). I followed the documentation as a test, but it does not show up in Whatsapp.

context.getTwilioClient().messages.create({
                from: 'whatsapp:' + context.WHATSAPP_NUMBER,
                body: "Office Location",
                persistentAction: ['geo:37.787890,-122.391664'],
                to: event.From
            }).then(message => {
                callback(null);
            }).catch(err => callback(err));

The body 'Office Location' shows up in Whatsapp, but not the persistentAction.

John C
  • 517
  • 2
  • 6
  • 16

2 Answers2

1

I can confirm that it's not working. I tried also uninstalling the current version of twilio package (https://www.npmjs.com/package/twilio) and going back a few minor versions (3.38, 3.37, 3.36) and still not working.

I got it working using twilio cli (https://www.twilio.com/docs/twilio-cli/quickstart).

This worked:

twilio api:core:messages:create --from whatsapp:+14155238886 --body "Twilio HQ" --persistent-action "geo:37.787890,-122.391664|375 Beale St" --to whatsapp:+15005550006

Maybe there is something with Twilio Node Helper library (package).

Alex Baban
  • 11,312
  • 4
  • 30
  • 44
1

Found the solution:

I created a separate lambda function, and use the lambda function that I am using in Lex to invoke this:

//index.js

const axios = require("axios");
const dotenv = require("dotenv");
dotenv.config();

function main(params) {
    const authToken = '***';
    const authSID = '***';
    const url = 'https://api.twilio.com/2010-04-01/Accounts/ACCOUNT_SID/Messages.json';

    const messageBody = {
        Body: params.name,
        From: "whatsapp:+14155238886",
        PersistentAction: params.location,
        To: "whatsapp:" + params.phoneNumber
    };

    return new Promise((resolve, reject) => {
        axios.post(url, new URLSearchParams(messageBody), {
            auth: {
                username: authSID,
                password: authToken
            }
        }).then(response => {
            console.log(response.data.sid);
            resolve("Success")
        }, error => {
            console.log(error);
            reject(error);
        }
        );
    });
}
exports.handler = main;
John C
  • 517
  • 2
  • 6
  • 16