Learn QnAMaker Azure Bot With Bot Framework SDK V4


QnA Maker service is used to create a knowledge base to add question-and-answer support to your Azure Bot. When you create your knowledge base, you seed it with questions and answers.




Previous Article : Learn azure bot service using Bot Framework SDK V4

In this tutorial, you will learn the following.
  1. Create a QnA Maker service and knowledge base.
  2. Train and Publish knowledge base information.
  3. Add QnA Maker Knowledge Bas information to your Bot
  4. Update your bot to query the knowledge base
  5. Test you bot locally
  6. Publish your bot to Azure Bot Service
  7. Test your bot using Web Chat Client
Below are the prerequisites,
  1. The bot created in the previous article. We will add a question-and-answer feature to the bot.
  2. QnA Maker portal is used to create, train, and publish the knowledge base to use with the bot.
Step 1 - Create a QnA Maker service and knowledge base
  • Sign into to the QnA Maker portal with your Azure credentials.
  • Click "Create a knowledge base".
  • Click “Create a QnA Services".



  • It will navigate to Azure Portal. Once there, fill all the below details to proceed
    • Name
    • Subscription
    • Pricing Tier
    • Resource Group
    • Search Location
    • App Name
    • Website Location



  • Once it is created, connect your QnA Services with your knowledge base.
  • Select Microsoft Azure Directory ID.
  • Select Azure Subscription Name.
  • Select available Azure QnA Service.
  • Name your knowledge base.



  •  Provide the URL from where the data needs to be extracted.



  • Click “Create your KB” to build a knowledge base.




Step 2 - Train and Publish knowledge base information
  • Once the knowledge base is created, click “Save and Train” followed by Publish button to publish the knowledge base.



  • You can click "Create Bot" using this screen or integrate the QnA Maker Services with an existing solution.


Step 3 - Add QnA Maker Knowledge information to your Bot
To continue with the below steps, kindly visit my previous article and download the source code.
Browse the solution and navigate to the app.settings file.
  1. {  
  2.   "MicrosoftAppId""",  
  3.   "MicrosoftAppPassword""",  
  4.   "ScmType""None",  
  5.     
  6.   "QnAKnowledgebaseId""knowledge-base-id",  
  7.   "QnAAuthKey""qna-maker-resource-key",  
  8.   "QnAEndpointHostName""your-hostname"   
  9. }  



Field
Value
QnAKnowledgebaseId
The knowledge base ID that the QnA Maker portal generated for you.
QnAAuthKey
The endpoint key that the QnA Maker portal generated for you.
QnAEndpointHostName
The host URL that the QnA Maker portal generated. Use the complete URL, starting with https:// and ending with /qnamaker. The full URL string will look like "look like "https://< >.azure.net/qnamaker".
Step 4 - Update your bot to query the knowledge base
  • Add NuGet Package to your project Microsoft.Bot.Builder.AI.QnA
  • Right-click dependencies and select Manage Nuget Package
  • Select Browse Option
  • Type NuGet package “Microsoft.Bot.Builder.AI.QnA”
  • Select the Nuget Package
  • Check the version and click install and accept the prompt.



Similarly, add Nuget Package Microsoft.Extensions.Configuration


Navigate to Startup.cs file, add these namespace references.
    1. using Microsoft.Bot.Builder.AI.QnA;  
    2. using Microsoft.Extensions.Configuration;  
    And, modify the ConfigureServices method create a QnAMakerEndpoint that connects to the knowledge base defined in the appsettings.json file in Startup.cs.
      1. services.AddSingleton(new QnAMakerEndpoint    
      2. {    
      3.    KnowledgeBaseId = Configuration.GetValue<string>($"QnAKnowledgebaseId"),    
      4.    EndpointKey = Configuration.GetValue<string>($"QnAAuthKey"),    
      5.    Host = Configuration.GetValue<string>($"QnAEndpointHostName")    
      6.  });    
      In your EchoBot.cs file, add these namespace references.
      1. using System.Linq;  
      2. using Microsoft.Bot.Builder.AI.QnA;  
       Add a EchoBotQnA connector and initialize it in the bot's constructor to EchoBot.cs.
        1. public QnAMaker EchoBotQnA { get; private set; }  
        2. public EchoBot(QnAMakerEndpoint endpoint)  
        3. {  
        4.    EchoBotQnA = new QnAMaker(endpoint);  
        5. }  
        Below the OnMembersAddedAsync( ) method, create the method AccessQnAMaker( ) by adding the following code.
          1. private async Task AccessQnAMaker(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)  
          2. {  
          3.    var results = await EchoBotQnA.GetAnswersAsync(turnContext);  
          4.    if (results.Any())  
          5.    {  
          6.       await turnContext.SendActivityAsync(MessageFactory.Text(" results.First().Answer), cancellationToken);  
          7.    }  
          8.    else  
          9.    {  
          10.       await turnContext.SendActivityAsync(MessageFactory.Text("Sorry, could not find an answer in the Q and A system."), cancellationToken);  
          11.    }  
          12. }  
          Now, within OnMessageActivityAsync( ), call your new method AccessQnAMaker( ) by adding the following code.
            1. protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)  
            2. {  
            3.    // First send the user input to your QnA Maker knowledge base  
            4.    await AccessQnAMaker(turnContext, cancellationToken);  
            5.    ...  
            6. }  
            Step 5 - Test your bot locally
            • Press F5, Browse the bot emulator and connect with localhost and port number
            • At this point, your bot should be able to answer some questions. Run the bot locally and open it in the Emulator.





            Step 6 - Publish your bot to Azure Bot Service
            • Right-click the solution.
            • Select the Publish option.
            • Select the publish profile  and click Publish to proceed. 




            Step 7 - Test your bot using Web Chat Client
            • Browse the WebApp Bot using Azure Portal
            • Select the Test in WebChat under Bot Management


            I hope you have enjoyed and learned something new in this article. Thanks for reading and stay tuned for the next article.

            Learn and Build Azure Bot With Bot Framework SDK V4

            Azure Bot Service provides an integrated environment that is purpose-built for bot development, enabling you to build, connect, test, deploy, and manage intelligent bots.


            In this tutorial, you will learn the following:
            1. Create Bot using VS2017 (Bot Framework SDK V4 template)
            2. Launch Emulator to run and test the Bot locally
            3. Create Azure Bot using Azure Bot Services
            4. Deploy and test the Bot at Web Chat
            Below are the prerequisites:
            Step 1 - Create Bot using VS2017 (Bot framework SDK V4 template)
            • Launch Visual Studio 2017, create a new project, and select the Bot Framework.
            • Select the Echo Bot (Bot Framework V4) template.
            • Select the location and give the bot name.
            • Click OK to create the project.


            • The project consists of all necessary code to get started with a quick bot. Expand the solution followed by the Bot folder. Click on the EchoBot.cs file.
            EchoBot.cs file consists of two main methods.
            • OnMessageActivityAsync -> Invoke with every new message
            • OnMembersAddedAsync -> invoke first time to add to any channel



            Step 2 - Launch Emulator to run and test the Bot locally
            • Fill out the fields for your bot. Use your bot's welcome page address (typically http://localhost:3978) and append routing info '/api/messages' to this address.
            • Click "Connect".

            As you connect with Bot Framework Emulator.
            • A welcome message will appear at the initial stage, i.e., “Hello and Welcome”.
            • Type the message “How r u “. You will get back the echo with the same message.

            So, a simple echo bot is created and tested locally using Bot Framework V4.
            Step 3 - Create an Azure Bot using Azure Bot Services
            Log into the Azure portal.
            • Click the "Create a new resource" link found on the upper left-hand corner of the Azure portal.
            • Select AI + Machine Learning.
            • Select Web App bot.

            Navigate to Azure Bot Service blade.
            • Set all the required information.
              • Name
              • Subscription
              • Resource Group
              • Location
              • Pricing
              • App Name
            • Select the Bot Template, i.e., Echo Bot (C#).
            • Click OK to select the template.
            • Click "Create" to the Azure Bot Service and deploy the bot to the cloud.


            Navigate to the App Service Setting to get the Publish profile.
            • Select "All App Service Settings".
            • Select "Overview".
            • Click on "Get Publish Profile" to download.

            Step 4 - Deploy and test the Bot at Web Chat
            • Navigate and right-click on Visual Studio Project solution.
            • Select "Build" and then publish it.
            • As you are doing the first time, the profile is not selected till yet. Click the Start 

            • Browse the downloaded profile and click the Publish button.
            • The solution will get deployed to the cloud.

            Now that your bot is created, test it in Web Chat.

            Test the bot

            In the Bot Management section, click Test in Web Chat. The Azure Bot Service will load the Web Chat control and connect to your bot.


            I hope you have enjoyed and learned something new in this article. Thanks for reading and stay tuned for the next article. 


            SharePoint Online - Set A Reminder

            This article will talk about the below-defined two artifacts and when to use what.
            1. Set a Reminder
            2. Alert Me 
             S.noSet a Reminder  Alert ME
             1 It is available for the Modern experience only It is available for both the Modern and Classic experiences.
             2 It works with both List and Library with a defined custom date column It works with List and Library without any defined column
            It works as a reminder for a particular user, even without an update or action trigger to item or document  It works as a trigger but it needs an item update or any action trigger to item or document.
             4Custom Date column is a prerequisite Event trigger; i.e. Item create, update, delete is a prerequisite
            Let's get started to explore more on this topic.
            Step 1: Create a Custom List or Library with Custom Date Column
            List or Library can have multiple date columns, then "Set a reminder" shows all the date columns. It will work with a single selection of date column.
            Let's follow the below steps to proceed.
            1. Hover on the Flow option.
            2. Select Flow option at List View Level.
            3. Select Set a reminder.
            4. Select custom date column  i.e. Column Name "Date".





            Step 2: Configure MS Flow for OOTB Reminder Template
            One you select date column, the flow template will appear. Set the "Remind Me" as the number of days, i.e., 2. It means the reminder will trigger two days before the defined timeframe in Date Column.



            Step 3: Trigger Flow and Check the Email
            How does it work now? Example: If a user has created a couple of items or document in List or Library where date column is configured as the 5th of the current month, as the user mentioned the reminder duration is 2 days, on the 3rd of the same month, they will get notified.
            Flow executes and triggers an email two days before, as per the defined date in the Date column.





            NoteThe reminder will be triggered for the user who has configured the reminder, irrespective of the document in the list.
            Now, let's talk about Alert also. Alert is an existing feature of SharePoint Online and OnPremises. Alert can be defined at Item as well as List or Library level.
            Step 1: Alert Me at List Level 
            If I navigate to List and click the "...", the fall back menu option will appear with the "ALERT ME" option.




            Step 2: Alert Me Trigger Options at List Level
            The Alert Me option triggers the email or message based on change type; i.e., a new item added, existing items modified, items deleted.





            Step 3: Alert Me at List Item Level
            If I navigate to List Item and click the "...", the fall back menu option will appear with "ALERT ME" option.







            Step 4: Alert Me Trigger Options at List Item Level
            The Alert Me option triggers the email or message based on change type; i.e., any changes to document or item created or modified by ME.






            I hope you have enjoyed and learned something about "when to use what" in this article. Thanks for reading and stay tuned for the next article.


            SharePoint Online Hub Site - Overview

            Here, I am going to address two queries:
            1. What is SharePoint Hub Site?
            2. Why use SharePoint Hub Site?

            What is a SharePoint Hub Site?


            SharePoint Hub Site is a connective tissue or conceptual view to connect and organize the site collections based on projects, department, regions, etc. 
            Before going deep, let's talk about Hub. The word "hub" illustrates that it is a central part of the wheel that rotates with an axle and helps the spoke to radiate.
            Hub Sites are a way to tie all the autonomous site collections together under one navigation umbrella.

            SharePoint Hub Site Characteristics

            • Discovers related content, such as news and other site activities
            • Applies common navigation, branding, and site structure across associated sites
            • Searches across all associated sites

            Why SharePoint Hub Site? 

            It moves away from a hierarchical structure to a flat structure.



            Hierarchical structure illustration

            This structure is widely accepted among the organizations due to the reasons mentioned below:
            • Permission Inheritance
            • Retention Policy inheritance
            • Shared Term Store
            • Shared Theme and Styling
            • Global Navigation and others





            Flat Structure Illustrate

            SharePoint Hub site can connect with multiple teams and communication sites (Site Collection). It provides a set of common features:
            • Brings together related teams and communication sites
            • Shared experience for the family of related sites
            • Roll up news, event and site Activity
            • Apply Common navigation and branding
            • Search across the hub and associated sites




            SharePoint Hub Sites on Office 365 are all about connecting your various workplaces so you can share, manage, and find the content and apps you need regardless of the device you’re using. The shared theme and logo also creates consistency and unifies all of the different teams and sites you may be active on.




            Furthermore, content discovery is amplified through the scoped search feature, as the association allows for the search results to include content from any of the associated sites. This means aggregated news and activities from the various associated sites can bring everything together.

            In the next article, you will learn more about -
            1. How to create and associate Hub Sites
            2. Hub Site features
            3. Enterprise Governance for Hub Sites
            I hope you have enjoyed and learned something new in this article. Thanks for reading and stay tuned for the next article.

            Speaking at Microsoft Azure Vidyapeeth

            Glad to share, I am speaking at Microsoft Azure Vidyapeeth

            Topic: How Azure Bot can interact with Azure SQL using AI Services

            Event Time:-  Friday 28-June-2019 at 3 to 4 PM IST.

            Registration Link:-https://info.microsoft.com/IN-AZUREPLAT-WBNR-FY19-06Jun-28-AzureBotinteractionwithSQLusingAIservices-SRDEM2949_LP01Registration-ForminBody.html