【发布时间】:2017-05-09 21:59:23
【问题描述】:
我使用以下文件启动了一个 Heroku 应用程序:-
app.js
'use strict'
const express = require('express')
const bodyParser = require('body-parser')
const request = require('request')
const app = express()
app.set('port', (process.env.PORT || 5000))
// Process application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({extended: false}))
// Process application/json
app.use(bodyParser.json())
// Index route
app.get('/', function (req, res) {
res.send("Hello world, I seem to be working")
})
// for Facebook verification
app.get('/webhook', function (req, res) {
if (req.query['hub.verify_token'] === 'test-token') {
res.send(req.query['hub.challenge']);
} else {
res.send('Error, wrong validation token');
}
})
// Spin up the server
app.listen(app.get('port'), function() {
console.log('running on port', app.get('port'))
})
.gitignore
node_modules
package.json
{
"name": "heroku-node-practice",
"version": "1.0.0",
"description": "New bot",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node app.js"
},
"author": "Paigal",
"license": "ISC",
"dependencies": {
"body-parser": "^1.17.1",
"express": "^4.15.2",
"foobar": "^1.1.0",
"mongoose": "^4.9.8",
"request": "^2.81.0"
}
}
过程文件
web: node app.js
我使用以下命令安装了 node.js 依赖项:npm install express request body-parser --save
git push heroku master 之后,应用程序正确启动。
但是,当尝试在 fb developer 中设置 webhook 时,错误是“无法验证 URL。响应与预期挑战不匹配'然后对挑战给出不同的响应。也就是说,我的 URL 响应的是“Hello world,我似乎在工作”而不是数字键。
非常感谢您的帮助!
【问题讨论】:
-
听起来您没有为 webhook 指定正确的 URL ...
标签: node.js facebook heroku chatbot facebook-chatbot