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

China☆狼群 提交于 2021-02-02 09:34:13

问题


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?

回答1:


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.



来源:https://stackoverflow.com/questions/64755946/issue-with-size-limit-limit-of-262144-bytes-from-bot-while-displaying-adaptive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!