我在节点js后端工作,它使用telerivet webhook API从Android应用程序接收用户短信。每当我运行应用程序atheroku时它给我不能GET /错误,我的index.js代码是
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
var WEBHOOK_SECRET = "62DZWMCCFFHTTQ44CG3WUQ94CTT7GAAN";
app.post('/telerivet/webhook',
bodyParser.urlencoded({ extended: true }),
function(req, res) {
var secret = req.body.secret;
if (secret !== WEBHOOK_SECRET) {
res.status(403).end();
return;
}
if (req.body.event == 'incoming_message') {
var content = req.body.content;
var from_number = req.body.from_number;
var phone_id = req.body.phone_id;
// do something with the message, e.g. send an autoreply
res.json({
messages: [
{ content: "Thanks for your message!,Our Backend Is Still in Alpha Stage,Hang Tight" }
]
});
}
res.status(200).end();
}
);
app.listen(process.env.PORT || 5000);
请帮助,我在做错了 它让我在浏览器上运行应用程序时无法获取/错误,并且在使用应用程序进行测试时也无法回复短信
答案 0 :(得分:0)
我找到了出路,这是我的新代码:
var express = require('express');
var app = express();
app.set('port', (process.env.PORT || 5000));
app.use(express.static(__dirname + '/public'));
app.get('/', function(request, response) {
response.send('Hello World!');
});
var bodyParser = require('body-parser');
var WEBHOOK_SECRET = "62DZWMCCFFHTTQ44CG3WUQ94CTT7GAAN";
app.post('/telerivet/webhook', bodyParser.urlencoded({ extended: true }),function(req, res) {
var secret = req.body.secret;
if (secret !== WEBHOOK_SECRET) {
res.status(403).end();
return;
}
if (req.body.event == 'incoming_message') {
var content = req.body.content;
var from_number = req.body.from_number;
var phone_id = req.body.phone_id;
// do something with the message, e.g. send an autoreply
res.json({
messages: [
{ content: "Thanks for your message!,Stay Tuned for Awesome " }
]
});
}
res.status(200).end();
}
);
app.listen(app.get('port'), function() {
console.log('Node app is running on port', app.get('port'));
});