对话流上下文 [英] Dialogflow Context

查看:55
本文介绍了对话流上下文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一些问题,我无法从dialogflow的上下文中访问参数,我只是尝试使用 agent.getContext agent.context.get ,但仍然无法工作.

I got some problem, I can't access my parameters from context on dialogflow, i just trying using agent.getContext and agent.context.get but still not work.

有我的代码来设置上下文

there is my code for set the context

function noTelp(agent){
const telp = agent.parameters.phoneNumber;

let query = db.collection('pelanggan').where('no_telp','==',telp);
return query.get().then(snapshot => {
    if (snapshot.empty) {
      agent.add('Mohon Maaf data no telepon '+telp+' tidak ditemukan');
      agent.add('untuk menambahkan data kamu silahkan tuliskan nama kamu');
      agent.setContext({     >set the context
        name : 'tambahData',
        lifespan : 2,
        parameters : {noTelp : telp}
      });
      console.log('No matching documents.');
      return;
    }
}

这是用于调用上下文的

function tambahData(agent){
   const context = agent.getContext('tambahData'); >get the context
   const telp = context.parameters.noTelp; >get the parameters from context
   const nama = agent.parameters.nama;

   agent.add(nama+telp); >test calling parameters
}

推荐答案

使用了V1或V2中的一致方法.您可以按以下方式修改代码,它将起作用.我只能这样工作.

Used a consistent method either from V1 or V2. You can modify the code as below, it will work. I managed to work like this only.

设置上下文:

agent.context.set({
        name: 'global_main_context',
        lifespan: 5,
        parameters: param
    });

获取上下文

let globalContext = agent.context.get('global_main_context');

我建议继续更新每个事务中的上下文,因为它是生命周期,如果您跨多个事务,它将自动杀死该上下文.

I would suggest to keep updating the context in each of transaction because it as lifespan that will automatically kill that context if you cross a number of transactions.

这篇关于对话流上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆