为单个 Twilio 号码注册多个 webhook [英] Register multiple webhooks for single Twilio number
问题描述
是否可以以编程方式为单个 Twilio 号码注册多个 webhook URL?(当我们收到入站短信时,我们希望使用该数据调用多个 webhook)
Is it possible to programmatically register multiple webhook URLs for a single Twilio number? (When we receive an inbound SMS we would like multiple webhooks to be called with that data)
文档更新incomingPhoneNumber 资源" 建议您可以选择设置smsUrl
,但不清楚如何为单个号码设置多个 webhook URL.>
The docs for "update an incomingPhoneNumber resource" suggest that you can optionally set the smsUrl
, but it's not clear how you would set multiple webhook URLs for a single number.
推荐答案
不是通过 Twilio 控制台选项.您可以编写一个可以分叉出多个出站 Webhook 的 Twilio 函数,如下所示,然后您只需将 Twilio 控制台指向这个 Twilio 函数即可.
Not through the Twilio console options. You can write a Twilio Function that can fork out multiple outbound webhooks such as below, and then you just point the Twilio console to this Twilio Function.
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
};
let url1 = "https://example.com/1";
let url2 = "https://example.com/2";
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);
});
};
这篇关于为单个 Twilio 号码注册多个 webhook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!