node.js - 如何从 node.js 对话框流包设置对话框流上下文
问题描述
我正在使用sessionClient.detectIntent()
将文本发送到对话流并且它工作正常,现在我也想用文本发送上下文。我怎样才能做到这一点?
解决方案
我通常通过以下方式创建上下文:
exports.createContext = async function(contextId, parameters, sessionPath, sessionId, lifespan = 333) {
let contextPath;
try {
contextPath = contextClient.contextPath(projectId, sessionId, contextId);
} catch (e) {
console.error("Error => ");
console.error(e)
}
const request = {
parent: sessionPath,
context: {
name: contextPath,
parameters: struct.encode(parameters),
lifespanCount: lifespan
}
};
contextClient.createContext(request)
};
当我必须在调用 detectIntent 方法之前创建上下文时,只需调用此方法即可:
bot.createContext('CONTEXT_NAME_GOES_HERE', '{PARAMETER: VALUE}', sessionPath, session_id, lifespan = 1);
推荐阅读
- html - 向用户提供大容量图像的安全方法?
- c# - 使用 MySQL 创建 edmx“字典中不存在给定的键”
- php - 如何使用 PHP 搜索和替换 MS Word 文档中的文本片段
- asp.net-mvc - ASP.NET 日期范围约束/验证
- c# - System.Data.Sqlite dll不同版本对同一个数据库返回不同的BOOL值
- jestjs - 配置 jest 在不同的文件夹中运行测试
- bash - 在 bash 中切割字符串周围的所有内容
- android - 更新到版本“4.10.1”/“4.10.2”后 Gradle 同步失败
- javascript - 如何从巴尔干图中的二进制图像数据加载图像
- adaptive-cards - 是否可以提供自定义 input.date 自适应卡