gpt4 book ai didi

node.js - dialogflow-fulfillment-library 和express,需要什么?

转载 作者:太空宇宙 更新时间:2023-11-03 22:43:21 24 4
gpt4 key购买 nike

我正在尝试将dialog-fulfillment-library与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\n breaks and emoji! 💁`,
buttonText: 'This is a button',
buttonUrl: 'https://assistant.google.com/'
})
);

res.json(agent);
};

return self;
};

我收到一个类型错误:将循环结构转换为 JSON我尝试过回收代理,但它在对话流端不起作用。使用:

  res.send(JSON.stringify(agent, decycle())); 

返回:Webhook 调用失败。错误:无法解析 Webhook JSON 响应:在消息 google.cloud.dialogflow.v2.WebhookResponse 中找不到字段:request_。

有人用过这种方法吗,还是不行?

最佳答案

我已提交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);
res.status(200).send(agent);
}


// Webhook
app.post('/', function (req, res) {
console.info(`\n\n>>>>>>> S E R V E R H I T <<<<<<<`);
WebhookProcessing(req, res);
});

app.listen(8080, function () {
console.info(`Webhook listening on port 8080!`)
});

确保同时使用action-on-google 和dialogflow-fulfillment 模块。
intentMap 键是 intent.displayName

关于node.js - dialogflow-fulfillment-library 和express,需要什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51406463/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com