【问题标题】:store agent SessionsClient of dialogflow api存储 dialogflow api 的代理 SessionsClient
【发布时间】: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


    【解决方案1】:

    我解决了这个问题,只是保存 SessionId 并在以后的调用中传递相同的 id 而不是生成一个新的

    async reestablishSession({projectId, google_app_credentials, sessionId}) {
        process.env.GOOGLE_APPLICATION_CREDENTIALS = google_app_credentials;
        const sessionClient = new dialogflow.SessionsClient();
        const sessionPath = await sessionClient.projectAgentSessionPath(projectId, sessionId)
        await sessionClient.initialize();
        return {
            sessionId: sessionId,
            sessionClient: sessionClient,
            sessionPath: sessionPath,
        };
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-02
      • 1970-01-01
      • 1970-01-01
      • 2021-01-16
      相关资源
      最近更新 更多