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.
Trending Bot Articles:
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.
Don’t forget to give us your 👏 !
Create chatbot using bot framework sdk and LUIS — Part 3 was originally published in Chatbots Life on Medium, where people are continuing the conversation by highlighting and responding to this story.