1

I'm trying to utilize Twilio to create a WhatsApp group, using the instructions from TwilioDevEd here: https://github.com/TwilioDevEd/whatsapp-group-messaging and running createConversation.js using exactly the code provided. (I've shown this code below, reverting the phone numbers back to the example strings from the original author.) When I run https://.twil.io/createConversation.js, I get the following error:

UnhandledPromiseRejectionWarning: Unhandled promise rejection: TypeError: Cannot read property 'conversations' of undefined

I interpret this a failure to create the client in line 5 of the sample, though I'm not sure of it. Any idea what is causing this error and how I can address?

Help would be much appreciated!

Nolan

exports.handler = async function(context, event, callback) {
  const numbers = ['YOUR_PHONE_NUMBER', 'YOUR_FRIENDS_PHONE_NUMBER'];
  const client = context.getTwilioClient();

  const conversation = await client.conversations.conversations.create();

  numbers.forEach(async (number) => {

    const newParticipant = await client.conversations.conversations(conversation.sid).participants.create({
      'messagingBinding.address': `whatsapp:${number}`,
      'messagingBinding.proxyAddress': `whatsapp:${process.env.WHATSAPP_NUMBER}`
    });

    const message = await client.messages.create({
      'to': `whatsapp:${number}`,
      'from': `whatsapp:${process.env.WHATSAPP_NUMBER}`,
      'body': ' Sam has invited you to join a group conversation. *Please tap the button below to confirm your participation.*'
    });
  });

  return callback(null, conversation.sid);
};

I was expecting this to create a client object and a new conversation. I was able to get similar code working in my local environment, and thus have suspected it might have something to do with environment setup. For some context on things I've already tried / confirmed --

  • The Environment Variables has TWILIO_SERVICE_SID and SYNC_MAP_SID with appropriate ISXXX and MPXXX values
  • The option for Add my Twilio Credentials (ACCOUNT_SID) and (AUTH_TOKEN) to ENV is checked
  • I made no changes to the default Dependencies
  • I replaced the numbers array with phone numbers in the format '+14151234567'

Thanks again for any suggestions!

nsm0213
  • 11
  • 1
  • 1
    > I made no changes to the default Dependencies Without knowing more details, I'd suggest to update the twilio dependency. This is always the first thing I do when using Functions because the default version is not very recent. – IObert Oct 29 '22 at 15:36

0 Answers0