Customer Support Agent
Customer support agent via WhatsApp with Jira integration, built with Python, FastAPI, LangGraph, and Redis.
Architecture
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ WhatsApp │────▶│ FastAPI │────▶│ AgentRunner │
│ (Webhook) │ │ /webhooks │ │ (ADK Style) │
└─────────────────┘ └─────────────────┘ └────────┬────────┘
│
▼
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Redis │◀───▶│ StateStore │◀───▶│ LangGraph │
│ (Sessions) │ │ │ │ StateGraph │
└─────────────────┘ └─────────────────┘ └────────┬────────┘
│
┌───────────────┼───────────────┐
▼ ▼ ▼
┌────────────┐ ┌────────────┐ ┌────────────┐
│ CustomerDB │ │ Jira │ │ Parsing │
│ (Tool) │ │ (Tool) │ │ (Utils) │
└────────────┘ └────────────┘ └────────────┘
Conversational Flow
[Customer] “Hi”
│
▼
[Agent] “Hi! To help you, please send me your CNPJ.”
│
▼
[Customer] “11.111.111/0001-91”
│
▼
[System] Validates CNPJ in the database
│
├─── Invalid CNPJ ──▶ “I couldn’t find an active account. Please confirm the number.”
│ │
│ └──▶ [Back to requesting CNPJ]
│
└─── Valid CNPJ ──▶ “Perfect! Tell me the product and describe your request.”
│
▼
[Customer] “Product: ERP, Request: error in the report”
│
▼
[System] Creates ticket in Jira
│
▼
[Agent] “✅ Request created: SUP-123”
Requirements
- Python 3.12+
- Docker and Docker Compose
- Poetry (dependency manager)
Installation
1. Clone the repository
cd customer-support-agent
- Install dependencies
# Install Poetry (if needed)
curl -sSL https://install.python-poetry.org | python3 -
Install dependencies
poetry install
- Configure environment variables
Create a .env file at the root of the project:
# Redis
REDIS_URL=redis://localhost:6379/0
# Jira
JIRA_BASE_URL=https://your-domain.atlassian.net
JIRA_EMAIL=your-email@example.com
JIRA_API_TOKEN=your-api-token
JIRA_PROJECT_KEY=SUP
JIRA_ISSUE_TYPE=Task
# WhatsApp (optional)
WHATSAPP_PROVIDER=cloudapi
- Start the services
Start Redis and the application
docker compose up -d
# Or start only Redis (for local development)
docker compose up -d redis
# Run the application locally
poetry run uvicorn app.main:app --reload --port 8000
Usage
Testing with cURL
# Health check
curl http://localhost:8000/health
# Simulate WhatsApp message - Greeting
curl -X POST http://localhost:8000/webhooks/whatsapp \
-H "Content-Type: application/json" \
-d '{"from":"+5511999999999","text":"hi"}'
# Send valid CNPJ
curl -X POST http://localhost:8000/webhooks/whatsapp \
-H "Content-Type: application/json" \
-d '{"from":"+5511999999999","text":"11111111000191"}'
# Send product and request
curl -X POST http://localhost:8000/webhooks/whatsapp \
-H "Content-Type: application/json" \
-d '{"from":"+5511999999999","text":"Product: ERP System, Request: error when generating report"}'
bash
Valid CNPJs for testing (mock)
CNPJ Name Status
11111111000191 Demo Client Ltd. Active
22222222000191 Test Company S.A. Active
33333333000191 Inactive Company Inactive
API Endpoints
Method Endpoint Description
GET /health Health check
POST /webhooks/whatsapp Receives WhatsApp messages
GET /sessions/{phone} Retrieves session state
DELETE /sessions/{phone} Removes session
Tests
# Run all tests
poetry run pytest
# Run with coverage
poetry run pytest --cov=app
# Run a specific test
poetry run pytest tests/test_graph_flow.py -v
Project Structure
customer-support-agent/
├── app/
│ ├── main.py # FastAPI webhook
│ ├── settings.py # Config via env vars
│ └── agent/
│ ├── runner.py # AgentRunner (ADK style)
│ ├── graph.py # LangGraph StateGraph
│ ├── state.py # SupportState TypedDict
│ ├── nodes.py # Node functions
│ ├── tools/
│ │ ├── customer_db.py # Customer validation (mock)
│ │ └── jira.py # Jira REST integration
│ └── utils/
│ ├── parsing.py # CNPJ, product, request parsing
│ └── store.py # Redis state store
├── tests/
│ └── test_graph_flow.py # Flow tests
├── docker-compose.yml
├── Dockerfile
├── pyproject.toml
└── README.md
Jira Configuration
Creating an API Token
- Go to https://id.atlassian.com/manage-profile/security/api-tokens
- Click “Create API token”
- Copy the token and add it to the .env
Creating the Project
- Create a project in Jira (e.g., “SUP” for Support)
- Configure the issue type (Task, Bug, etc.)
- Update the variables JIRA_PROJECT_KEY and JIRA_ISSUE_TYPE
WhatsApp Integration
WhatsApp Cloud API
Configure the webhook URL in Meta Business:
https://your-domain.com/webhooks/whatsapp
Twilio
Configure the webhook URL in the Twilio Console:
https://your-domain.com/webhooks/whatsapp
Top comments (0)