如何使用Carrousel作为响应在dialogflow上创建意图?

时间:2019-04-16 12:28:44

标签: node.js android-intent carousel dialogflow

“功能”的目的是使用轮播在dialogflow中创建“意图”。我使用了Google API函数“ createIntent”提供的代码。我的项目在node.js中编码。这是我的功能:

async function createIntentCustom(
) {
  const dialogflow = require('dialogflow');
  const intentsClient = new dialogflow.IntentsClient();
  const agentPath = intentsClient.projectAgentPath(ID_PROJECT);
  //Question
  const part = {
    text: "Question",
  };
  const trainingPhrase = {
    type: 'EXAMPLE',
    parts: [part],
  }
  const trainingPhrases = [trainingPhrase];  

  // carousel  
  const SelectItemInfo = {
    key : "cle",
  };

  const Image = {
    image_uri : "https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png",
    accessibility_text : "imageText",
  };

  const Item = {
    info :  SelectItemInfo,
    title : "titre",
    description : "description",
    image: Image,
  };

  const SelectItemInfo1 = {
    key : "cle1",
  };

  const Image1 = {
    image_uri : "https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png",
    accessibility_text : "imageText1",
  };

  const Item1 = {
    info :  SelectItemInfo1,
    title : "titre1",
    description : "description1",
    image: Image1,
  };

  const carousel = {
    items : [Item,Item1],
  };
  const Text = {
    text: ["reponse :"],
  };

  const message = {
    text: Text,
    carousel_select : carousel,
  };

  const intent = {
    displayName: "FirstIntent",
    trainingPhrases: trainingPhrases,
    messages: [message],
  };
  const createIntentRequest = {
    parent: agentPath,
    intent: intent,
  };
  // Create the intent
  const responses = await intentsClient.createIntent(createIntentRequest);
  console.log(`Intent ${responses[0].name} created`);
}

除了没有轮播,我碰巧创建了一个“意图”。但是执行过程中没有错误,您对问题有想法吗?

0 个答案:

没有答案