将 messagingServiceSid 附加到 nodejs 库中的 twiml 响应

Attach messagingServiceSid to a twiml response in nodejs library

我有一个 webhook 设置,我可以接收消息并回复它们。我希望我的 webhook 发送响应以附加 messagingServiceSid。

我没有在文档中找到为来自我的 webhook 的响应配置它的方法,仅适用于使用

的新 SMS
client.sendMessage({
  messagingServiceSid: 'MG9752274e9e519418a7406176694466fa',
  to: '+16518675309',
  body: 'Phantom Menace was clearly the best of the prequel trilogy.'
}, function(err, message) {
  console.log(message);
});

这段代码有类似的东西吗?通过 UI 是否可行?

app.post('/foo/bar/sms', twilio.webhook({
  host:'gassy-ocelot-129.herokuapp.com',
  protocol:'https'
}), function(request, response) {
  var twiml = new twilio.TwimlResponse();
  twiml.message('This HTTP request came from Twilio!');
  response.send(twiml);
});

图片: No messagingService on reply messages sent using twiml response

Message Detail view from logs

如果您在当前设置为该消息服务的 phone 号码上收到传入的 SMS(通过网络 ui 或 phone 号码 REST),则传入的请求将查询字符串中有 MessagingServiceSid

这里是 Twilio 开发人员布道者。

据我所知,无法使用 TwiML 回复来自消息服务的消息。

但是,不使用 TwiML,您可以只 send the SMS back to your user from the REST API 和 return 一个空的 <Response> 到传入的 webhook。有点像这样:

app.post('/foo/bar/sms', twilio.webhook({
  host:'gassy-ocelot-129.herokuapp.com',
  protocol:'https'
}), function(request, response) {
  // send the message from the message service
  client.sendMessage({
    messagingServiceSid: 'MG9752274e9e519418a7406176694466fa',
    to: request.body.From,
    body: 'Your message'
  }, function(err, message) {
    console.log(message);
  });
  // send empty TwiML response
  var twiml = new twilio.TwimlResponse();
  response.send(twiml);
})

如果有帮助请告诉我。