Wine Not Build a Bot? 🍷
When it comes to simple solutions to sprucing up an FAQ page, chatbots are one of my favorite solutions. Whether you run a small business and are a one-person customer support team, you find your customer support team fielding the same questions about your hours and location, or even if you’re wanting to share knowledge, chatbots are a fantastic way to delegate frequently asked questions. I’ve written about it before, but I’ll say it again: creating a chatbot to answer FAQs using Azure tools is not only easy to build, but even easier to integrate with tools like Twilio.
I met Brendan Eliason at a Microsoft Reactor event a couple months ago. Brendan is a student at Holberton School, which is a software-engineering school that trains full-stack software engineers in 2 years or less. I’ve worked with many Holberton School students in the past, ranging from former principals like Elaine Yeung to former horticulturists like Robert Malmstein. One of my favorite parts of working with Holberton students (and bootcampers/non-traditional background folks in general) is bringing in their “previous life” expertise into their engineering projects. So, when Brendan mentioned that he spent his “previous life” in the wine industry, I was thrilled to collaborate on a fun chatbot involving wine & chatbots. It was the perfect pairing if you will. 🍷🥂
In this post, we’ll walk you through how me made a basic QnA bot to build a sommelier bot. Feel free to substitute our wine FAQ with your own set of questions and answers- no need to change anything else!
So, let’s get started! You can follow along here, or open up this Microsoft Learn Module and follow along yourself!
Open QnA Knowledge Base Portal
You’ll be navigating between two main tabs for this project. The Azure Portal, and the QnA Maker portal.
- Open a fresh tab, and sign into your Azure account. If you do not already have an Azure account, you can sign up here.
- Open the QnA Maker in a second tab.
What is a Knowledge Base?
Our bot needs knowledge–without a knowledge base, our bot will not know how to answer the specific questions we’d like it to have an expertise in. Our knowledge base will be hosted in a QnA service (created in Azure).
Create a QnA Knowledge Service
Select Create a QnA Service. Selecting this button takes you to the Azure Portal and signs you in with the credentials you used earlier. You create the QnA Maker service and the associated Azure app service that will host it in this portal.
What is a QnA Service?
Knowledge bases are hosted in a QnA service (created in Azure) and let us determine the region in which the knowledge base will sit (as well as its billing and performance).
Provide the following details to create your QnA Maker service:
1️⃣ Enter a globally unique name for your QnA Maker service, such as sombot-qna. Make a note of this name as you’ll be using it later.
2️⃣ Select your Azure subscription (you can use Free Trial to start).
3️⃣ Select the F0 pricing tier for the service (this is the free tier).
4️⃣ Create a resource group called LearnRG.
5️⃣ Select your closest location for the service (this should be the same region as the bot service).
6️⃣ Create a resource group called LearnRG.
7️⃣ Select F (3 Indexes), the free tier, for the search pricing tier.
8️⃣ Select the location you used earlier for your Azure Search location
9️⃣ Your App name will populate into App name automatically; make sure there is a green checkmark near your name. If not, try a new unique name!
🔟 Select website location (again, closest location to you)
🙅🏼♀️ You won’t be using Application Insights for this test, so disable App insights.
✅ Select Create.
Grab a quick beverage (some Pinot perhaps? 🍷) and your resource will soon be deployed and created for the service.
Connect QnA Maker + Knowledge Base
Our chatbot is pretty useless without knowledge–so now let’s give it some expert sommelier knowledge! In lieu of a multi-month style montage where we cut to myself and Brendan teaching a chatbot to code, all we have to do is upload the Q&A questions that Brendan put together with his expert wine knowledge.
Head back to the QnA Maker web portal. If you refresh the page, dropdown menus showing your account info will show up under Step 2. Select the Directory ID, subscription name, and QnA service (the ones we just selected/created in the Azure Portal).
Scroll down to Step 3 and provide a unique name for your Knowledge Base. I’m naming mine WineFacts.
Populate the Knowledge Base
1️⃣ If you’re following along and want a set of FAQ questions, you can can use this word doc. Or create your own quick sample question and answer doc. Supported formats include .tsv, .pdf, .doc, .docx, .xlsx, containing questions and answers in sequence.
2️⃣ Under Step 4 of the QnA web portal tab, select Add file, locate the document you wish to populate your knowledge base with, and add the document as a source to populate your KB (knowledge base).
3️⃣ Under Chit-chat, select the personality type you’d like your bot to have. Chit-chat is optional, but will populate your knowledge base with answers to commonly asked chatbot questions in the cadence/style that you choose. For example, for this wine bot we wanted a sophisticated sommelier-style attitude, so I opted for “Witty” (“Professional”, or “Friendly” would have worked just fine–your choice!).
By opting into a chit-chat style, you’ll immediately add responses for questions often promoted to chatbots such as “Do you have an age?”, “What’s your sign?” and some less common edge cases like “Are you swole?”, “Can you take a leisurely walk?” (…lol wut? 🤔 That’s oddly specific, but I digress 😂).
While chit-chat is optional, I would highly suggest adding it to your bot. Otherwise, you’ll find yourself either manually having to create responses to questions or your bot will simply reply with an “answer not found” response for all questions not entered in from your Knowledge Base.
4️⃣ Select Create your KB.
5️⃣ After a short time, your KB will be created and the Edit page will load (this may take a minute, so feel free to grab some charcuterie or crudités to pair with your wine 🥂). You may have to do a bit of clean-up here (remove/add line-breaks, check formatting, etc).
Once your knowledge base is formatted and looks good to go, click Save & Train in the top right corner.
Test Knowledge Base & Publish
Spend some time asking your bot some commonly asked questions by clicking Test in the top right corner. If your bot is responding as you’d expect, click Publish.
In a couple minutes, you should see a success message as well as URL information for your published knowledge base.
Before we get ahead of ourselves, let’s recap what we’ve done so far!:
- Created a QnA Knowledge service (this is the QnA Maker service within Azure)
- Created our QnA Knowledge Base (where our FAQs will be hosted)
- Connected our QnA Maker with our Knowledge Base (connecting the QnA Knowledge service to our QnA Knowledge Base)
- Populated our Knowledge Base (the FAQs for our bot)
- Tested Knowledge Base
- Published Knowledge Base
Integrate Bot with QnA
Now it’s time to integrate our QnA knowledge base with our bot! We’ll now create a chatbot with Azure to integrate with our QnA Maker knowledge base.
Once you’ve published your Knowledge Base, click the Create Bot button to be taken to the Azure Portal.
Now we’ll input the details to create our bot in Azure.
1️⃣ Give your bot an appropriate name
2️⃣ Use the Subscription service you have been using for this course
3️⃣ Select the proper Resource Group
4️⃣ Choose the location for the bot. (it’s best to use the same location as your other services!)
5️⃣ Select F0 pricing tier
6️⃣ Your app name should auto-populate, so no action needed here!
7️⃣ Choose C# as the SDK language
8️⃣ For the remaining fields, leave them as their default.
9️⃣ Click Create.
Give yourself a few minutes to sip your rosé, and your bot should be created shortly!
At last–we can chat with our bot! 🥳
Make your way over to the Azure Portal and open your new bot resource from the notification. Under Bot management, select Test in Web Chat and test the QnA.
Ask your bot a couple sample questions to make sure it’s interacting like the sommelier you’ve trained it to be 🥂. Feel free to edit questions in your Knowledge Base if you see any gaps in your bot’s wine education. Once you feel comfortable with your bot’s answers, navigate to the left hand navigation of your recently created Configuration section to view your Application Settings.
Let’s Connect Our Bot to Our QnA Service!
Here’s the part where we connect it all together 🤖 If you don’t already have it open, create a new tab to sign into your QnA Maker account and find the details for your QnA Maker service that was published. In the Postman sample, find the GUID (this represents the knowledge base ID) and copy it. We’ll paste that GUID and select the Hidden Value for QnAKnowledgebaseId in our Application Settings.
Do the same for the QnAEndpointHostName and QnAAuthKey in Application Settings. Save these settings, and find Test in Web Chat under the Bot Management section in the left side navigation. Our bot is now connected to our QnA Maker Service! 🎉 Test out the bot by asking it a question or two, and your bot should be up and running and at your service.
Congrats, you did it! You now have published a QnA Maker service that has been published on Azure. Your web chatbot has been integrated with QnA Maker and allows folks to chat in a interactive way with your bot. OK, that was a lot… let’s take a look at that diagram again, shall we?
Let’s Connect it to Twilio!
Now we’ll need to connect it to the proper Channel. I’ve decided to use Twilio for this, since I’m familiar with their API. If you’re unfamiliar, Twilio allows software developers to programmatically make and receive phone calls, send and receive text messages, and perform other communication functions using its web service APIs. Head over to Twilio, and set-up an account if you don’t have one already (🙋♀️ sign up here). You can use Twilio in all kinds of ways (fake boyfriend apps and ADHD reminders to name a few 🤳)!
Once you’ve created a Twilio account, create a new project. We’ll need a couple things to get our bot connected to Twilio:
- A Twilio phone number
- A Twilio Account Sid (acts as a username for our Twilio app)
- A Twilio Auth Token (acts as a password)
Give your project a unique name, and you’ll be taken to your dashboard. In the left-hand side navigation, click on the Phone Numbers section (labeled as “#” — can’t find it? it may be hiding behind the “…” icon that you need to expand!). Click on Buy a Number and hit the Search button. Once you find a number that suits your needs (the area code doesn’t matter, but it will need texting capabilities!), click Buy (note: phone numbers typically cost about $1-$2 monthly).
Let’s Create a TwiML App!
Now we need to create a TwiML app so we can give it a Request URL (in this case, https://sms.botframework.com/api/sms) for messaging with Twilio. In the Twilio console click through to Programmable Messaging > Tools > TwiML Apps. Click the red ➕ sign icon, or Create new TwiML App.
Fill out the TwiML App form with a friendly name, and under Messaging add https://sms.botframework.com/api/sms as the Messaging Request URL (HTTP POST).
Lastly, navigate back to the Azure Portal, select Channels (under Bot Management and add your Twilio credentials to your Azure Web App Bot like so:
To test that all is working smoothly with your bot, text a question to your Twilio phone number, and enjoy! You’ve successfully built a QnA Bot with Azure, and hooked it up to Twilio–SUCCESS! 🎉
If you’ve made it this far, congrats on making your first bot! As you can see, QnA Maker is an incredibly simple way to create a basic bot to manage commonly asked questions for customers, friends, family members, or wine newbies. Do you have an FAQ page on your site? Then you can build a bot for it!
As always, here to answer any questions, tackle any bugs, or help you build your own. Comment below, or reach out on Twitter if you get stuck! I’m here to help. 🤖💖 -Chloe
Originally published at https://dev.to on November 10, 2019.