【发布时间】:2021-01-21 14:13:06
【问题描述】:
我正在聊天中集成对话流,但我遇到了问题。我不知道如何存储与代理的会话
async startSession({projectId, google_app_credencials}) {
process.env.GOOGLE_APPLICATION_CREDENTIALS = google_app_credencials;
const sessionId = uuid.v4();
const sessionClient = new dialogflow.SessionsClient();
const sessionPath = await sessionClient.projectAgentSessionPath(projectId, sessionId)
await sessionClient.initialize();
return {
sessionId: sessionId,
sessionClient: sessionClient,
sessionPath: sessionPath,
};
}
async sendMessageAndGetResponse(message, {sessionPath, sessionClient}) {
const request = {
session: sessionPath,
queryInput: {
text: {
text: message,
languageCode: 'pt-BR',
},
},
};
const responses = await sessionClient.detectIntent(request);
const result = responses[0].queryResult;
return {
response: result.fulfillmentText,
fields: result.parameters.fields,
}
}
我需要在每次调用sendMessageAndGetResponse 时返回startSession,然后我需要存储我的nodejs 服务器。但我在 redis 中存储 SessionsClient 的尝试失败了。现在我想知道是否有一种方法可以在以后的调用中仅使用 SessionPath 重新建立与代理的连接。
//attempt to save in redis
let dialogflowBot = {
projectId: dialogflow.project_name,
google_app_credencials: DialogflowHelper.getCredentialsPath(dialogflow)
}
dialogflowBot.bot = await DialogflowHelper.startSession(dialogflowBot);
redisClient.set(filaChat.id_registro, JSON.stringify(dialogflowBot));
//error: Converting circular structure to JSON
//Can't save the sessionClient
如何保存SessionClient 以便稍后再次呼叫他,或者只保存SessionPath 以重新建立连接?
【问题讨论】:
标签: javascript node.js redis dialogflow-es