I have created a Node.js bot using the Bot Framework and deployed it into Azure.
By default, the bot messaging end point for the Azure bot msbotnew1
will be
https://msbotnew1.azurewebsites.net/api/messages
I am able to communicate with the bot using Web Chat
, and also I am able to send outgoing whatsapp messages from Twilio to my cellphone number.
Code for setting the Azure messaging endpoint:
var restify = require('restify');
var builder = require('botbuilder');
var botbuilder_azure = require("botbuilder-azure");
var request = require("request");
var twilio = require("twilio");
var fs = require('fs');
// Setup Restify Server
var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function () {
console.log('%s listening to %s', server.name, server.url);
});
// Create chat connector for communicating with the Bot Framework Service
var connector = new builder.ChatConnector({
appId: process.env.MicrosoftAppId,
appPassword: process.env.MicrosoftAppPassword,
openIdMetadata: process.env.BotOpenIdMetadata
});
// Listen for messages from users
server.post('/api/messages', connector.listen());
Code for sending outgoing whatsapp messages from Twilio to cellphone number:
var twilio = require("twilio");
const accountSid = process.env.accountSid;
const authToken = process.env.authToken;
const client = require('twilio')(accountSid, authToken);
client.messages
.create({
body: 'Hello there!',
from: 'whatsapp:+14155238886',
to: process.env.whatsappToNumber
})
.then(message => console.log(message.sid))
.done();
But for the incoming messages, The inbound endpoint URL had to be set in this page:
https://www.twilio.com/console/sms/whatsapp/sandbox
The incoming endpoint is set in the above page as follows:
WHEN A MESSAGE COMES IN
: https://msbotnew1.azurewebsites.net/api/messages
I get the following error in the Bot app output, when an incoming message was texted from whatsapp:
ERROR: ChatConnector: receive - invalid request data received.
I have tried various combinations of the endpoint URLs which aren't working, such as https://msbotnew1.azurewebsites.net/sms
, https://msbotnew1.azurewebsites.net/api/messages/sms
https://msbotnew1.azurewebsites.net/api/sms
How can I get the correct endpoint URL to send incoming messages from Whatsapp cellphone to Azure node.js bot using Twilio?