代码之家  ›  专栏  ›  技术社区  ›  Patwie

请求许可时的错误响应

  •  0
  • Patwie  · 技术社区  · 6 年前

    我正在努力创建一个请求用户许可的非常基本的示例。设置是

    意图:

     "request_permission":
       - phrase "where am I?"
       - action: "request_permission"
       - events: <empty>
     "user_info":
       - phrase: <empty>
       - action: "user_info"
       - events: "actions_intent_PERMISSION" 
    

    下面是使用节点的官方示例。我写道:

    'use strict';
    
    const functions = require('firebase-functions');
    const {Permission, DialogflowApp} = require('actions-on-google');
    const {WebhookClient} = require('dialogflow-fulfillment');
    const {Card, Suggestion, SimpleResponse} = require('dialogflow-fulfillment');
    
    const app = dialogflow({debug: true});
    
    process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
    
    exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
      const agent = new WebhookClient({ request, response });
      const app = new DialogflowApp({request, response});
    
      function welcome_intent(agent) {agent.add(`welcome intent`); }
      function fallback_intent(agent) {agent.add(`fallback intent.`); }
    
      function request_permission(agent){
        let conv = agent.conv();
        conv.ask(new Permission({
          context: 'I need your location',
          permissions: 'DEVICE_COARSE_LOCATION'
        }))
        agent.add(conv);
      }
    
      function user_info(agent){
        if (app.isPermissionGranted()) {
          const zipCode = app.getDeviceLocation().zipCode;
          if (zipCode) {
              app.tell(`your zip code ise ${zipCode}`);
          } else {
              app.tell('I cannot tell your zip code.');
          }
        } else {
            app.tell('Without permission I cannot tell the zip code');
        }
      }
    
      let intentMap = new Map();
      intentMap.set('Default Welcome Intent', welcome_intent);
      intentMap.set('Default Fallback Intent', fallback_intent);
      intentMap.set('request_permission', request_permission);
      intentMap.set('user_info', user_info);
      agent.handleRequest(intentMap);
    });
    

    不过,当启动模拟器并激活我的应用程序,然后问“我在哪里?”我明白了

    MalformedResponse
    'final_response' must be set.
    

    是的,我确实检查了firebase控制台日志,“实现”——滑块“启用此事件的webhook调用”处于打开状态。

    我不会在这里问是否会有一个V2兼容的示例,其中包含一个非常基本的权限请求。我知道答案 Dialogflow v2 API + Actions v2 API: MalformedResponse 'final_response' must be set

    0 回复  |  直到 6 年前