带 webhook 的 Twilio SMS 转发 Slack 机器人
Twillio SMS forwarding Slack bot with webhook
我在 Slack API 传入网络挂钩上启用了传入网络挂钩。
适用于您的工作区的 Webhook URL 个:
说明:
要使用 webhook URL 发送消息,请在 JSON 中将消息作为 application/json POST 请求的正文发送。
将此 webhook 添加到您下面的工作区以激活此 curl 示例。
发送到 post 频道的示例 curl 请求:
curl -X POST -H 'Content-type: application/json' --data '{"text":"Hello, World!"}' https://hooks.slack.com/services/T0AFATG95/B73FDS5R6V/hFApP
(令牌不完整)。
当我发送 POST 请求时,它起作用了!
APP 2:18 私信
你好,世界!
现在我想让 Twillio 使用 web-hook 或 TwiML 将这个 POST 请求发送到 slack。 ???
这基本上是对松弛 URL 的接力。我如何向 URL 发出 POST 请求,以便发送到 twillio # 的消息在正文中发送?
在 twillio phone 设置下我 select 什么时候发生:
一条消息来自 Webhook [WEB HOOK GOES HERE] HTTP POST
或者我可以使用:
TwiML Bin 而不是并在 twilio phone 设置中分配它。
如果我无法做到这一点,我将使用 lambda 函数来实现,我只是认为可能有一种方法可以实现这一点,因为我不对消息进行任何操作。
您可以使用 Twilio Function
执行此操作,这是该函数的代码:
const got = require('got');
exports.handler = function(context, event, callback) {
const requestBody = {
text: event.Body
};
got.post('https://hooks.slack.com/services/T0AFATG95/B73FDS5R6V/hFApP', {
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(requestBody)
})
.then(response => {
let twiml = new Twilio.twiml.MessagingResponse();
twiml.message("Your message has been forwarded to Slack.");
callback(null, twiml);
})
.catch(err => {
callback(err);
});
};
备注:
event.Body
保存发送到您的 Twilio 号码的 SMS 消息
如果您不想向发件人发送任何回复,请注释掉或删除此行:twiml.message("Your message has been forwarded to Slack.");
还读了这个Building apps with Twilio Functions
https://support.twilio.com/hc/en-us/articles/115007737928-Building-apps-with-Twilio-Functions
@philnash 的博客 post 是此答案的灵感来源 https://www.twilio.com/blog/2017/07/forward-incoming-sms-messages-to-email-with-node-js-sendgrid-and-twilio-functions.html
我在 Slack API 传入网络挂钩上启用了传入网络挂钩。 适用于您的工作区的 Webhook URL 个:
说明:
要使用 webhook URL 发送消息,请在 JSON 中将消息作为 application/json POST 请求的正文发送。
将此 webhook 添加到您下面的工作区以激活此 curl 示例。
发送到 post 频道的示例 curl 请求:
curl -X POST -H 'Content-type: application/json' --data '{"text":"Hello, World!"}' https://hooks.slack.com/services/T0AFATG95/B73FDS5R6V/hFApP
(令牌不完整)。
当我发送 POST 请求时,它起作用了!
APP 2:18 私信 你好,世界!
现在我想让 Twillio 使用 web-hook 或 TwiML 将这个 POST 请求发送到 slack。 ??? 这基本上是对松弛 URL 的接力。我如何向 URL 发出 POST 请求,以便发送到 twillio # 的消息在正文中发送?
在 twillio phone 设置下我 select 什么时候发生:
一条消息来自 Webhook [WEB HOOK GOES HERE] HTTP POST
或者我可以使用:
TwiML Bin 而不是并在 twilio phone 设置中分配它。
如果我无法做到这一点,我将使用 lambda 函数来实现,我只是认为可能有一种方法可以实现这一点,因为我不对消息进行任何操作。
您可以使用 Twilio Function
执行此操作,这是该函数的代码:
const got = require('got');
exports.handler = function(context, event, callback) {
const requestBody = {
text: event.Body
};
got.post('https://hooks.slack.com/services/T0AFATG95/B73FDS5R6V/hFApP', {
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(requestBody)
})
.then(response => {
let twiml = new Twilio.twiml.MessagingResponse();
twiml.message("Your message has been forwarded to Slack.");
callback(null, twiml);
})
.catch(err => {
callback(err);
});
};
备注:
event.Body
保存发送到您的 Twilio 号码的 SMS 消息如果您不想向发件人发送任何回复,请注释掉或删除此行:
twiml.message("Your message has been forwarded to Slack.");
还读了这个
Building apps with Twilio Functions
https://support.twilio.com/hc/en-us/articles/115007737928-Building-apps-with-Twilio-Functions@philnash 的博客 post 是此答案的灵感来源 https://www.twilio.com/blog/2017/07/forward-incoming-sms-messages-to-email-with-node-js-sendgrid-and-twilio-functions.html