0

Is there anyway of displaying the Auto-fill option in the bot emulator or any other channel using MS Bot framework. If not can you suggest any other alternative ?

vamsi
  • 73
  • 1
  • 8
  • Can you explain what you want to Autofill? if it is the input text for chat, please take a look at [this GitHub issue](https://github.com/Microsoft/BotFramework-WebChat/issues/476) – D4RKCIDE May 14 '18 at 16:28
  • Thanks for responding ! Yes, I need text to be autofilled either it will be in database or some static data. I have gone through the link, I have smae sort of issue. But I didn't find any solution over there. My issue is how we are going to show the data which we got from the API in the emulator. – vamsi May 14 '18 at 17:26
  • There is no native solution for this in bot framework, so its something you would have to roll your own feature for. The emulator uses webchat. So I would look into how to do this in webchat. I know I have seen some customers have done this before let me look to see if I can dig up any examples. A good thing for you to do is look for Autofill or autocomplete solution for webchat. – D4RKCIDE May 14 '18 at 18:35
  • I would post in that GitHub issue asking if anyone has a solution to share. I also found these other related issues https://github.com/Microsoft/BotFramework-WebChat/issues/648 and https://github.com/Microsoft/BotFramework-WebChat/issues/680 – D4RKCIDE May 14 '18 at 21:44

3 Answers3

2

Is there anyway of displaying the Auto-fill option in the bot emulator or any other channel using MS Bot framework

I embed web chat in my website and I use the following approach to implement Auto-fill (auto suggestion) for webchat input box, you can refer to it.

Html code:

<div id="bot"></div>
<div>
    <datalist id="mylists">
        <option value="Hello World">
        <option value="Azure">
        <option value="botframework">
        <option value="LUIS">
        <option value="QNA">
    </datalist>
</div>

JS code:

<script>
    BotChat.App({
        directLine: { secret: "{directline_secret}" },
        user: { id: 'You'},
        bot: { id: '{bot_id}' },
        resize: 'detect'
    }, document.getElementById("bot"));

    $(function () {
        //in this sample, I use a static datalist

        //you can also retrieve data from external storage, such as database, 
        //and dynamically generate datalist based on records 
        //then append dynamic datalist to web page

        //attach the datalist to webchat input box

        $("input.wc-shellinput").attr("list", "mylists");

    })
</script>

Test result:

enter image description here

Fei Han
  • 26,415
  • 1
  • 30
  • 41
  • 1
    If use webchat, another approach is attaching jQuery Autocomplete widgets to webchat input box, this SO thread:[Query Auto-Completion in c# bot in bot framework](https://stackoverflow.com/questions/49527724/query-auto-completion-in-c-sharp-bot-in-bot-framework/49530202#49530202) discussed about it, you can check it. – Fei Han May 15 '18 at 06:13
0

I also used HTML5 datalist to achieve auto-suggest. Here I am sharing my sample coding.

Html code:

<div id="bot"></div> //bot directline div
<datalist id="mylists"></datalist> //(suggestion list)
            <template id="resultstemplate">
                <option>Ray0</option>
                <option>Ray1</option>
                <option>Ray2</option>
                <option>Ray3</option>
                <!--etc ... similar options skipped -->
                <option>Ray2123</option>
                <option>Ray3123</option>
            </template>
        </div>

JS Code

$("input.wc-shellinput").attr("list", "mylists"); //append data list option with input box
var search = document.querySelector('.wc-shellinput'); // chat input box class(.wc-shellinput)
        var results = document.querySelector('#mylists'); // suggestion list 

        // below query for showing suggestion list in the chat & with limited count or otherwise large suggestion list will appear in the chat bot 
        var templateContent = document.querySelector('#resultstemplate').content;
        search.addEventListener('keyup', function handler(event) {
            while (results.children.length) results.removeChild(results.firstChild);
            var inputVal = new RegExp(search.value.trim(), 'i');
            var set = Array.prototype.reduce.call(templateContent.cloneNode(true).children, function searchFilter(frag, item, i) {
                if (inputVal.test(item.textContent) && frag.children.length < 6) frag.appendChild(item);
                return frag;
            }, document.createDocumentFragment());
            results.appendChild(set);
        });
Siva
  • 375
  • 3
  • 5
0

You can use autosuggestion if you're deploying it to the web, to use autosuggestion in your chatbot you have to:

  • Create a table in azure storage and keep your questions/queries that you want them to appear in autosuggestion.

  • Create a search service in azure, you have to add an index in the search service and link your table to it.

  • Then link created index with indexer and run the indexer.

  • Add the following code in your chatter.html to get autosuggestion in your chatbot

     <script>
     var searchServiceName = "search-service-name-here";
     var searchServiceApiKey = "xxxxxxxxxxxxxxxxxxxxxxxx";
     var indexName = "index-name";
     var suggestName = "suggestername";
     var apiVersion = "2019-05-06";
     var suggestUri =
       "https://" +
       searchServiceName +
       ".search.windows.net/indexes/" +
       indexName +
       "/docs/suggest?api-version=" +
       apiVersion;
     var autocompleteUri =
       "https://" +
       searchServiceName +
       ".search.windows.net/indexes/" +
       indexName +
       "/docs/autocomplete?api-version=" +
       apiVersion;
     var searchUri =
       "https://" +
       searchServiceName +
       ".search.windows.net/indexes/" +
       indexName +
       "/docs/search?api-version=" +
       apiVersion;
    
asingh
  • 56
  • 1
  • 5