如何删除或将寿命设置为零-Dialogflow代理上下文

时间:2018-12-10 16:09:43

标签: dialogflow actions-on-google

我想问你如何将上下文的寿命设置为零或为空。

我尝试过的示例:

    const { WebhookClient } = require('dialogflow-fulfillment'); //"dialogflow-fulfillment": "^0.5.0"

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

agent.context.set({
            'name': 'context_name',
            'lifespan': 0 
          });

agent.context.set({
            'name': 'context_name',
            'lifespan': null
          });

agent.setContext({ name: 'context_name', lifespan: 0 });

agent.setContext({ name: 'context_name', lifespan: null });

agent.context.delete('context_name');

但是,它总是将自身再次设置为5。

是否可以删除或将其设置为零?

3 个答案:

答案 0 :(得分:0)

您需要使用clearContext()

const { WebhookClient } = require('dialogflow-fulfillment'); //"dialogflow-fulfillment": "^0.5.0"

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

agent.clearContext('context_name');

希望有帮助。

答案 1 :(得分:0)

您需要清除意图处理程序中的上下文。每次调用意图时,上下文都会更新。清除上下文的首选方法是

agent.context.delete('context_name');

答案 2 :(得分:0)

尝试执行以下操作,将寿命设置为“ -1”:

agent.setContext({ name: 'context_name', lifespan: -1 });