WhatsApp On Premise API Bot framework adapter
USAGE
const {
BotFrameworkAdapter,
ConversationState,
UserState,
} = require("botbuilder-waba");
const adapter = new BotFrameworkAdapter({});
const conversationState = new ConversationState(storage);
const userState = new UserState(storage);
const moc = new BOT(conversationState, userState);
const waParser = async (req, res, next) => {
if (!req.body.messages) {
return res.send({ message: "no messages in webhook call" });
}
const sender = req.params.sender;
const message = req.body.messages[0];
const question = findText(message);
const recipient = message.from;
req.body.question = question;
req.body.recipient = recipient;
req.body.sender = sender;
req.body.isAudio = message.type === "voice" || message.type === "audio";
req.body.message = message;
req.body.type = "message";
req.body.location = message?.location;
req.body.channelId = "whatsapp";
req.body.conversation = {};
req.body.conversation.id = recipient;
req.body.text = question;
return next();
};
server.post("/api/messages/:sender", waParser, (req, res) => {
adapter.processActivity(req, res, async (context) => {
await moc.run(context);
});
});
GOOD LUCK