Google BrowserCarousel上的操作未正确呈现

时间:2018-11-07 18:46:50

标签: dialogflow actions-on-google

我将DialogFlow自定义实现与Google动作库结合使用来构建机器人。该机器人似乎运行得很好,但是当我在设备上对其进行测试时,我的BrowserCarousel响应无法正确呈现:

Shows up like this on the Actions On Google Simulator...

...and like this on Google Assistant on my test device.

这是我的履行代码:

const { 
    dialogFlow,
    SimpleResponse,
    Image,
    BrowseCarousel,
    BrowseCarouselItem,
    LinkOutSuggestion,
    Suggestions,
    BasicCard
} = require('actions-on-google');
require('isomorphic-fetch');

module.exports = (conv, params) => {
    // LOGIC: (1) GraphQL query fetches all pages with the tag 
    //        (2) Filter by exact tag matches first
    //        (3) Add partial matches.
    //        (4) If no tag matches, put a custom message.
    //        (5) Add all cards to a custom Payload.

    let search_term = params.search_term;
    return new Promise((resolve, reject) => {
        fetch('https://www.nayimanzil.com/graphql', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify({ query: '{ pages(last: 100) { nodes { title link tags(last: 10) { edges { node { name } } } featuredImage { sourceUrl } } } }' }),
            })
        .then(res => res.json())
        .then(res => {
            let filter_exact = new Array();
            let filter_extend = new Array();
            //console.log((res.data.pages.nodes.length));
            for(var i=0; i<res.data.pages.nodes.length; i++) {
                let extend_switch = false;
                for(var j=0; j<res.data.pages.nodes[i].tags.edges.length; j++) {
                    let tag_name = res.data.pages.nodes[i].tags.edges[j].node.name;
                    /*console.log(i + " - " + j);
                    console.log(tag_name + " - " + search_term + (tag_name == search_term));
                    console.log(tag_name + " - " + search_term + (tag_name.includes(search_term)));*/
                    if(tag_name == search_term)
                        filter_exact.push(res.data.pages.nodes[i]);
                    else if(tag_name.includes(search_term) && extend_switch==false){
                        filter_extend.push(res.data.pages.nodes[i]);
                        extend_switch = true;
                    }
                }
            }
            let carousel_items = new Array();
            let share_chips = new Array();
            let filter_joined = filter_exact.concat(filter_extend);

            console.log("Filter Joined Length: " + filter_joined.length);
            console.log(filter_joined);

            for(var k=0; k<filter_joined.length; k++){
                carousel_items.push(new BrowseCarouselItem({
                    title: filter_joined[k].title,
                    url: filter_joined[k].link,
                    image: new Image({
                        url: ((filter_joined[k].featuredImage==null) ? 'https://www.nayimanzil.com/wp-content/uploads/2018/06/nayimanzil-template.jpg' : filter_joined[k].featuredImage.sourceUrl),
                        // url: filter_joined[i].featuredImage.sourceUrl,
                        alt: "Search Result " + (k+1)
                    }),
                    footer: filter_joined[k].title,
                    description: filter_joined[k].title
                }));

                // FB share format - 
                // https://www.facebook.com/dialog/feed?app_id=288644845112477&link=https://www.nayimanzil.com&picture=https://www.nayimanzil.com/wp-content/uploads/2018/05/love009-landscape.jpg&name=NAME&description=DESCRIPTION&caption=CAPTION&redirect_uri=REDIRECT_URI

                share_chips.push(new LinkOutSuggestion({
                    name: "Link " + (k+1),
                    url: "https://www.facebook.com/dialog/feed?app_id=288644845112477&link=" + filter_joined[k].link + "&picture="
                         + ((filter_joined[k].featuredImage==null) ? 'https://www.nayimanzil.com/wp-content/uploads/2018/06/nayimanzil-template.jpg' : filter_joined[k].featuredImage.sourceUrl)
                         + "&redirect_uri=https://www.nayimanzil.com"
                }));

                if(k>1) break;
            }

            conv.ask("खुशखबरी! मुझे कुछ लेख मिल गए।");
            if(filter_joined.length<2){
                conv.ask(new BasicCard({
                    title: filter_joined[0].title,
                    url: filter_joined[0].link,
                    image: new Image({
                        url: ((filter_joined[0].featuredImage==null) ? 'https://www.nayimanzil.com/wp-content/uploads/2018/06/nayimanzil-template.jpg' : filter_joined[0].featuredImage.sourceUrl),
                        alt: "Search Result 1"
                    }),
                    footer: filter_joined[0].title,
                    description: filter_joined[0].title
                }));
            }
            else {
                conv.ask(new BrowseCarousel({
                    items: carousel_items
                }));
            }
            conv.ask("आप कौन सा लेख शेयर करना चाहते हैं?");

            console.log("share_chips.length = " + share_chips.length);

            for(var i=0; i<filter_joined.length; i++) {

                conv.ask(new LinkOutSuggestion({
                    name: "Link " + (i+1),
                    url: "https://www.facebook.com/dialog/feed?app_id=288644845112477&link=" + filter_joined[i].link + "&picture="
                         + ((filter_joined[i].featuredImage==null) ? 'https://www.nayimanzil.com/wp-content/uploads/2018/06/nayimanzil-template.jpg' : filter_joined[i].featuredImage.sourceUrl)
                         + "&redirect_uri=https://www.nayimanzil.com"
                }));

                if(i>1) break;
            }

            return resolve();
        });
    });
}

这是响应JSON:

{
  "conversationToken": "[\"search-articles_followup\"]",
  "expectUserResponse": true,
  "expectedInputs": [
    {
      "inputPrompt": {
        "richInitialPrompt": {
          "items": [
            {
              "simpleResponse": {
                "textToSpeech": "खुशखबरी! मुझे कुछ लेख मिल गए।"
              }
            },
            {
              "carouselBrowse": {
                "items": [
                  {
                    "title": "शादी से पहले सेक्स? क्या है सही सोच?",
                    "description": "शादी से पहले सेक्स? क्या है सही सोच?",
                    "footer": "शादी से पहले सेक्स? क्या है सही सोच?",
                    "image": {
                      "url": "https://www.nayimanzil.com/wp-content/uploads/2018/05/love007-square.jpg",
                      "accessibilityText": "Search Result 1"
                    },
                    "openUrlAction": {
                      "url": "https://www.nayimanzil.com/%e0%a4%b6%e0%a4%be%e0%a4%a6%e0%a5%80-%e0%a4%b8%e0%a5%87-%e0%a4%aa%e0%a4%b9%e0%a4%b2%e0%a5%87-%e0%a4%b8%e0%a5%87%e0%a4%95%e0%a5%8d%e0%a4%b8-%e0%a4%95%e0%a5%8d%e0%a4%af%e0%a4%be-%e0%a4%b9%e0%a5%88/"
                    }
                  },
                  {
                    "title": "क्या है शादी टूटने के कारण? आज की संस्कृति में शादी बचाने के 7 उपाय।",
                    "description": "क्या है शादी टूटने के कारण? आज की संस्कृति में शादी बचाने के 7 उपाय।",
                    "footer": "क्या है शादी टूटने के कारण? आज की संस्कृति में शादी बचाने के 7 उपाय।",
                    "image": {
                      "url": "https://www.nayimanzil.com/wp-content/uploads/2018/06/nayimanzil-template.jpg",
                      "accessibilityText": "Search Result 2"
                    },
                    "openUrlAction": {
                      "url": "https://www.nayimanzil.com/%e0%a4%b6%e0%a4%be%e0%a4%a6%e0%a5%80-%e0%a4%9f%e0%a5%82%e0%a4%9f%e0%a4%a8%e0%a5%87-%e0%a4%95%e0%a5%87-%e0%a4%95%e0%a4%be%e0%a4%b0%e0%a4%a3/"
                    }
                  },
                  {
                    "title": "सच्चा प्यार क्या है? आओ जाने इसके गुण और निशानियां।",
                    "description": "सच्चा प्यार क्या है? आओ जाने इसके गुण और निशानियां।",
                    "footer": "सच्चा प्यार क्या है? आओ जाने इसके गुण और निशानियां।",
                    "image": {
                      "url": "https://www.nayimanzil.com/wp-content/uploads/2018/05/love001-square.jpg",
                      "accessibilityText": "Search Result 3"
                    },
                    "openUrlAction": {
                      "url": "https://www.nayimanzil.com/%e0%a4%b8%e0%a4%9a%e0%a5%8d%e0%a4%9a%e0%a4%be-%e0%a4%aa%e0%a5%8d%e0%a4%af%e0%a4%be%e0%a4%b0-%e0%a4%95%e0%a5%8d%e0%a4%af%e0%a4%be-%e0%a4%b9%e0%a5%88/"
                    }
                  }
                ]
              }
            },
            {
              "simpleResponse": {
                "textToSpeech": "आप कौन सा लेख शेयर करना चाहते हैं?"
              }
            }
          ],
          "linkOutSuggestion": {
            "url": "https://www.facebook.com/dialog/feed?app_id=288644845112477&link=https://www.nayimanzil.com/%e0%a4%b8%e0%a4%9a%e0%a5%8d%e0%a4%9a%e0%a4%be-%e0%a4%aa%e0%a5%8d%e0%a4%af%e0%a4%be%e0%a4%b0-%e0%a4%95%e0%a5%8d%e0%a4%af%e0%a4%be-%e0%a4%b9%e0%a5%88/&picture=https://www.nayimanzil.com/wp-content/uploads/2018/05/love001-square.jpg&redirect_uri=https://www.nayimanzil.com",
            "destinationName": "Link 3"
          }
        }
      },
      "possibleIntents": [
        {
          "intent": "assistant.intent.action.TEXT"
        },
        {
          "intent": "d99a58da-d9fc-4762-ae0c-ad9d3ec30d7a"
        }
      ],
      "speechBiasingHints": [
        "$search_term"
      ]
    }
  ],
  "responseMetadata": {
    "status": {
      "message": "Success (200)"
    },
    "queryMatchInfo": {
      "queryMatched": true,
      "intent": "d99a58da-d9fc-4762-ae0c-ad9d3ec30d7a",
      "parameterNames": [
        "search_term"
      ]
    }
  }
}

我还创建了三个LinkOutSuggestion对象,但是只出现了一个。

有什么想法我在做什么错吗?

0 个答案:

没有答案