var http = require('http');
var twilio = require('twilio')(ACCOUNT_SID, AUTH_TOKEN);
var qs = require('querystring');
http.createServer(function (req, res) {
var body = '';
req.setEncoding('utf8');
req.on('data', function(data) {
body += data;
});
req.on('end', function() {
var data = qs.parse(body);
var jsonString = JSON.stringify(data);
var jsonDataObject = JSON.parse(jsonString);
// log the received message
console.log(jsonDataObject.Body);
twilio.messages.create({
to:'MY_PHONE_NUMBER',
from:'TWILIO_NUMBER',
body:'Hello World'
}, function(error, message) {
if (error) {
console.log('There was an error.')
console.log(error.message);
}
});
res.writeHead(200, {'Content-Type': 'text/xml'});
res.end();
});
}).listen(1337, '127.0.0.1');
console.log('TwiML servin\' server running at http://127.0.0.1:1337/');
我試圖使用Twilio節點模塊收到短信,反過來一旦收到回覆短信迴應。因爲我可以記錄身體,所以接收消息似乎沒有問題。但是,當我嘗試回覆該消息時,我收到了401驗證錯誤。我使用ngrok來公開我的本地主機,這樣我就可以將它綁定到Twilio的API中。請看下面:接收與Twilio節點模塊短信與短信
我在哪裏錯了?
謝謝 - 但我不需要憑據接收傳入的文本?那部分有什麼變化? –
您不需要接收憑據,不需要,只需設置您的號碼的URL。 – philnash
我試過我的代碼,因爲它沒有證書 - 並且消息的正文不再記錄。 –