Miniproject
Miniproject
The motivation behind this project stems from a need to enhance the dining experience by
reducing wait times and improving service efficiency, particularly during peak hours. Unlike
other systems typically found in restaurant management, this chatbot targets a broader
audience including casual diners and regular customers who seek a quick and interactive way
to order their meals.
This project is significant as it not only answers frequent and common queries related to
menu options and restaurant services but also provides these answers promptly at any time
desired by the user.
This alignment with advanced technological methodologies ensures that the restaurant
chatbot can effectively handle interactions, making it a valuable tool for modern restaurant
management and customer service.
TABLE OF CONTENT
1. INTRODUCTION 1
1.1. INTRODUCTION 2
1.3. OBJECTIVES 3
2. CHATBOTS 4
2.1. CHATBOT 5
2.2. TYPES 5
3. REQUIREMENTS 9
4. SYSTEM ARCHITECUTRE 12
4.1. ARCHITECTURE 13
5. IMPLEMENTATION 18
5.2. TRAINING 20
8. REFRENCES 33
9. APPENDIX 35
In this context, our project focuses on developing a restaurant chatbot that assists customers
by facilitating order placement, offering promotions and discounts, checking operational
hours, and tracking order statuses. By integrating principles of natural language processing
(NLP) and natural language understanding (NLU), this chatbot is capable of understanding
and interacting in a conversational manner, closely mimicking human-like interactions.
2
1.3. OBJECTIVES
a) Enable customers to place orders, track them, and make inquiries seamlessly through
the chatbot, saving time and simplifying the ordering process.
b) Automate the ordering process to reduce workload on restaurant staff and minimize
errors, thereby improving overall service quality.
c) Offer customers real-time updates on the status of their orders from preparation
through to delivery, ensuring transparency and improving service satisfaction.
3
2. CHATBOTS
4
2.1. CHATBOT
A chatbot is a computer program that can simulate a conversation or chat with a user in
natural language through messaging applications, website, or mobile applications and interact
with users according to their input and should be available 24/7. Chatbots are developed and
became so popular due to the increased use of smart devices and IoT technology.
2.2. TYPES
a. Base-line chatbot: It is a chatbot that is based on a database and uses if / then logic to
create a conversation flow and that takes a lot of time to ensure the understanding of
the question and the answer needed.[1]
b. AI chatbot: This type of chatbot is more complex than base-line but it is more
interactive and personalized and needs big data training to be impressive if the
problem is matched to their capabilities.[2]
c. Hybrid Model: A hybrid approach mixes the Base-line & AI chatbot to make it smart
and his behavior more expected by depending on database and Ai algorithm to work
together.[3]
a) User Input: The interaction begins when a user sends a message or query to the
chatbot. This input can be in the form of text typed into a chat interface or spoken
words captured by a speech recognition system.
b) Natural Language Processing (NLP): The chatbot's underlying system processes the
user input using natural language processing (NLP) algorithms. NLP enables the
chatbot to understand the meaning and context of the user's message, including
parsing text for keywords, identifying intent, and extracting relevant information.
c) Intent Recognition: Based on the user input, the chatbot determines the user's intent
or what action they want to perform. Intent recognition involves categorizing the
user's message into predefined categories or actions, such as placing an order, asking a
question, or requesting assistance.
5
d) Response Generation: Once the user's intent is identified, the chatbot generates a
response to address the user's query or fulfill their request. This response can be pre-
programmed text, dynamically generated content, or a combination of both, tailored to
provide relevant information or assistance based on the context of the conversation.
b) Using Platforms
It is similar to scratch chatbots but the only difference is that you do not have
to hire a specialized developer and use the chatbot builder platforms like
6
Google Dialogflow, IBM Watson, Botsify and Rasa, it’s not hard or
impossible to achieve it. but it’s not possible to create an NLP-enabled
chatbot that can deal with unstructured data.
7
Advantages of Google Dialogflow:
8
9
3. REQUIREMENTS
a) The chatbot system must provide a menu of available food items, including
descriptions, prices, and dietary information.
b) The chatbot should facilitate the ordering process by guiding users through
menu options and assisting with selection confirmation.
c) The system should support the addition and removal of items from the user's
order, allowing for real-time adjustments before finalizing the purchase.
d) The system should allow users to track the status of their orders, providing
updates on preparation, cooking, and delivery progress as applicable.
e) The system should generate order confirmation messages upon successful
completion of a transaction, including order details and receipt information
for user reference.
10
e) The system should employ filters or algorithms to detect and filter out
inappropriate language or content, preserving a family-friendly and respectful
environment for users.
f) The system should be designed with scalability in mind, accommodating
potential future expansions such as additional menu items, seasonal
promotions, or integration with third-party delivery services.
11
4. SYSTEM ARCHITECUTRE
12
4.1. Architecture
Figure 1
Figure 2
13
Dialogflow's built-in machine learning expands on your list with other, similar
phrases.
Action: You can define an action for each intent. When an intent is matched,
Dialogflow provides the action to your system, and you can use the action to
trigger certain actions defined in your system.
Parameters: When an intent is matched at runtime, Dialogflow provides the
extracted values from the end-user expression as parameters. Each parameter
has a type, called the entity type, which dictates exactly how the data is
extracted. Unlike raw end-user input, parameters are structured data that can
easily be used to perform some logic or generate responses.
Responses: You define text, speech, or visual responses to return to the end-
user. These may provide the end-user with answers, ask the end-user for more
information, or terminate the conversation.
The following diagram shows the basic flow for intent matching and responding to the
end-user:
Figure 3
c) Fulfillment is the last piece in the puzzle, it is the code that you write to interface with
backend services to respond to a dynamic request. Dialogflow has inbuilt integration
with Google Cloud Functions to interface with your backend. You can also provide any
other custom HTTPS endpoint to connect Dialogflow to your backend.
14
Figure 4
d) Entities
There is a type of every intent parameter, which is known as an Entity type. The task
performed by the end-user is to explain how data can be extracted from the end-user
expression. The Dialogflow offers you a various system entity which are predefined,
which is able to match various types of common data. For example, there are various
types of system entities for matching email addresses, colors, time, date, etc. For
matching custom data, we can also make our custom entities. For example: we can
define a fruit entity that matches the kinds of the fruits which are available to buy with
the agent of a grocery store.
e) Context
The context of Dialogflow is the same as a natural language context. When a person
tells you, "they are blue," you have to grasp the context to know which they are
referring to. In the same way, for Dialogflow, in order to handle an end-user
expression, the Dialogflow context must be provided to match an intent appropriately.
To handle the flow of the conversation, contexts are used. By setting input and output
contexts, that are recognized by the string names, we can configure the contexts for
the intents. If the intent is matched, then for that intent, any configured output context
15
will be active. When the contexts are in the active state then the Dialogflow try to
match intent configured to the input contexts which is corresponding to the contexts
which are presently active.
Figure 5
16
4.3. Flow Chart
Figure 6
17
5. IMPLEMENTATION
18
5.1. Creating Intents in Dialogflow:
a. Welcome Intent: This intent is triggered when a user initiates a conversation with the
chatbot. Its purpose is to greet the user and provide a friendly welcome message,
setting the tone for the interaction.
b. Fallback Intent: This intent is triggered when the chatbot is unable to understand the
user's input or when the user's message does not match any existing intents. Its
purpose is to handle unexpected or ambiguous user inputs gracefully and guide the
user back on track.
c. order.add - context: ongoing-order: This intent is triggered when the user wants to add
items to their order. Its purpose is to handle the process of adding food items to the
current order being created by the user.
d. order.remove - context: ongoing-order: This intent is triggered when the user wants to
remove items from their order. Its purpose is to manage the process of removing
specific food items from the current order.
f. track.order - context: ongoing-tracking: This intent is triggered when the user wants to
track the status of their order. Its purpose is to retrieve information about the current
status of the user's order from the database and provide it to the user.
g. check.operational.hours: This intent is triggered when the user inquires about the
operational hours of the restaurant or food establishment. Its purpose is to provide
information about the opening and closing hours of the restaurant on a given day.
19
h. Each intent serves a specific function within the chatbot's conversation flow, allowing
users to interact with the system to place orders, make inquiries, and track their orders
effectively.
Figure 7
5.2. Training
Training the intents involves providing sufficient examples of user queries or
utterances that correspond to each intent. This process allows the chatbot to learn and
understand the different ways users may express their intentions during interactions. Here's
how training is typically done for each intent:
a) Welcome Intent: Include variations of greetings and opening phrases that users may use
to start a conversation, such as "Hi", "Hello", "Good morning", or "Hey there".
20
b) Fallback Intent: Include a diverse set of examples representing common
misunderstandings, typos, or ambiguous inputs that users might provide. These
examples help the chatbot recognize when it needs to trigger the fallback response.
During training, it's essential to include a diverse range of examples that capture the
different ways users may express similar intents. This helps the chatbot generalize and
respond accurately to a variety of user inputs during real interactions. Additionally, ongoing
monitoring and refinement of the training data based on user feedback and observed
interactions can further improve the chatbot's performance over time.
21
Figure 8
a) Creation
Food Items: Create entities for various food items available for ordering, such as
"pizza", "burger", "sushi", "salad", "sandwich", "pasta", "smoothie", etc. Include
synonyms and variations to ensure robust recognition.
22
Order Actions: Create entities to represent actions related to ordering, such as
"add", "remove", "cancel", or "modify". These entities help the chatbot understand
the user's intent regarding their order management.
b) Entity Mapping:
Mapping entities to intents and slot types is essential for the chatbot to
comprehend user inputs accurately and fulfill their requests effectively. Here's how we
can map entities in our food ordering chatbot:
Intent Mapping: Associate each entity with the intents where they are relevant. For
example:
Map food item entities to the "order.add" intent for adding items to the
order.
Map quantities entities to the "order.add" intent to specify the quantity of
each food item.
Map special request entities to intents such as "order.add" or
"order.modify" to accommodate customizations.
23
ambiguous, prompt the user for clarification or provide default actions based on
context to ensure a seamless user experience.
By meticulously designing and mapping entities in our food ordering chatbot, we can
enhance its ability to understand user inputs, facilitate smoother interactions, and
ultimately deliver a satisfying ordering experience for users.
Food-item is our entity consisting of multiple food items which are available in the
restaurant
Figure 9
24
Here, In the order.add intent, the training phrases are highlighted with yellow and
orange colors indicating the entities are mapped accordingly.
The orange texts are food item, while the default entity sys-number is used for
‘quantity’.
Figure 10
a) Python Backend:
i. Python serves as the backend programming language for implementing
the business logic and handling user requests in the chatbot
application.
ii. In the context of our food ordering chatbot, the Python backend
receives user inputs and processes them to determine the appropriate
responses.
iii. The backend interacts with the DBMS to fetch or update data related to
food items, orders, user preferences, etc.
iv. Python frameworks such as FastAPI or Flask are commonly used to
build the backend infrastructure for handling HTTP requests and
responses.
b) DBMS Integration:
i. The DBMS (e.g., MySQL, PostgreSQL) stores and manages the data
required for the chatbot application, such as food item details, order
information, user profiles, etc.
ii. The Python backend interacts with the DBMS through database
connectors or ORMs (Object-Relational Mapping) to perform CRUD
(Create, Read, Update, Delete) operations on the database.
25
iii. Queries are constructed in Python to retrieve or manipulate data in the
DBMS based on user requests and application logic.
c) Fulfillment:
i. Fulfillment refers to the process of generating responses to user queries
or actions in the chatbot application.
ii. In our scenario, the fulfillment logic is implemented in Python backend
functions or methods.
iii. When a user interacts with the chatbot and triggers an intent (e.g.,
placing an order, querying operational hours), the corresponding
fulfillment function is executed to generate a response.
iv. The fulfillment function may involve querying the database to retrieve
relevant information (e.g., food item details, order status) and
formatting the response for the user.
d) Webhooks:
i. Webhooks are endpoints in the backend application that receive HTTP
POST requests from external services, such as chatbot platforms like
Dialogflow.
ii. In the context of our chatbot, Dialogflow sends user queries to the
webhook endpoint configured in the fulfillment section.
iii. The Python backend processes the webhook request, extracts relevant
information (e.g., user input, parameters), executes the appropriate
logic (e.g., intent handling, database operations), and sends back a
response to Dialogflow.
iv. Webhooks facilitate real-time communication between the chatbot
platform and the backend application, enabling dynamic interaction
and response generation based on user inputs.
26
27
6. TESTING & VALIDATION
Building a reliable and engaging chatbot requires thorough testing. Here are key criteria to
consider:
28
a. Intent Recognition Accuracy: Test how effectively the chatbot understands
user queries phrased differently. Use synonyms, variations, and natural
language to ensure robust intent detection.
b. Response Speed and Relevance: Assess the speed of the chatbot's responses
and ensure they are directly relevant to the user's questions. Ideally, responses
should be near-instantaneous and provide accurate information.
c. Multiple Questions Handling: Verify how the chatbot handles follow-up
questions within a conversation. The chatbot should maintain context and
guide the user towards a resolution without needing repeated information.
d. User Engagement: Observe if the chatbot uses conversational techniques to
keep users engaged. This might include prompts, questions, or informative
messages to encourage further interaction.
4. Domain-Specific Testing:
a. Industry-Tailored Questions: Develop a comprehensive list of questions
specific to your chatbot's domain or industry. Test the chatbot's ability to
answer these questions using relevant terminology.
5. Error Handling and Robustness:
a. Ambiguity Management: Evaluate the chatbot's ability to handle ambiguous
phrases or questions with multiple interpretations. Ideally, the chatbot should
clarify or offer different possibilities.
b. Unknown Information Handling: Test how the chatbot reacts to out-of-
vocabulary words, typos, or unexpected user inputs. It should provide
informative responses or offer to escalate the issue to a human agent.
6. Continuous Improvement:
Regularly test and refine your chatbot throughout development. Analyze real
user interactions to identify areas for improvement. Test edge cases that may
not be common but could still occur. By iteratively testing and refining, you
can ensure your chatbot delivers an exceptional user experience.
b) Classic Criteria
29
The classic criteria in the software test. By testing the software at and around critical
points, and what it accepts and what it does not accept. The software is also presented to a
group of people to be tested and examined based on interactions and data with humans.
a) Features to be tested
Tested features will be those features that the bot has been trained on and given all the
necessary information and data about these features.
Order.complete Response_Order.complete
Order.remove Response_Order.remove
Track.order Response_Track.order
Operational-hours Response_Operational-hours
30
b) Testing Environment
The testing of the bot was completed on the local host environment by hosting
the bot using NG Rock software, which creates a link that enables users outside the
local environment to access and interact with the bot.
31
7. CONCLUSION
This chatbot was designed to streamline the food ordering process for customers,
providing a user-friendly interface that simplifies menu browsing and order
customization. By integrating with a backend database and utilizing webhooks for real-
time updates, the bot efficiently manages incoming orders, updates kitchen workflows,
and tracks order status, ensuring that customers receive timely and accurate updates about
their food.
The system not only enhances customer interaction by providing details about the
restaurant's operational hours and responding to frequently asked questions but also
supports the restaurant staff by reducing the workload associated with phone orders and
manual order tracking. Through the integration of the Dialogflow platform and FastAPI,
the chatbot ensures seamless communication between the customers and the restaurant’s
management system, thus improving overall service delivery.
Additionally, the chatbot provides a platform for the restaurant to expand its digital
presence, facilitating easy scalability and updates to the menu and services as the business
evolves. It introduces potential efficiencies in handling peak traffic times and special
promotions, contributing positively to the restaurant's operational capabilities.
32
In conclusion, this project not only showcases the application of artificial intelligence in
enhancing customer service in the restaurant industry but also sets a foundation for future
enhancements such as integration with more sophisticated AI features for personalized
recommendations based on customer preferences and order history. This initiative not
only elevates the customer experience but also supports the restaurant's staff in
maintaining high service standards, ultimately contributing to increased customer
satisfaction and business growth.
Future Improvements: The project scope for the food ordering chatbot could be
expanded to include features such as voice command capabilities, integration with kitchen
management systems, and support for digital payments to streamline the entire dining
experience. Future enhancements might also involve personalization algorithms for dish
recommendations based on user preferences, multilingual support for diverse customer
bases, and the integration of loyalty programs to enhance user engagement and
satisfaction.
33
8. REFRENCES
1. “Dialogflow ES basics.”
https://cloud.google.com/dialogflow/es/docs/basics
2. “Dialogflow Architecture.”
https://medium.com/google-cloud/deconstructing-chatbots-getting-started-with-
dialogflow-4f91deb32135
3. “Natural Language Processing.”
https://www.geeksforgeeks.org/natural-language-processing-nlp-tutorial/
4. “CodeBasics NLP – Tutorial.”
https://youtube.com/playlist?
list=PLeo1K3hjS3uuvuAXhYjV2lMEShq2UYSwX&si=fgNqZuFM16vlYYu3
5. “Gemini.”
https://gemini.google.com/
6. Installation:
https://www.mysql.com/products/workbench/
https://dialogflow.cloud.google.com/
34
35
9. APPENDIX
36
b) Track Order
c) Operational hours
37
9.2.
Database Screenshots
a) Table - food_items
b) Table – orders
38
c) Table – orders_tracking
app = FastAPI()
inprogress_orders = {}
39
@app.post("/")
async def handle_request(request: Request):
# Retrieve the JSON data from the request
payload = await request.json()
intent_handler_dict = {
'order.add - context: ongoing-order': add_to_order,
'order.remove - context: ongoing-order': remove_from_order,
'order.complete - context: ongoing-order': complete_order,
'track.order - context: ongoing-tracking': track_order,
'check.operational.hours': check_operational_hours
}
return JSONResponse(content={
40
"fulfillmentText": message
})
if rcode == -1:
return -1
return next_order_id
41
order_total = db_helper.get_total_order_price(order_id)
del inprogress_orders[session_id]
return JSONResponse(content={
"fulfillmentText": fulfillment_text
})
if len(food_items) != len(quantities):
fulfillment_text = "Sorry I didn't understand. Can you please specify food items
and quantities clearly?"
else:
new_food_dict = dict(zip(food_items, quantities))
if session_id in inprogress_orders:
current_food_dict = inprogress_orders[session_id]
current_food_dict.update(new_food_dict)
inprogress_orders[session_id] = current_food_dict
else:
inprogress_orders[session_id] = new_food_dict
order_str =
generic_helper.get_str_from_food_dict(inprogress_orders[session_id])
fulfillment_text = f"So far you have: {order_str}. Do you need anything else?"
42
return JSONResponse(content={
"fulfillmentText": fulfillment_text
})
food_items = parameters["food-item"]
current_order = inprogress_orders[session_id]
removed_items = []
no_such_items = []
if len(removed_items) > 0:
fulfillment_text = f'Removed {",".join(removed_items)} from your order!'
if len(no_such_items) > 0:
fulfillment_text = f' Your current order does not have {",".join(no_such_items)}'
if len(current_order.keys()) == 0:
fulfillment_text += " Your order is empty!"
43
else:
order_str = generic_helper.get_str_from_food_dict(current_order)
fulfillment_text += f" Here is what is left in your order: {order_str}"
return JSONResponse(content={
"fulfillmentText": fulfillment_text
})
return JSONResponse(content={
"fulfillmentText": fulfillment_text
})
b) db_handler.py
import mysql.connector
global cnx
cnx = mysql.connector.connect(
host="localhost",
user="root",
password="root",
database="kichudb"
44
)
# Function to call the MySQL stored procedure and insert an order item
def insert_order_item(food_item, quantity, order_id):
try:
cursor = cnx.cursor()
return 1
return -1
except Exception as e:
print(f"An error occurred: {e}")
# Rollback changes if necessary
cnx.rollback()
return -1
45
# Function to insert a record into the order_tracking table
def insert_order_tracking(order_id, status):
cursor = cnx.cursor()
def get_total_order_price(order_id):
cursor = cnx.cursor()
return result
46
# Executing the SQL query to get the next available order_id
query = "SELECT MAX(order_id) FROM orders"
cursor.execute(query)
47
else:
return None
if __name__ == "__main__":
# print(get_total_order_price(56))
# insert_order_item('Samosa', 3, 99)
# insert_order_item('Pav Bhaji', 1, 99)
# insert_order_tracking(99, "in progress")
print(get_next_order_id())
c) session_handler.py
import re
return ""
48