This project implements a WhatsApp-based AI assistant for dental clinics, enabling patients to book appointments via text or voice messages. It leverages LangGraph for conversational flows, FastAPI for the backend, and integrates with Google Calendar for scheduling.

- Multi-Modal Communication: Handles both text and voice messages.
- Voice Transcription: Transcribes audio messages using the Whisper model via Groq.
- Conversational AI: Processes user inputs through LangGraph-powered chatbot.
- Google Calendar Integration: Checks for available slots and creates appointments.
- FastAPI Backend: Provides API endpoints for WhatsApp webhook and other functionalities.
- Project Management with
uv
: Utilizesuv
for dependency management and project setup.
- Python 3.12 or higher
uv
installed globally
-
Clone the repository:
git clone https://github.com/yourusername/whatsapp-dental-bot.git cd whatsapp-dental-bot
-
Initialize the project with
uv
:uv init --app
-
Add dependencies:
uv add fastapi langgraph langchain langchain_groq google-api-python-client python-dotenv
-
Set up environment variables:
Create a
.env
file in the root directory and add the following:GROQ_API_KEY=your_groq_api_key OPENAI_API_KEY=oepnai_api_key FACEBOOK_AUTH_TOKEN=facebook_auth_token SENDER_PHONE=sender_phone
Ensure you have the necessary credentials for Google Calendar API access.
-
Run the application:
uv run main.py
The application will be available at http://127.0.0.1:5001
.
The conversational flow is managed by LangGraph with the following logic:
- Text Message: Directly processed by the
chatbot
node. - Audio Message: Routed to the
audio
node for transcription, then passed to thechatbot
node. - Chatbot Node: Interacts with the
tools
node to perform actions like checking and creating appointments in Google Calendar.
This modular design allows for easy scalability and maintenance.
The tools
node utilizes the Google Calendar API to:
- Check Availability: Search for free time slots.
- Create Appointments: Schedule new appointments based on user input.
-
Create a Google Cloud Project:
- Go to the Google Cloud Console.
- Click on Select a project and then New Project.
- Enter a project name and click Create.(support.google.com)
-
Enable Google Calendar API:
- In the APIs & Services Dashboard, click + ENABLE APIS AND SERVICES.
- Search for "Google Calendar API" and click on it.
- Click Enable to activate the API for your project.(endgrate.com)
-
Configure OAuth Consent Screen:
- Navigate to APIs & Services > OAuth consent screen.
- Choose External or Internal based on your needs and click Create.
- Fill out the required fields such as App name, User support email, and Developer contact information.
- Click Save and Continue through the scopes and test users sections.(endgrate.com, developers.google.com)
-
Create OAuth 2.0 Credentials:
- Go to APIs & Services > Credentials.
- Click + CREATE CREDENTIALS and select OAuth client ID.
- Choose Desktop app as the application type.
- Enter a name and click Create.
- Click Download JSON to obtain your
credentials.json
file.(developers.google.com, support.google.com, developers.google.com)
-
Place
credentials.json
in Your Project:- Move the downloaded
credentials.json
file to the root directory of your project. - Ensure this file is included in your
.gitignore
to prevent it from being committed to version control.
- Move the downloaded
-
Authenticate and Generate
token.json
:The first time you run your application, it will prompt you to authenticate with your Google account. Upon successful authentication, a
token.json
file will be created, storing your access and refresh tokens.Note: The
token.json
file is user-specific and should also be excluded from version control.
For more detailed instructions, refer to the Python Quickstart Guide for Google Calendar API.
Audio messages received from WhatsApp are processed as follows:
- Reception: Audio message is received via the FastAPI endpoint.
- Transcription: The
audio
node uses the Whisper model via Groq to transcribe the audio into text. - Processing: Transcribed text is then passed to the
chatbot
node for further handling.
This ensures seamless handling of both text and voice inputs.
To integrate WhatsApp with your application, follow these steps:
- Visit Meta for Developers and log in with your Facebook account.
- Accept the terms and set up your developer profile.
- Navigate to My Apps and click on Create App.
- Select Other as the app type and click Next.
- Choose Business as the app type and click Next.
- Enter an App Name, provide a Contact Email, and select your Business Account (if available). Click Create App.
- In your app's dashboard, scroll down to the Add Products to Your App section.
- Find WhatsApp and click Set Up.
- Follow the on-screen instructions to set up the WhatsApp Business API.
-
In the WhatsApp section of your app dashboard, navigate to Getting Started.
-
Select or create a WhatsApp Business Account (WABA).
-
Add and verify a phone number to be used for sending messages.
-
Generate a Permanent Access Token with the necessary permissions:
whatsapp_business_messaging
whatsapp_business_management
-
In your app dashboard, go to Webhooks and click Set Up Webhooks.
-
Select the WhatsApp Business Account.
-
Provide a Callback URL (your FastAPI endpoint) and a Verify Token.
-
Subscribe to the following fields:
messages
message_deliveries
message_reads
- Use the Test Number provided in the Getting Started section to send