1

DialogFlow Fulfillment ライブラリでパラメータ値を更新するにはどうすればよいですか? エージェントのコンテキストにアクセスし、値の更新をループするヘルパー メソッドを作成しましたが、機能していないようです。

export const dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
    const wbhc = new WebhookClient({ request, response });

    function testIntentHandler(agent: any) {
        const date = agent.parameters['date'];
        const datePeriod = agent.parameters['date-period'];

        if (date && !datePeriod) {
            setDialogFlowParameter('date-period', {
                startDate: date,
                endDate: date
            }, agent.context);
        }

        agent.add("I've set the value");
    }

    // Run the proper function handler based on the matched Dialogflow intent name
    const intentMap = new Map();
    intentMap.set('TestIntent', testIntentHandler);
    wbhc.handleRequest(intentMap);
});

function setDialogFlowParameter(param: string, val: any, context: any) {
    const contexts = context.contexts;
    const keys = Object.keys(contexts);

    for (const key of keys) {
        const c = context.get(key);
        c.parameters[param] = val;
        context.set(key, c.lifespan, c.parameters);
    }
}

この質問はNodeJSのダイアログフローフルフィルメントライブラリに焦点を当てていることに注意してください.何時間も検索しても答えが見つかりませんでした.

4

1 に答える 1