Webhook 允许 GET 方法
Webhook allowing GET method
根据文档,
"When an intent in which a webhook was enabled is triggered,
Dialogflow sends data to the service in the form of POST request with
a POST body in the format of response to a query."
所以我假设 GET 请求是不可能的...不是吗?
在 Postman 中,我可以使用我的代码发出 GET 请求,但是在部署到 Heroku 并在 fulfillment 部分设置 URL 之后,除了 [=22] 之外,我无法得到任何正确的响应=].
非常感谢。
这是代码。
这是我第一次尝试使用 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);
正确,GET 请求是不可能的。发送的 JSON 的大小很容易超过 GET 允许的 URL 长度。
根据文档,
"When an intent in which a webhook was enabled is triggered, Dialogflow sends data to the service in the form of POST request with a POST body in the format of response to a query."
所以我假设 GET 请求是不可能的...不是吗?
在 Postman 中,我可以使用我的代码发出 GET 请求,但是在部署到 Heroku 并在 fulfillment 部分设置 URL 之后,除了 [=22] 之外,我无法得到任何正确的响应=].
非常感谢。
这是代码。 这是我第一次尝试使用 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);
正确,GET 请求是不可能的。发送的 JSON 的大小很容易超过 GET 允许的 URL 长度。