Create chatbot using bot framework sdk and LUIS — Part 5 | by Sushmita Mishra | Jan, 2022
This the last part of this blog series.
In this part we will complete the coding for view orders and cancel order conversation flow.
Changes in vieworder_dialog
In the waterfall steps add a step view_step. Define the async functionfor view_step. Fetch user_id from context object. We have already defined a function getOrders in orderApp module (see previous parts of the blog) to fetch the orders from csv, which are not in “Cancelled” status, for the given user id. Now we will call that function. Function getOrders returns the result in dataframe. Read each row from the dataframe and display the result to the user as bot response. End the dialog to go back to the main dialog.
Below is the final code for vieworder_dialog.py
Changes in cancelorder_dialog.py
In cancelorder_dialog we will add 2 steps in the waterfall steps- intro_step and act_step.
In the intro_step, add code to prompt the user to provide the order id which he wants to delete.
In the act_step read the order id provided by the user. We have already defined a function cancelOrder in the module orderApp in previous parts of this blog series. As per our use case we will accept an order for cancellation only if it is in “Order Received” status. If the order is already picked for processing then it cannot be cancelled. Hence, in cancelOrder function, for the provided user id and order id parameters, status of the order is verified. If status is “Order Received” then the order status is updated to cancelled.
This cancelOrder fucntion is called in act_step. Message returned from cancelOrder function is displayed as the bot response to the user.
Final code for cancelorder_dialog:
We have now completed coding for all the modules. Time to test the bot. Run the bot framework emulator to connect to the bot service and test it. Follow the steps mentioned in Part 1 to test the bot using emulator.
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?
Run the bot and select “Existing User” option. Provide the user id for which there are few orders available in the csv. Then select view orders option to verify if the order details displayed are correct or not.
After verifying view order flow, now select cancel order and provide an order id which exists in the csv.
Repeat the test for orders which are not in “Order Recieved” status.
Links for previous parts of this blog series.
Part 1, Part 2, Part 3, Part 4.
Source code for the bot is here.
Credit: Source link