BotBuilderCommunity / botbuilder-community-js

Part of the Bot Builder Community Project. Repository for extensions for the Bot Builder JavaScript SDK, including middleware, dialogs, recognizers and more.
MIT License
117 stars 38 forks source link

Twilio WhatsApp Adapter: request doesn't contain a valid Twilio Signature #349

Closed HesselWellema closed 1 year ago

HesselWellema commented 1 year ago

Hi,

I am struggling getting the adapter to work properly. The validation of the request keeps failing resulting in the errormessage above

const { TwilioWhatsAppAdapter } = require('@botbuildercommunity/adapter-twilio-whatsapp');
const whatsAppAdapter = new TwilioWhatsAppAdapter({
    accountSid: '<Sid from Twilio console >', 
    authToken: '<>Auth token from Twilio console', 
    phoneNumber: '<phone number from Whatsapp Sandbox settings in Twilio>',
    endpointUrl: 'url from Sandbox setting in Twilio' 
});

For the endpointUrl parameter I use is the one from my chatbot: https://mybot.azurewebsites.net/api/whatsapp/messages

for the phoneNumber parameter I tried multiple formats without succes: whatsapp:+1XXXXXXXXXX whatsapp:1XXXXXXXXXX +1XXXXXXXXXX 1XXXXXXXXXX

I checked the source of this adapter and there are two possible causes:

  1. No x-twilio-signature header. I checked the request headers and there seems to be a valid x-twilio-signature header in there.
  2. The result of the twilio.validateRequest returns false. This method is taking authToken, signature, requestUrl and message. I checked them all and they seem fine.

I would appreciate some guidance. Otherwise I will need to figure our a way to debug this module tnx

HesselWellema commented 1 year ago

The sample works fine. Should have tried that first An analysis of my own botcode showed that the problem was a line of code: server.use(require('body-parser').json() Since I am using restify I am not sure why it is there in the first place.