[英]Handling inbound Twilio messages using node.js
我正在閱讀Twilio文檔的部分內容( https://www.twilio.com/help/faq/why-does-my-twilio-number-respond-with-thanks-for-the-message-configure-your與SMS消息響應相關的-numbers-sms-url-to-change-this-message ),並正在嘗試構建一個node.js應用程序,該應用程序將允許我以編程響應來響應入站SMS消息。
我一直在嘗試模擬這樣的SO帖子,該帖子處理類似的問題( 如何使用node.js響應傳入的Twilio呼叫和SMS消息? ),並具有以下代碼:
var AUTH_TOKEN = "*********************";
var twilio = require('twilio');
var express = require('express');
var http = require('http');
var app = express();
var bodyParser = require('body-parser');
app.use(bodyParser.urlencoded());
app.post('/welcome/sms/reply/', function(req, res) {
//Validate that this request really came from Twilio...
if (twilio.validateExpressRequest(req, AUTH_TOKEN)) {
var twiml = new twilio.TwimlResponse();
twiml.say('Hi! Thanks for checking out my app!');
res.type('text/xml');
res.send(twiml.toString());
}
else {
res.send('you are not twilio. Buzz off.');
}
});
http.createServer(app).listen(3000);
通過REST客戶端調用POST請求/ welcome / sms / reply會生成else語句,我不確定為什么會這樣,因為AUTH_TOKEN正是我的帳戶儀表板中的內容。
有關合並ngrok + Express的信息,請參閱此帖子。 https://www.twilio.com/blog/2015/09/monitoring-call-progress-events-with-node-js-and-express.html
Twilio開發人員布道者在這里。
如果您嘗試使用REST客戶端在那兒調用自己的終結點,並且正在驗證請求( twilio.validateExpressRequest
),則將需要像Twilio一樣構造請求。 至關重要的是,這包括一個X-Twilio-Signature
標頭,有關更多詳細信息,請參見該鏈接。
如果您使用Twilio測試您的代碼,它應該可以工作並且是有效的請求。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.