- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Firebase 云功能开发一个 DialogFlow 项目。我向我的 API 发送 GET 请求并从服务器接收回数据,然后将其显示在 fulfillment 文本属性上。没关系。
现在我需要将来自服务器的 cookie session ID 存储在一种“应用程序变量”中,以便跟踪客户端和服务器之间的交互。我尝试将 cookie session 保存在 Context 对象中,这样做时出现错误:
Agent.getContext 不是 IncomingMessage.resp 中的函数
代码如下:
exports.dialogflowFirebaseFulfillment = functions.https.onRequest( ( req, resp ) =>{
const agent = new WebhookClient( {request: req, response: resp} );
//SET CONTEXT HERE
const context = {
'name': 'sessione',
'lifespan': 2,
'parameters': {'idSessione': c.sessionID}
};
agent.setContext( context );
if( context ){
console.log( '*--*****************-- name context =' + context.name );
}
//...some stuff etc-
//call my function to consume API
callAVA( strRicerca ).then( ( strOutput ) =>{
return resp.json( {'fulfillmentText': strOutput} );
} ).catch( ( error ) =>{
return resp.json( {'fulfillmentText': 'error error'} );
} );
} );
// added parameter Agent-
function callAVA( agent, strRicerca ){
return new Promise( ( resolve, reject ) =>{
https.get( options, ( resp ) =>{
//variable options contains set cookies values , host name etc-
let data = '';
// A chunk of data has been recieved.
resp.on( 'data', ( chunk ) =>{
data += chunk;
} );
// The whole response has been received. Print out the result.
resp.on( 'end', () =>{
let c = JSON.parse( data );
let strOutput = c.output[0].output;
console.log( '----- ID DELLA SESSIONE : ' + c.sessionID );
if( c.sessionID ){
// I NEED TO SAVE IDSESSION FROM SERVER -
let context = agent.getContext( 'sessione' );
// GOT ERROR: agent.getContext is not a function at IncomingMessage.resp (????)
context.parameters.idSessione = c.sessionID;
}
resolve( strOutput );
//DO OTHER STUFF...
} );
resp.on( "error", ( err ) =>{
console.log( "Error: " + err.message );
reject( err.message );
} );
} );
} );
}
有没有其他方法可以跟踪向服务器发送请求的用户?我宁愿在不访问数据库的情况下保持简单......非常感谢,任何帮助将不胜感激。 :)
____________________________________ 编辑__________________________________暂时搁置上下文,我意识到我遗漏了一些要点,所以我已经根据您的建议修改了我的代码如下:
const functions = require('firebase-functions');
const querystring = require('querystring');
const {WebhookClient} = require('dialogflow-fulfillment');
const https = require('http');
postData = querystring.stringify({
'searchText': 'ciao',
'user':'',
'pwd':'',
'ava':'FarmaInfoBot'
});
const options = {
hostname: '86.107.98.69',
port: 8080,
path: ‘/mypath/search_2?searchText=',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(postData),
'Cookie':'JSESSIONID=' // -> this comes from the server, store it in context, conv.data or what else-> to do
}
};
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((req, resp) => {
const agent = new WebhookClient({ request: req, response: resp});
let strRicerca='';
if (req.body.queryResult.parameters['searchText']) {
strRicerca=req.body.queryResult.parameters['searchText'];
options.path+=strRicerca+'&user=&pwd=&ava=FarmaInfoBot';
}
/* IS THIS OK NOW TO INVOKE FUNCTION LIKE THIS, NOW THAT I ADDED AGENT ? */
callAVA(agent, strRicerca).then((strOutput)=> {
return resp.json({ 'fulfillmentText': strOutput });
}).catch((error) => {
return resp.json({ 'fulfillmentText': 'error!!!!!!!!!!'});
});
function callAVA(agent, strRicerca) {
return new Promise((resolve, reject) => {
https.get(options, (resp) => {
let data = '';
console.log(`STATUS RESPONSE: ${resp.statusCode}`);
console.log(`HEADERS RESPONSE: ${JSON.stringify(resp.headers)}`);
resp.on('data', (chunk) => {
console.log(`BODY: ${chunk}`);
var c=JSON.parse(chunk);
});
resp.on('end', () => {
let c=JSON.parse(data);
let strOutput= agent.add('Static response from Agent'); // c.output[0].output;
console.log(strOutput);
resolve(strOutput);
});
resp.on("error", (err) => {
console.log("Error: " + err.message);
reject(err.message);
});
});
});
}
let intentMap = new Map();
intentMap.set('test_fb', callAVA);
agent.handleRequest(intentMap);
});
现在程序正在运行,但我收到一个空响应,崩溃发生在结束事件中,正在解析 Json 数据。我的最终目标是找到一种方法,将来自服务器的 cookie 保存在一个全局变量中,并在整个对话中保持它。
最佳答案
看来这里有一些问题。
如果您的错误的直接原因是您将 callAVA()
函数定义为
function callAVA( agent, strRicerca )
但是当你在前面几行调用它时,你忽略了 agent
参数:
callAVA( strRicerca )
但是,从长远来看,您使用它的方式还有其他问题会给您带来麻烦。
虽然您正在做的事情可能是有效的,并且可能有效,但它也不同于通常的处理方式,并且您可能会因此导致一些问题。
通常,您创建 agent
,然后针对它注册 Intent Handlers。有点像
let intentMap = new Map();
intentMap.set('intent.name.1', intentHandlerFunction1);
intentMap.set('intent.name.2', intentHandlerFunction2);
agent.handleRequest(intentMap);
它将使用单个参数 agent
调用 Intent 名称的匹配函数。 (顺便说一句 - 返回 Promise 做得很好!你的那部分是正确的。)
作为 Intent 处理程序的一部分,您需要在 Promise 完成之前调用 agent.setContext(context)
。在后面的 Intent handler 中,当你想知道这个值时,你需要调用 agent.getContext('context-name')
它应该返回整个 Context 对象,包括剩余的生命周期和参数为了它..
更新
您在第一次编辑中所做的更改还不够。问题是您混合使用两种不同的方式来调用 Intent Handler:
在一种方式中,您直接使用第二个参数调用它。作为结果的一部分,它将 JSON 发送到 resp
对象。
换句话说,您已经使用 intentMap.set()
注册了它,这导致它被调用(仅使用 agent
参数)当调用 handleRequest()
并通过 agent
对象设置响应时。
一般来说,除非你想自己操作所有的JSON,否则你应该依赖方法(2)。您应该不自己直接调用 Intent Handler 函数,而应该让 handleRequest()
为您处理它。
由于您需要 strRicerca
对象,您可以在函数运行的相同范围内提供它,这似乎已经是这样了。因此您可能不需要将其作为参数包含在内。
关于dialogflow-es - 带有 Webhook 客户端 : Error agent. getContext 的 DialogFlow 不是 IncomingMessage.resp 中的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52189160/
自从我将 Dialogflow 升级为使用 v2 API 后,出现以下错误: Dialogflow IntentHandler not found for intent: myIntent 由于某些原
PermissionDenied:拒绝了“projects/XXXX-live/agent”上的403 IAM权限“dialogflow.sessions.detectIntent”。 创建服务时,我
基本上,我的代理人是法国人,当我输入 10h(12 小时格式为上午 10 点)时,我的 DialogFlow 代理人理解 22h(晚上 10 点),但我希望他理解上午 10 点。 (我想要 24 小时
我和我的团队正在使用 Dialogflow 为 Facebook Messenger 构建一个机器人,但由于我们的用户不会说同一种语言(西类牙语是项目中的默认语言),我们想要实现我们项目的英文版本,但
我是新来的 DialogFlow ,我开始创建代理,从smaltalk从头开始。问题是如何将更多预构建代理(例如警报和应用程序管理,以及货币转换器)附加到新创建的代理中? 谢谢你的帮助。 最佳答案 您
在 Dialogflow 中,通过扩展设置为自动化的“训练实体”的最佳方法是什么。在训练短语中添加实体和在实体屏幕中简单地添加示例值之间有什么区别吗? Dialogflow 培训是否比另一个更重视?创
我正在尝试训练 Dialogflow 机器人来识别不同的旅行请求(航类预订、酒店预订等)。我发现如果没有将时间指定为 12 小时格式(使用 AM/PM),它就不能正确解析时间。 我需要周六 08:00
我正在使用 webhook 在 dialogflow 上制作一个机器人。我收到一个错误:DEADLINE_EXCEEDED。我的 webhook 需要 5 秒多一点的时间来返回响应。有没有办法允许超过
我正在使用 Dialogflow 为银行创建一个机器人。我想保留与客户代表交谈的选择权。如果客户想与客户代表交谈,机器人应该停止,客户代表开始与客户聊天。在 Dialogflow 中如何实现。 最佳答
每当我输入 6 月 37 日作为输入时,它都不会给出错误,而是将日期视为 6 月 30 日。我想要做的是在输入 6 月 37 日时创建一个错误提示。 我在一个非常简单的意图上使用@sys.date,它
有没有办法以编程方式获取 Dialogflow 代理的对话历史记录? 我使用 Dialogflow 制作了一个聊天机器人。现在我需要以编程方式获取代理的对话历史记录。 最佳答案 That featur
我正在研究 dialogflow 跟进意图。结构是这样的。 它为每个新意图创建新上下文。 例如在重复意图中看到 每当我创建任何新意图时,它都会为其创建新上下文。正如你在图片中看到的那样。当我尝试删除这
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 4 年前。 Improve this qu
例如,如果您有 IntentA 并添加了 2 个后续意图:IntentB、IntentC,它工作正常,它应该添加一个上下文,因为它还没有输出上下文。但这就是问题所在。有时如果你添加另一个,例如 Fal
我正在使用 dialogflow 开发语音助手,我对意图的生命周期有疑问。据我了解,生命周期值为我提供了此意图中可能的交互次数。它在每次交互时递减,当等于 0 时,该值不能被识别为意图的可能值。 生命
我创建了一个聊天机器人,它会通知用户我(大)家庭成员的姓名以及他们的生活地点。我用 MySQL 创建了一个小型数据库,其中存储了这些数据,并在适当的时候使用 PHP 脚本获取它们,具体取决于用户与聊天
我想使用 dialogflow 进行注册。例如:我想让机器人问以下问题: 你叫什么名字?你的邮箱是多少? 等等。 我尝试实现此功能,但无法正确管理意图。我应该怎么做才能实现这一目标?谢谢 最佳答案 首
我希望尽可能生成动态文本而不需要创建 webhook。我知道创建动态文本的唯一方法是根据参数创建不同的路由或通过 using inline system functions像文本实现中的 $sys.f
我使用 创建了一个聊天机器人对话流 并与 集成Telegram、Facebook Messenger 和 Web . Dialogflow 的响应是通过 创建的履行用 Python 编写。 在 Tel
我使用 Dialogflow 创建了多个代理,其中许多都在生产中。但是,Dialogflow 项目突然消失了,现在我只能看到创建新代理的选项。 但是,我看到生产代理运行良好。我通过我创建的连接到 Di
我是一名优秀的程序员,十分优秀!