Building a Chatbot: Dialogflow, FastAPI, and GitHub in Action

Shashank Mankala
Python in Plain English
4 min readAug 21, 2023

--

STEP — 1: DIALOGFLOW API

Building a successful chatbot starts with designing effective conversational flows. I’ve chosen to leverage the power of Google’s Dialogflow API to achieve this. Dialogflow enables us to create natural and dynamic interactions between users and our chatbot.

  1. Creating Intents for Ordering and Tracking:

I’ve carefully crafted distinct intents for two main scenarios: ordering items and tracking orders. These intents define the different ways users can interact with our chatbot. For instance, I’ve set up an intent named “OrderFood” to handle food orders and another intent named “TrackOrder” to facilitate order tracking.

2. Designing Fulfillments:

Fulfillments are the heart of our backend logic. They allow us to respond to user requests with relevant information. By integrating webhooks and backend scripts, I’ve ensured that the chatbot can process and respond to user queries effectively. When a user interacts with the chatbot, the appropriate fulfilment is triggered to handle the request.

3. Training Phrases and Entities:

Dialogflow’s training phrases are examples of user inputs that help the chatbot understand different ways users might phrase their requests. For each intent, I’ve provided a variety of training phrases to ensure accurate intent recognition. Additionally, I’ve defined entities (such as food item names) to extract relevant information from user inputs.

STEP — 2: Establishing a Dynamic SQL Database

  1. Database Structure:

To effectively manage the chatbot’s data, I’ve designed an SQL database with three essential tables: “FoodItems,” “OrderTracking,” and “OrderStatus.” The “FoodItems” table stores details about the available food items and their corresponding prices. The “OrderTracking” table tracks user orders, capturing information such as order ID, order items quantity, and order price. The “OrderStatus” table stores the current status of each order.

STEP — 3: Developing the Backend Infrastructure

  1. Centralized Python Codebase:

Our backend logic is centralized within a Python codebase. This codebase handles incoming API calls, processes user intents, and triggers relevant fulfilment logic. It acts as the control centre of our chatbot’s functionalities, ensuring smooth communication between user inputs and the database.

2. Database Interaction:

I’ve created a separate Python file specifically for connecting to the SQL database. This file contains functions that allow us to interact with the database, such as inserting new orders, updating order statuses, and retrieving food item details. I created this file separately to enhance my code's modularity and maintainability.

STEP — 4: Creating a User-Friendly Frontend

  1. Displaying Food Items:

The front end of the application presents users with a display of food items and their corresponding prices. This provides users with a clear overview of available options before placing their orders.

2. Chatbot Integration:

I have integrated the front-end webpage with the chatbot. Users can interact with the chatbot to place orders, track existing orders, and inquire about menu items. This integration enhances user engagement and convenience.

STEP — 5: Version Control and Hosting

  1. GitHub Repository:

To maintain an organized development process, I hosted the project files on GitHub. This includes all code files, database schema, frontend assets, and related resources. GitHub’s version control system enables us to track changes, collaborate with team members, and manage the evolution of our project.

2. GitHub Pages Hosting:

I used GitHub Pages to host the application and make it accessible to users through web browsers. This allows users to interact with the chatbot and explore its features without the need for additional installations.

GitHub Hosted Link: GITHUB LINK

Tools and Technologies Used:

Throughout the development of our chatbot project, I’ve harnessed a range of powerful tools and technologies. Each of these tools played a crucial role in different aspects of the project, from conversational design to backend development and beyond. Here’s an overview of the tools and technologies that powered our chatbot journey:

  1. Google Dialogflow API: A robust platform for building conversational agents, Dialogflow enabled us to design natural interactions and manage the flow of conversations with users.
  2. Python: The programming language at the heart of our project, Python empowered us to build a dynamic and efficient backend to handle user requests and interactions.
  3. FastAPI: This modern web framework for building APIs in Python provided the infrastructure to create a responsive backend that efficiently processed user inputs and interactions.
  4. SQL Database: Our project relied on a structured SQL database to store and manage critical data, including food items, order tracking, and order statuses.
  5. GitHub Pages: By leveraging GitHub Pages, I was able to host the application and make it accessible to users through web browsers, streamlining the user experience.
  6. ChatGPT by OpenAI: As a cutting-edge language model, ChatGPT provided valuable assistance in assisting with codes, generating content, suggesting ideas, and structuring the blog post itself.

Note: Because I’m using the free version, it needs to restart the server frequently, so if you encounter any difficulties with the chatbot or if it’s not functioning correctly, please refer to this video demonstrated: LINK

By following these steps, you’ll be well-equipped to create a powerful and interactive chatbot that can handle food orders and order tracking seamlessly. Feel free to refer to the website to experience the chatbot. Stay tuned for more insights and updates as I continue refining my chatbot project.

Happy coding and best of luck with your own chatbot endeavour!

In Plain English

Thank you for being a part of our community! Before you go:

--

--

A data analyst with expertise in Python, SQL, Tableau, and Power BI. With a strong background in data manipulation, statistical analysis, and data visualization