A bit about the problem. I use Kommo Crm (Amo Crm) for work. There's integration inside that allows me to accept and send texts via Twilio, but that thing doesn't show me income images. So i need to do a custom solution. I decided to process images on my google app.
So I needed twilio to send 2 webhooks. 1 to kommo (to keep getting messages) and 1 to my app.
Right now 1 webhook to kommo works. Here's the settings (pic1settings) It's done through "Messaging Services" - "integration" - "webhook url"
So i changed the "webhook url" to my app url and tried to forward the hook to Kommo. My app received the hook, then hook were forwarded to kommo but It didnt go through. The message doesnt show in Kommo. Tried different ways. It says response 200 (success) but the message didn't appear.
Then i found this twilio function that sends 2 webhooks via axios.
const axios = require('axios');
const qs = require('querystring');
exports.handler = function(context, event, callback) {
let twiml = new Twilio.twiml.MessagingResponse();
let {
ApiVersion,
SmsSid,
SmsStatus,
SmsMessageSid,
NumSegments,
ToState,
From,
MessageSid,
AccountSid,
ToCity,
FromCountry,
ToZip,
FromCity,
To,
FromZip,
ToCountry,
Body,
NumMedia,
FromState
} = event;
let requestBody = {
ApiVersion,
SmsSid,
SmsStatus,
SmsMessageSid,
NumSegments,
ToState,
From,
MessageSid,
AccountSid,
ToCity,
FromCountry,
ToZip,
FromCity,
To,
FromZip,
ToCountry,
Body,
NumMedia,
FromState
};
console.log('Test '+ Body);
let url1 = "https://chatstwilio.amocrm.com/twilio_sms/webhook/twilio_message/incoming";
let url2 = "https://script.google.com/macros/s/AKfycbyrFMmuBDpjBIV05vD2utzL9v5au_hlcHbIA4uj7D09JkKW4XiDW9FoW/exec?fn=twiliomedia";
const config = {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}};
Promise.all([
axios.post(url1, qs.stringify(requestBody), config),
axios.post(url2, qs.stringify(requestBody), config)
]).then(result => {
callback(null, twiml);
}).catch(err => {
console.log(err);
callback(err);
});
};
It sends hooks, my app receives it, BUT kommo doesnt.
I assumed that the problems in headers. X-Twilio-Signature. Or maybe something else. Idk.
What would you suggest? How to make twilio to send 2 original webhooks?
In total:
- Twilio original webhook that made via "Messaging Services" - "integration" - "webhook URL" delivers the messages to Kommo CRM perfectly.
- If i change the "webhook URL" to my custom "twilio function" it stops deliver to Kommo.
Please help. In perfect scenario i need to get messages in Kommo and work on images in my google webapp.
So i didnt sleep 1 night and made a solution of how to send 2 or more original webhooks from twilio. Search Keywords: how to forward twilio webhook, how to send custom twilio webhook
Dont forget to enter your own authToken, https://your.site/webhook.