Skip to content

jayanth-yjr/forge-inspira-hackathon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MindMate WhatsApp Bot

A versatile chatbot system that can be used both locally via Flask/Streamlit and through WhatsApp integration.

Project Structure

.
├── cp_flask/               # Core Flask application for local bot
│   ├── agent.py           # Main agent logic and conversation handling
│   ├── app.py             # Flask application setup
│   ├── schemas.py         # Data schemas
│   └── __init__.py
├── data/                  # JSON data files
│   ├── doctors.json
│   ├── locations.json
│   ├── services.json
│   └── slots.json
├── wa_cp_flask/          # WhatsApp integration components
│   ├── bot_handler.py    # WhatsApp message handler
│   ├── send_whatsapp.py  # WhatsApp message sender
│   ├── history.py        # Conversation history management
│   └── __init__.py
├── requirements.txt      # Project dependencies
├── streamlit_chat.py    # Streamlit interface for local testing
└── webhook.py           # WhatsApp webhook handler

Usage Modes

The bot can be used in two different ways:

1. Local Flask/Streamlit Chatbot

This mode uses the following files:

  • cp_flask/ directory: Contains the core Flask application and agent logic
  • streamlit_chat.py: Provides a web interface for local testing
  • data/ directory: Contains all the necessary JSON data files

To run the local chatbot:

  1. Start the Flask server:
python cp_flask/app.py
  1. In a separate terminal, start the Streamlit interface:
streamlit run streamlit_chat.py
  1. Access the chat interface at http://localhost:8501

2. WhatsApp Integration

This mode uses the following files:

  • wa_cp_flask/ directory: Contains WhatsApp-specific handlers and utilities
  • webhook.py: Handles incoming WhatsApp messages
  • cp_flask/agent.py: Reuses the core agent logic for WhatsApp conversations

To run the WhatsApp bot:

  1. Start the webhook server:
python webhook.py
  1. Start ngrok to expose your local server:
ngrok http 3000
  1. Configure Meta Developer Account:
    • Go to Meta Developer Console
    • Set up a WhatsApp Business API
    • Configure webhook URL with your ngrok URL + /webhook
    • Set the verify token as "12345" (or update it in webhook.py)

Testing Webhook Verification

You can test if your webhook is properly configured using curl commands:

  1. Test the verification token (should return the challenge value):
curl -X GET "http://localhost:3000/webhook?hub.mode=subscribe&hub.verify_token=12345&hub.challenge=CHALLENGE_ACCEPTED"
  1. Test with invalid token (should return 403):
curl -X GET "http://localhost:3000/webhook?hub.mode=subscribe&hub.verify_token=wrong_token&hub.challenge=CHALLENGE_ACCEPTED"
  1. Test webhook with sample message (should return 200):
curl -X POST "http://localhost:3000/webhook" \
-H "Content-Type: application/json" \
-d '{
  "object": "whatsapp_business_account",
  "entry": [{
    "id": "WHATSAPP_BUSINESS_ACCOUNT_ID",
    "changes": [{
      "value": {
        "messaging_product": "whatsapp",
        "metadata": {
          "display_phone_number": "PHONE_NUMBER",
          "phone_number_id": "PHONE_NUMBER_ID"
        },
        "contacts": [{
          "profile": {
            "name": "NAME"
          },
          "wa_id": "WHATSAPP_ID"
        }],
        "messages": [{
          "from": "WHATSAPP_ID",
          "id": "MESSAGE_ID",
          "timestamp": "TIMESTAMP",
          "text": {
            "body": "Hello!"
          },
          "type": "text"
        }]
      },
      "field": "messages"
    }]
  }]
}'

Expected responses:

  • Verification test: Should return the challenge value
  • Invalid token test: Should return "Verification token mismatch"
  • Message test: Should return a 200 status code

Setup Instructions

Prerequisites

  • Python 3.8+
  • Meta Developer Account (for WhatsApp integration)
  • ngrok (for WhatsApp webhook)

Installation

  1. Clone the repository:
git clone <repository-url>
cd <repository-name>
  1. Install dependencies:
pip install -r requirements.txt
  1. Create a .env file in the root directory with the following variables:
GROQ_API_KEY="your_grok_api_key"

ACCESS_TOKEN="access token"
APP_ID="facebook developer app id"
APP_SECRET="facebook developer app secret"
RECIPIENT_WAID="+phone number" # Your WhatsApp number with country code (e.g., +31612345678)
VERSION="v23.0"
PHONE_NUMBER_ID="whatsapp phone number id"
VERIFY_TOKEN="12345"

FLASK_ENV="development"
FLASK_APP="app.py"

Features

  • Local chat interface using Streamlit
  • WhatsApp integration for mobile messaging
  • Intelligent conversation handling with OpenAI GPT
  • Appointment booking system
  • Doctor and service information lookup
  • Location-based hospital search

Usage

Local Chat

  1. Open the Streamlit interface
  2. Start chatting with the bot
  3. The bot can help with:
    • Booking appointments
    • Finding doctors
    • Locating hospitals
    • Answering healthcare queries

WhatsApp

  1. Send a message to your WhatsApp Business number
  2. The bot will respond automatically
  3. Follow the conversation flow for booking appointments or getting information

Security Notes

  • Never commit the .env file
  • Keep your API keys secure
  • Update the webhook verification token in production

Results

Alt text Alt text

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

License

[Add your license here]

About

forge

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages