Search code examples
azurechatbotazure-cognitive-searchazure-bot-serviceazure-qna-maker

How to pull plain text from website using Azure Bot?


I'm working on an Azure Chatbot that will be connected to Facebook Messenger. The purpose of the bot is to look for the phrase of the day more or less. I currently have a url that returns the phrase of the day in plain text.

What I need the bot to do is for example:

User: "Hi, what is the phrase for today?"

The Bot will search the url and retrieve the plain text returned.

Bot: "The phrase for today is 'Don't Give Up!'"

I'm currently using QnA Maker for a knowledgebase, but it only works for static FAQs, not for pulling text from a website. Any help will be appreciated.

Thanks,

Axel


Solution

  • There's a couple of different ways you can go about this:

    Programmatically Update Your QnA Knowledgebase

    You'd need to create some kind of separate function (maybe using Azure Functions) outside of your bot that makes this API request every day.

    curl -v -X PATCH "https://westus.api.cognitive.microsoft.com/qnamaker/v4.0/knowledgebases/{kbId}"
    -H "Content-Type: application/json"
    -H "Ocp-Apim-Subscription-Key: {subscription key}"
    
    --data-ascii "{body}"
    

    Body:

    {
      "add": {
        "qnaList": [
          {
            "id": 0,
            "answer": "You can change the default message if you use the QnAMakerDialog. See this for details: https://docs.botframework.com/en-us/azure-bot-service/templates/qnamaker/#navtitle",
            "source": "Custom Editorial",
            "questions": [
              "How can I change the default message from QnA Maker?"
            ],
            "metadata": []
          },
    [...]
    

    Have the bot use an HTTP Request to get the Daily Phrase

    Alternatively:

    You would start by either intercepting messages that equal/contain:

    "Hi, what is the phrase for today?"
    

    Or, if you want the user's question to be a little more flexible, you could use LUIS to parse user input and return an intent.

    Once you code that into your bot, just have the bot make a regular HTTP request to your website to the phrase, then send that to the user.


    I can provide some code examples, if needed, but please provide a code sample of where in your bot you want this to occur. The URL for your phrase may also be helpful.