Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
571 views
in Technique[技术] by (71.8m points)

node.js - Issue with size limit (limit of 262144 bytes) from bot while displaying adaptive card with large choice list (in botframework)

My team is working on a chatbot with Microsoft bot framework, as a requirement we need to show a dynamic choice list according to what the users select. For this we are hitting an API to fetch the custom response. Please find below an example of the response.

    {
        "items": [
            {
                "val": {
                    "Field1": "Hello World"
                },
                "_links": {
                    "self": [
                        {
                            "href": "API_URL_FOR_THIS_OPTION"
                        }
                    ]
                }
            },
            {
                "val": {
                    "Field1": "Hi World"
                },
                "_links": {
                    "self": [
                        {
                            "href": "API_URL_FOR_THIS_OPTION"
                        }
                    ]
                }
            },
    ],
    "_links": {
        "self": [
            {
                "href": "MAIN_API_URL"
            }
        ]
    }
} 

Here, the number of options to be shown in the dynamic choice list will be equal to the length of the items array. The following code is used to convert this response into choices array compatible with adaptive cards

        var arr1=[]
        for(var i=0; i<resp.body.items.length;i++)
        {
          arr1.push(resp.body.items[i].values["Field1"])
        }
        var choice_arr_new=[];
        for(var j = 0; j<arr1.length; j++)
        {
            var dictionry={};
                dictionry['title'] = arr[j];
                dictionry['value'] = arr[j];
                choice_arr_new.push(dictionry);               
        }

It works well but I am encountering a size limit of about 250 Kb as the api response has items.length of more than 3000 for some cases. And hence, I receive the following Error: The request content length exceeded limit of 262144 bytes, while trying to pass the choice array to the Adaptive card

Questions:-

  1. Is there any way to increase the size limit to accommodate large choices array for adaptive card?
  2. Is there any alternative way to display the list within Bot Framework?
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you still want to use cards, you will have to split your choices into multiple sets and distribute them across separate cards.

If you're using a flat list of choices then you may have to display many cards at once, and it would be a good idea to use carousels for that. You can use multiple activities to display multiple carousels. If you're interested in having a library that can disable multiple activities for you when a card in one of them is clicked, you may want to voice your support for my upcoming cards library: https://github.com/BotBuilderCommunity/botbuilder-community-dotnet/issues/137

If you can categorize your choices, perhaps even just by the first letter of the title, then you may want to have the user select a category first and then select the actual choice from the smaller set within that category.

If you want to display each choice as a button, you could just use regular Bot Framework cards instead of Adaptive Cards. If you've ever tried a Web Chat sample then you may have noticed that MockBot displays its menu as a long list of cards with buttons. You could supposedly use suggested actions as well but it's generally not a good idea to display that many suggested actions at once.

Finally, you could just display all your choices as a numbered list so that the user could enter their choice as text.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...