对话流程-实现-图书馆和快递,关于什么? [英] dialogflow-fulfillment-library and express, what to res on?
本文介绍了对话流程-实现-图书馆和快递,关于什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将对话履行库与express一起使用,而不使用Firebase函数。不过,我很难找到如何对付这名特工的方法。
const { WebhookClient, Card, Suggestion } = require('dialogflow-fulfillment');
module.exports = function () {
let self = {};
self.create = function (req, res, next) {
const agent = new WebhookClient({request: req, response: res});
agent.add(new Suggestion(`Quick Reply`));
agent.add(new Card({
title: `Title: this is a card title`,
imageUrl: 'https://developers.google.com/actions/images/badges/XPM_BADGING_GoogleAssistant_VER.png',
text: `This is the body text of a card. You can even use line
breaks and emoji! 💁`,
buttonText: 'This is a button',
buttonUrl: 'https://assistant.google.com/'
})
);
res.json(agent);
};
return self;
};
我遇到TypeError:将循环结构转换为JSON
我试过取消代理的循环,但在对话流端不起作用。
使用:
res.send(JSON.stringify(agent, decycle()));
退货:Webhook call failed. Error: Failed to parse webhook JSON response: Cannot find field: request_ in message google.cloud.dialogflow.v2.WebhookResponse.
有没有人这样用过,还是不可能?
推荐答案
我已为此提交了Pull Request。
以下代码适合我。
Package.json
{
"name": "Test_Agent",
"version": "0.0.1",
"description": "Test Agent webhook",
"main": "server.js",
"author": "Abhinav Tyagi, New Delhi, India",
"dependencies": {
"dialogflow-fulfillment": "^0.4.1",
"body-parser": "^1.18.3",
"express": "^4.16.3",
"actions-on-google": "^2.2.0"
}
}
server.js
'use strict';
const {WebhookClient} = require('dialogflow-fulfillment');
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
function welcome (agent) {
agent.add(`Welcome to Express.JS webhook!`);
}
function fallback (agent) {
agent.add(`I didn't understand`);
agent.add(`I'm sorry, can you try again?`);
}
function WebhookProcessing(req, res) {
const agent = new WebhookClient({request: req, response: res});
console.info(`agent set`);
let intentMap = new Map();
intentMap.set('Default Welcome Intent', welcome);
intentMap.set('Default Fallback Intent', fallback);
// intentMap.set('<INTENT_NAME_HERE>', yourFunctionHandler);
agent.handleRequest(intentMap);
}
// Webhook
app.post('/', function (req, res) {
console.info(`
>>>>>>> S E R V E R H I T <<<<<<<`);
WebhookProcessing(req, res);
});
app.listen(8080, function () {
console.info(`Webhook listening on port 8080!`)
});
确保同时使用Google上的操作模块和Dialogflow实现模块。
这篇关于对话流程-实现-图书馆和快递,关于什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文