如何对传入的短信进行“双重网络挂钩"? [英] How can I do a 'double webhook' on an incoming SMS?

查看:24
本文介绍了如何对传入的短信进行“双重网络挂钩"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Twilio 中,有一个选项可以在通过我们的一个电话号码接收 SMS 时向网络钩子发送请求.

In Twilio there is an option to send a request to a webhook when receiving an SMS on one of our phone numbers.

我试图让它向 2 个不同的端点发射 2 个网络钩子.

I am trying to get it to fire 2 webhooks to 2 different endpoints.

我可以将两个端点放在一个动词中吗?或者我是否需要编写一个 Twilio 函数来触发 2 个 webhook?这看起来应该很简单,但我在 Twilio 文档中迷失了方向.

Can I put two endpoints inside a single verb? Or do I need to write a Twilio Function to fire 2 webhooks? This seems like it should be simple but I am getting lost in the Twilio documentation.

最初我打算写一个 TwiML bin 来尝试用动词处理这个问题.但是在文档中它说没有动词可以执行,这意味着第二个不会触发.

Initially I was going to write a TwiML bin to try and handle this with the verb. However in the documentation it says that no verbs can execute after which means the second one will not fire.

推荐答案

Twilio 开发人员布道者在这里.

Twilio developer evangelist here.

如果您需要将一条传入消息通知两个不同的服务,那么我将使用您自己的应用程序或 Twilio 函数将请求发送给它们.

If you need two different services to be notified about the one incoming message then I would use either an application of your own or a Twilio Function to send the request on to both of them.

您可以使用看起来像这样的 Twilio 函数 来完成此操作:

You could do this with a Twilio Function that looks a bit like this:

const got = require('got');

exports.handler = function(context, event, callback) {
  let twiml = new Twilio.twiml.MessagingResponse();
  Promise.all([
    got.post(FIRST_URL, { body: JSON.stringify(event) }),
    got.post(SECOND_URL, { body: JSON.stringify(event) })
  ]).then(responses => callback(null, twiml));
};

您需要将 got 添加到您的函数依赖项中才能使其工作.另请注意,这会以空的 TwiML 响应进行响应.由于您将这些消息传递到 Front,我假设您没有执行自动响应.这也不能处理错误,但至少应该让您开始.

You'll need to add got to your Function dependencies for this to work too. Also note that this responds with an empty TwiML response. Since you are passing these messages into Front, I assume you aren't performing automated responses. This also doesn't handle errors, but should get you started at least.

告诉我这是否有帮助.

这篇关于如何对传入的短信进行“双重网络挂钩"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆