我已经启用了Slack API传入Web挂钩上的传入Web挂钩。 Webhook工作区的URL:
说明:
要使用您的webhook URL分发消息,请使用JSON作为application / json POST请求的正文发送消息。
将此webhook添加到下面的工作区以激活此卷曲示例。
发布到频道的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手机设置下,我选择以下情况:
Webhook中有一条消息[WEB HOOK GOES HERE] HTTP POST
或者我可以使用:
转而使用TwiML Bin并在twilio手机设置中指定它。
如果我无法实现这一点,我将使用lambda函数来执行此操作,我只是可能有一种方法可以实现此目的,因为我不会操纵任何有关消息的内容。
答案 0 :(得分:1)
您可以使用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号码的短信如果您不想向发件人发送任何回复,请注释或删除此行: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的博客文章是这个答案的灵感来源https://www.twilio.com/blog/2017/07/forward-incoming-sms-messages-to-email-with-node-js-sendgrid-and-twilio-functions.html