根据文件,
“触发启用webhook的意图时, Dialogflow以POST请求的形式向服务发送数据 一个POST主体,其格式为对查询的响应。“
所以我认为GET请求是不可能的......不是吗?
在邮递员中,我可以使用我的代码发出GET请求,但在部署到Heroku并在履行部分设置URL后,除了“Webhook调用失败”之外,我无法获得任何正确的响应。错误:404 Not实测值”。
非常感谢。
这是代码。 这是我第一次尝试使用Node: - )
const express = require('express');
const bodyParser = require('body-parser');
const http = require('https');
var port = process.env.PORT || 8080;
const server = express();
server.use(bodyParser.json());
server.post('/get-movie-details', function (req, res) {
//This line is crashing the app in Heroku from Dialogflow. Paramaters are not correctly passed
let movieToSearch = req.body.result.parameters.query;
let finalurl = encodeURI('https://api.themoviedb.org/3/search/movie?api_key=c21ed50674dabf90143d1136bf9279ae&language=en-US&query=' + req.body.result.parameters.query + '&page=1&include_adult=false');
console.log('This is the finalUrl: ' + finalurl);
http.get(finalurl, (responseFromAPI) => {
responseFromAPI.on('data', function (chunk) {
let movie = JSON.parse(chunk)['results'][0];
let dataToSend = movie.original_title + ' is a ' + movie.vote_average + ' vote average released in ' + movie.release_date + '. Maybe you want some more information?';
return res.json({
speech: dataToSend,
displayText: dataToSend,
source: 'The movieDataBase'
});
});
}, (error) => {
return res.json({
speech: 'Something went wrong!',
displayText: 'Something went wrong!',
source: 'get-movie-details'
});
});
});
server.listen(port);
console.log('Server started! At https://localhost:' + port);
答案 0 :(得分:2)
正确,GET请求是不可能的。发送的JSON大小很容易超过GET允许的URL长度。