Create chatbot using bot framework sdk and LUIS — Part 3 | by Sushmita Mishra | Jan, 2022
In Part-1 and Part-2 we created a basic e-comm chatbot and started creating ‘create order’ conversation flow. In this part we will be generating order id and saving the order details in data storage. In next part we will be adding intelligence using LUIS. Complete source code is here.
Following tasks we will complete in this part:
- Generate order ID for the order details provided by the user
- Create a csv file to save the order details against the user id. (to keep this tutorial simple we r using csv for data storage, replace it with your database).
Create a csv file to store order details:
In the project folder add a new folder. Name it Data. Create a csv file order_dummy.csv with 5 columns — user_id, order_id, creation_date, order_status, order_description.
Create helper functions to manage order data:
Create a new python script orderApp.py in the project folder. We will be adding 3 functions — addOrders, viewOrders, cancelOrder. addOrders function is for adding the order details in csv, viewOrder function is for fetching order details of a given user id and cancel order is to update the order status to cancel for the given user id.
Copy below code in orderApp.py:
Update createorder_dialog to generate order id and save order details:
Open createorder_dialog.py, we will now update summary_step. Add code to generate a new order id. All order id’s will have prefix ‘ord’ followed by 4 digit random number.
1. How Conversational AI can Automate Customer Service
2. Automated vs Live Chats: What will the Future of Customer Service Look Like?
3. Chatbots As Medical Assistants In COVID-19 Pandemic
4. Chatbot Vs. Intelligent Virtual Assistant — What’s the difference & Why Care?
Create a pandas dataframe. Add a record with the order details along with user id and order id. also set the order status to “Order Received”. Pass this dataframe to addOrder function of orderApp module.
Add bot response, show the newly generated order id to the user in the bot response.
Below is the updated createorder_dialog.py:
With this we have completed coding required for Part-3. Test your bot using bot frmaework emulator. Follwo the steps givin in Part 1, to run the emulator.
Try similar flow with existing user. Check the data saved in csv file.
See you in next part of the blog.
Source code is here. Part-1 of the blog. Part -2.
Credit: Source link