【问题标题】:Google Assistant Session Entity Some time working sometime not working.. nodejs谷歌助理会话实体有时工作有时不工作.. nodejs
【发布时间】:2019-10-09 23:05:19
【问题描述】:

我有一个代码..从谷歌上的操作给出..有时它工作有时它不是..如果有人有任何想法帮助我.. 会话实体无法正常工作

const dialogflowAPI = require('dialogflow');
const sessionClient = new dialogflowAPI.SessionEntityTypesClient();
const client = new dialogflowAPI.EntityTypesClient();
const entityList = ['measure','dimension','size'];
const size = ['top','bottom','high','highest','low','lowest'];
exports.entityList=entityList;
exports.size=size;
exports.createSessionEntityType = async function(conv,entityName,entityValues){
try{
    const sessionEntityType = {
    name: conv.body.session + '/entityTypes/'+entityName,
    entityOverrideMode: 1,
    entities: entityValues,
  };
  const request = {
        parent: conv.body.session,
        sessionEntityType: sessionEntityType,
  };
  console.log(sessionEntityType);
  const [response] = await sessionClient.createSessionEntityType(request);
} catch(e) { 
   console.log(e); 
} 

【问题讨论】:

    标签: node.js dialogflow-es actions-on-google


    【解决方案1】:

    Actions on Google 处理会话实体的方法不同。您无需调用 API,而是在 Webhook 响应中提供实体。 documentation 显示了提供此信息的新方法。它还提供了一个代码 sn-p,说明如何在 Node.js 库中执行此操作。

    app.intent('input.welcome', (conv) => {
      conv.ask('make your choice: apple or orange?');
      // Set the fruit session entity values to 'apple' and 'orange'.
      const responseBody = conv.serialize();
      responseBody['sessionEntityTypes'] =  [ {
        name: conv.body.session + '/entityTypes/fruit',
        entities: [{
            value: 'APPLE_KEY',
            synonyms: [
              'apple', 'green apple', 'crabapple'
            ]
         },
         {
            value: 'ORANGE_KEY',
            synonyms: [
             'orange'
            ]
         }],
        entityOverrideMode: 'ENTITY_OVERRIDE_MODE_OVERRIDE'
      }];
      conv.json(responseBody);
    });
    

    【讨论】:

    • 只有单个实体在工作...如果我有 2 个实体称为“度量”和“维度”.. 那个时候最后一个实体(“维度”)正在工作..如果我有单个实体称为“测量”那个“测量”正常工作的时间..所以基本上只有单个实体工作..我想要多个会话实体......谢谢
    • Nodejs const responseBody = conv.serialize(); responseBody['sessionEntityTypes'] = [ { name: conv.body.session + '/entityTypes/'+entityName, entities: entityValues, entityOverrideMode: 'ENTITY_OVERRIDE_MODE_SUPPLEMENT', Kind:'KIND_MAP' }]; conv.json(responseBody);
    • 我有 3 个不同的实体.. 一次只有一个实体在工作,最后一次推送..
    • 但是您是否将所有会话实体设置在数组的正确级别?
    • 完成了兄弟谢谢..单个实体仅在单个意图中工作..我为 3 个实体创建了 3 个新意图.. 它有效:)
    猜你喜欢
    • 2015-05-14
    • 2018-01-13
    • 1970-01-01
    • 2017-06-08
    • 1970-01-01
    • 2023-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多