Dialogflow 客户端跟进意图

Dialog Flow Client Followup Intent

我想知道是否有一种方法可以跟踪意图的上下文。我知道您可以使用前一个意图的输出上下文作为后续意图的输入上下文。但这意味着我也必须跟踪寿命。还有别的办法吗???

var context = [];

async function TextRecognition(queryText) {
    const sessionId = uuid.v4();


    const sessionPath = sessionClient.sessionPath(projectId, sessionId);

    // The text query request.
    const request = {
        session: sessionPath,
        queryInput: {
            text: {
                // The query to send to the dialogflow agent
                text: queryText,
                // The language used by the client (en-US)

                languageCode: 'en-US',
            },
        },
    };
    if (contextList !== null && contextList.length !== 0) {
        console.log(contextList);
        request.queryParams = {
            contexts: context,
        };
    }

    const responses = await sessionClient.detectIntent(request);
    const result = responses[0].queryResult;
    if (result.intent) {
        if (typeof result.outputContexts[0] !== 'undefined') {
            result.outputContexts.forEach(context => {
                context.push(context);
            });
        }

        return result.fulfillmentText;
    } else {
        console.log(`No intent matched.`);
    }
}

找到答案 :) 首先没有问题,只需确保为每个客户端创建会话 ID,您不需要跟踪 dialogflow 为您做的任何事情:p