How I integrated an intelligent bot in PowerApps with QnA Maker and a custom service ?

Ashay Maheshwari
Chatbots Life
Published in
4 min readJun 17, 2019

--

Overview –

PowerApps is the new no-code platform of Microsoft and is the spearhead of their “Mobile First” Strategy. With a rich set of integration connectors, which are more than 220+ at present, it is appealing high among its competitors in the market. Read more about PowerApps on this link.

QnA Maker is a Conversational AI Service of Microsoft using which one can create a FAQ bot in minutes. Just bring in your questions with a variety in utterances and map a specific answer you want user to receive as a response. Read more about QnA Maker on this link.

Requirement –

I developed a simple Leave Management PowerApp using which one can apply leaves, check leave status, check leave history, leave balances, etc. The data associated with leaves is stored in SharePoint Lists. Thought of integrating a Virtual Assistant (Chat Bot) within PowerApps where user can chat in some similar way as given below –

Possible Question Answer Pair expected by User

The data resides in SharePoint List and must be fetched dynamically based on the user request and current status.

Challenges –

  1. PowerApps does not provide QnA Maker connector.
  2. QnA Maker is static pre-filled FAQ knowledge base. It cannot connect further with a database to get latest data.
  3. Microsoft Bot framework can get integrated with PowerApps using Direct Line Channel. But it is a lengthy and complex procedure.

Top 4 Bot Tutorials

1. AWS setup for Deep Learning

2. How to Integrate API.AI with Chatfuel

3. Build a working SMS chat-bot in 10 minutes

4. Chatbot Conference in San Francisco

Solution –

a. Prepare the back end Service — Write a custom service which can connect to SharePoint List database and fetch data for a specific user request. In my case, I wrote it in Python Flask using SharePlum Package. Here is a sample end-point –

GET /leaveapi/v1/balance?id=<user id stored in sharepoint>

b. Create a QnA Maker service and create a knowledge base as given below –

A sample entry in QnA Maker Knowledge Base (KB)

Do the same for all other end-points or queries user would make

c. Connect QnA Maker service with PowerApps using custom connector. Refer the article for details.

d. Create a Custom connector for Custom Python Flask Service. Refer the article to create a custom connector in PowerApps.

e. Design PowerApps Screen — Refer the article to create a chat screen in PowerApps

f. Connect to LeaveQnA (My custom connector for QnA Maker) using the given formula –

Set(
__response_from_qna,
First(LeaveQnA2.GenerateAnswer({question: userinput.Text}).answers).answer
);

The above code snippet connects to QnA Maker and get response mapped against the Knowledge Base (KB)

g. Set user ID using Office 365 connector and then connect to LeaveDataFetcher (my custom connector for Python Flask) to get response based on user ID –

Set(
__user_id,
Office365Users.MyProfileV2().mail
);
Set(
__casual_leaves_bal,
First(LeaveDataFetcher.LeaveBalance({id: __user_id}).casual_leave).casual_leave
);

The above code snippet gets user ID (email) and then calls LeaveDataService (Custom Python service) to get data against a user for his/her casual leave balance.

h. Based on the response, call the custom data connector as given below –

If(
"GetCasualLeaveBalance" in __response_from_qna,
Set(
__answer,
"Hello ! Your total causal leave balance is - " & Char(13) & Char(13) & __casual_leaves_bal
);
Collect(
chatDisplay,
{
question_asked: userinput.Text,
answer_generated: __answer
}
);

Don’t forget to give us your 👏 !

--

--

An enthusiastic Cloud Engineer now spending time on Microsoft Azure, Data Science Fundamentals, Machine Learning and Artificial Intelligence