我的Node.js应用程序设置为响应以付费Twilio号码收到的短信。我用ngrok测试了它,一切正常。然而,一旦我将应用程序部署到Heroku,我就开始在Twilio控制台中看到11200 HTTP检索失败错误。
Heroku中是否需要设置配置设置?
// Twilio Credentials
const accountSid = 'xxx';
const authToken = 'xxx';
const client = require('twilio')(accountSid, authToken);
const MessagingResponse = require('twilio').twiml.MessagingResponse;
var express = require('express');
var app = express();
var bodyparser = require('body-parser');
app.use(bodyparser.urlencoded({extended: true}));
app.set('port', (process.env.PORT || 3000));
app.use('/', function(request, response){
response.send();
});
app.post('/sms', function(req, res) {
const twiml = new MessagingResponse();
twiml.message('Hi, this is Culpability. Your incident has been logged. Your
unique id # XXXX');
res.writeHead(200, {'Content-Type': 'text/xml'});
res.end(twiml.toString());
});
app.listen(app.get('port'), function() {
// console.log('Node app is running on port', app.get('port'));
});
答案 0 :(得分:0)
Twilio开发者传道者在这里。
我认为问题主要在于您用于发送响应的方法。目前,/sms
路线的最后一行是res.end(twiml.toString());
Response#end
is used "to quickly end the response without any data."
我认为你对res.writeHead()
的使用现在也可能已经过时了。
我会将您的/sms
路线更改为以下内容:
app.post('/sms', function(req, res) {
const twiml = new MessagingResponse();
twiml.message('Hi, this is Culpability. Your incident has been logged. Your unique id # XXXX');
res.set('Content-Type', 'text/xml');
res.status(200).send(twiml.toString());
});
然后尝试重新部署到Heroku,看看会发生什么。