Function Twilio功能:尝试发送传入的sms警报以处理停止请求
我正在尝试向管理员电话号码发送警报短信,并使用本地语言版本的停止响应回复原始短信(我们已关闭此号码的自动响应) 下面的代码用于将响应发送到原始人-但是,它不会向我们想要的号码(当前+447824636xxx)发送警报短信 我在帮助文档、StackOverflow或Google Twilio开发组中找不到任何关于在Twilio函数中如何工作的信息 请建议如何使突出显示的代码正常工作Function Twilio功能:尝试发送传入的sms警报以处理停止请求,function,twilio,twilio-functions,Function,Twilio,Twilio Functions,我正在尝试向管理员电话号码发送警报短信,并使用本地语言版本的停止响应回复原始短信(我们已关闭此号码的自动响应) 下面的代码用于将响应发送到原始人-但是,它不会向我们想要的号码(当前+447824636xxx)发送警报短信 我在帮助文档、StackOverflow或Google Twilio开发组中找不到任何关于在Twilio函数中如何工作的信息 请建议如何使突出显示的代码正常工作 exports.handler = function(context, event, callback) { c
exports.handler = function(context, event, callback) {
console.log ("Incoming SMS")
console.log (event.From)
console.log (event.Body)
if (event.Body == "STOP" || event.Body == "Stop" || event.Body == "stop") {
console.log ("Received a STOP message")
// ***** BELOW CODE DOES NOT SEND SMS ****
// Send a warning message to Chloe
let client = context.getTwilioClient()
let c = client.messages.create({
body: "We have a STOP message on Fresenius NO from ",
to: "+447824636xxx",
from: event.To
})
// ***** ABOVE CODE DOES NOT SEND ANYTHING *****
console.log ("Sent warning to Admin")
// Respond to the user/patient with STOP message in local language
let twiml = new Twilio.twiml.MessagingResponse();
twiml.message("Du har nå meldt deg av MyFresubin og vil ikke motta flere meldinger fra dette nummeret.");
twiml.message.to = event.From
twiml.message.from = "+4759444xxx"
callback(null, twiml);
}
else {callback(null)}
}
您的代码将无法工作,因为您调用回调函数太快,并且将在对Twilio API的调用能够完成之前终止执行 工作代码: 当然,可以随意添加原始代码中的
STOP
条件语句
exports.handler = function (context, event, callback) {
let twiml = new Twilio.twiml.MessagingResponse();
twiml.message("Du har nå meldt deg av MyFresubin og vil ikke motta flere ....");
let client = context.getTwilioClient();
// Send a warning message to Chloe
client.messages
.create({
to: '+447824636xxx',
from: event.To,
body: "We have a STOP message on Fresenius NO from " + event.From
})
.then(message => {
console.log(message.sid);
// Respond to the user/patient with STOP message in local language
callback(null, twiml);
});
}