A Natural Language Processing (NLP) chatbot module that allows investors to interact with ZMX (Zimbabwe Mercantile Exchange) and C-Trade platforms entirely through voice prompts or text messages over WhatsApp, powered by Twilio.
# R&R Mercantile Exchange WhatsApp NLP Chatbot
**R&R Mercantile Exchange — Trading Platform**
Author: Ronald Murape | May 2026 | Version 1.0.0
---
## Overview
A Natural Language Processing (NLP) chatbot module that allows investors to interact
with R&R Mercantile Exchange platforms entirely through voice
prompts or text messages over WhatsApp, powered by Twilio.
Users can say (or type) commands like *"Buy 100 Econet shares"* or *"Show my last 5
transactions"* and receive an instant plain-language reply — all within WhatsApp.
---
## Features
| # | Feature | Example Command |
|---|---------|----------------|
| 1 | **Buy Stocks** | "Buy 50 Econet shares" |
| 2 | **Sell Stocks** | "Sell my 30 Delta shares" |
| 3 | **View Portfolio** | "Show my portfolio" |
| 4 | **Transaction History** | "Show my last 10 transactions" |
| 5 | **Stock Price Check** | "What is the price of CBZ?" |
| 6 | **Account Balance** | "How much money do I have?" |
Voice notes are also supported — Whisper automatically transcribes them.
---
## Architecture
```
WhatsApp User
|
Twilio API → POST /webhook
|
[Voice note?] ──Yes──> Gemini inline audio (STT)
|
GPT-4o Function Calling (NLP: intent + entities)
|
Action Handler (route to DB operation)
|
SQLite / MSSQL Database
|
Response Generator
|
Twilio API → WhatsApp User
```
---
## Tech Stack
| Component | Technology |
|-----------|-----------|
| Web Framework | FastAPI 0.116.1 |
| NLP / Intent | Google Gemini 2.0 Flash |
| Speech-to-Text | Google Gemini inline audio |
| WhatsApp | Twilio WhatsApp Business API |
| Database (dev) | SQLite via aiosqlite |
| Database (prod) | Microsoft SQL Server via pyodbc |
| Language | Python 3.11 |
---
## Project Structure
```
r_and_r_exchange/
├── r_and_r_exchange.py # Main FastAPI service (all-in-one)
├── seed_data.sql # Database schema + seed data
├── README.md # This file
└── requirements.txt # Python dependencies
```
---
## Requirements
### Python Dependenci …