建议不适用于Google上的操作

时间:2018-12-12 08:24:15

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

我使用dialogflow和Google图书馆上的操作创建了一个聊天机器人。在后端代码中,我创建了包括if在内的函数。我在“否则”中添加了新建议。这些不会显示在Google模拟器上的操作中。另一个建议正在起作用。仅在该时间不显示。请给我一些解决方法。 这是我的代码:

'use strict';
const functions = require('firebase-functions');
const {
   dialogflow,
   Suggestions,
   Carousel,
   Image,
   Table,
   List,
} = require('actions-on-google');
const app = dialogflow({debug: true});

// Constants for list and carousel selection
const Order_Food = 'order food';
const Extra_Product = 'extra product';
const Spa_Reservation = 'spa reservation';
const Restaurant_Booking = 'restaurant booking';

app.intent('user.provide_room_number', (conv) => {
    conv.ask('Great! I can help you with the following. Please select 
from the options below.');
//conv.ask(new Suggestions('Order Food', 'Extra Product', 
  'Restaurant', 'Spa'));
// Create a carousel
conv.ask(new Carousel({
    items: {
        // Add the first item to the carousel
        [Order_Food]: {
          synonyms: [
            'order food',
            'food',
          ],
          title: 'Food',
          description: 'Can order some food',
          image: new Image({
            url: 'http://www.restauranteelpalacete.com/wp-content/uploads/2018/01/Online-Food-Ordering.jpg',
            alt: 'Food',
          }),
        },
          // Add third item to the carousel
          [Spa_Reservation]: {
            synonyms: [
              'spa',
              'spa reservation',
            ],
            title: 'Spa Reservation',
            description: 'Can put the reservation on the spa.',
            image: new Image({
              url: 'https://res.klook.com/images/fl_lossy.progressive,q_65/c_fill,w_1295,h_720,f_auto/w_80,x_15,y_15,g_south_west,l_klook_water/activities/kykzulvt1t71kwhnmkik/OasisSpa.jpg',
              alt: 'Spa',
            }),
          },
          // Add fourth item to the carousel
          [Restaurant_Booking]: {
            synonyms: [
              'restaurant',
              'restaurant booking',
            ],
            title: 'Restaurant',
            description: 'Can put the reservation on the Restaurant.',
            image: new Image({
              url: 'https://cdn-image.foodandwine.com/sites/default/files/1501607996/opentable-scenic-restaurants-marine-room-FT-BLOG0818.jpg',
              alt: 'Restaurant',
            }),
          },
    },
}));

});

 app.intent('actions_intent_OPTION-handler', (conv, params, option) => {
 // Get the user's selection
 // Compare the user's selections to each of the item's keys
 if (!option) {
  conv.ask('You did not select any item from the list or carousel');
} else if (option === 'order food') {
  conv.ask(new SimpleResponse({speech:"Absolutely, have you decided what you like or you could go through the in room dinning menu. \n Do you need order Food.?",text:"Absolutely, have you decided what you like or you could go through the in room dinning menu. Do you need order Food.?"}));
  conv.ask(new Suggestions(["Ok", "Done", "Thanks"]));
} else if (option === 'spa reservation') {
  conv.ask(new Suggestions('Yes I need Spa.'));
  conv.ask(`We have an excellent Spa that offer exquisite treatment packages. You can select one of the options. We have quite a few free slots today. Do you need information about that.`);

} else if (option === 'restaurant booking') {
  conv.ask(`We have some dining options for you today. Do you want more information. `);
  conv.ask(new Suggestions('I need restaurant.'));
} else {
  conv.ask('You selected an unknown item from the list, or carousel');
}

});

1 个答案:

答案 0 :(得分:0)

您应该更有效地设计对话机器人。在第二种情况下,建议之后,意图中不应再进行任何对话。建议是为了触发意图。对于您的情况,最好的方案是创建跟进意图。 建议没有出现在对话中,因为在每个丰富的响应中,至少应存在一个简单的响应。尝试下面的代码。希望对您有帮助。

conv.ask(new SimpleResponse({speech:"Absolutely, have you decided what you like or you could go through the in room dinning menu. \n Do you need order Food.?",text:"Absolutely, have you decided what you like or you could go through the in room dinning menu. Do you need order Food.?"}));
conv.ask(new Suggestions(["Ok", "Done", "Thanks"]));