【发布时间】:2019-05-17 01:53:09
【问题描述】:
我有一个关于 webhook 连接的问题。
我通常通过对话框流的内联编辑器进行编辑。
但现在我想在本地编辑。
所以我做了一些设置,看两个例子。
https://chatbotsmagazine.com/creating-nodejs-webhook-for-dialogflow-2b050f76cd75
https://github.com/dialogflow/fulfillment-temperature-converter-nodejs
[1] 我制作了文件,
(1) 用户/a/firebase.js
(2) Users/a/functions/index.js(带包模块)
(3) ngrok 的 webhook 服务器。
(4) 我在 dialogflow webhook 上附加了这个链接“https://ngrok~~/webhook”
[2] firebase.js 有
{}
[3] index.js 有
'use strict';
const express = require('express');
const bodyParser = require('body-parser');
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
const request = require('request');
const { dialogflow } = require('actions-on-google');
const app = dialogflow();
const admin = require('firebase-admin');
const server = express();
//admin.initializeApp();
process.env.DEBUG = 'dialogflow:debug';
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
console.log('Dialogflow Request body: ' + JSON.stringify(request.body));
function hello(agent) {
agent.add(`Welcome to my agent!`);
}
function fallback(agent) {
agent.add(`I didn't understand`);
agent.add(`I'm sorry, can you try again?`);
}
let intentMap = new Map();
intentMap.set('hello', hello);
intentMap.set('Default Fallback Intent', fallback);
agent.handleRequest(intentMap);
});
var port = process.env.PORT || 3000;
// create serve and configure it.
server.get('/getName',function (req,res){
res.send('Swarup Bam');
});
server.listen(port, function () {
console.log("Server is up and running...");
});
服务器在本地以ngrok port 3000 启动。
我在我的代码中写了server.listen。
但它似乎在我的代码中没有 webhook 帖子。
因此,总而言之,当我在 dialogflow 中写下 'hello' 时,ngrok 会给出 404 not found 错误。
【问题讨论】:
-
您能否更新您的问题以澄清您所说的“没有 webhook 输出”是什么意思。你在尝试什么,当你尝试时你看到了什么?你是如何在本地启动服务器的?
-
请更新问题 - 不要试图在 cmets 中做广泛的答案,只需在更新问题后回复即可。 cmets 最好要求澄清,以便我们可以创建一个问题,为您和可能有类似问题的其他人解释您的情况。
-
我编辑了我的问题并删除了 cmets。非常感谢您提供有关如何使用 stackoverflow 的建议! :)
标签: javascript node.js firebase dialogflow-es chatbot