# wassengerhq/whatsapp-chatgpt-bot architecture

> Architecture diagram of the GitHub repository wassengerhq/whatsapp-chatgpt-bot, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/wassengerhq/whatsapp-chatgpt-bot
- Repository: https://github.com/wassengerhq/whatsapp-chatgpt-bot

## Overview

This repository runs a WhatsApp customer-support chatbot: a user message arrives through Wassenger, the server hands the webhook event to the bot, and the bot filters and prepares the message, uses conversation context and OpenAI to produce a response, then replies through Wassenger. Separate paths support human-agent handoff, configurable business tools, audio transcription and voice replies, and outbound sample or on-demand messages. The README documents multimodal and webhook/tunnel capabilities; sampled source shows their main integration points, but not every bot-processing detail.

Main entry points: [`actions.js`](https://github.com/wassengerhq/whatsapp-chatgpt-bot/blob/master/actions.js) (Messaging actions), [`bot.js`](https://github.com/wassengerhq/whatsapp-chatgpt-bot/blob/master/bot.js) (AI response and tools), [`server.js`](https://github.com/wassengerhq/whatsapp-chatgpt-bot/blob/master/server.js) (Webhook and HTTP routes), [`main.js`](https://github.com/wassengerhq/whatsapp-chatgpt-bot/blob/master/main.js) (Startup and setup)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Service runtime"]
  node_startup["Startup and setup<br/>[main.js]"]
  node_http["Webhook and HTTP routes<br/>[server.js]"]
  node_audiofiles[("Temporary audio files<br/>[server.js]")]
end

subgraph group_conversation["Conversation handling"]
  node_eligibility["Message filtering<br/>[bot.js]"]
  node_input["Input preparation<br/>[bot.js]"]
  node_assistant["AI response and tools<br/>[bot.js]"]
  node_reply["Reply and handoff<br/>[bot.js]"]
  node_business["Business tool functions<br/>[functions.js]"]
end

subgraph group_integrations["External integrations"]
  node_wassenger{{"Wassenger API"}}
  node_openai{{"OpenAI services"}}
  node_ngrok{{"Ngrok tunnel"}}
  node_actions["Messaging actions<br/>[actions.js]"]
end

subgraph group_stateconfig["State and configuration"]
  node_memory["Chat state and cache<br/>[store.js]"]
  node_config["Bot configuration<br/>[config.js]"]
end

node_user(("WhatsApp user"))

node_user -->|"sends messages"| node_wassenger
node_wassenger -->|"delivers webhook"| node_http
node_startup -->|"loads device and setup"| node_actions
node_startup -->|"starts server"| node_http
node_startup -.->|"creates tunnel"| node_ngrok
node_startup -->|"registers webhook"| node_actions
node_http -->|"serves outbound requests"| node_actions
node_http -->|"dispatches message"| node_eligibility
node_eligibility -->|"accepts eligible messages"| node_input
node_input -->|"transcribes audio"| node_actions
node_input -->|"provides prepared input"| node_assistant
node_assistant -->|"reads and updates context"| node_memory
node_assistant -->|"requests completions"| node_openai
node_assistant -->|"runs selected tools"| node_business
node_assistant -->|"passes generated response"| node_reply
node_reply -->|"generates voice audio"| node_openai
node_reply -->|"sends reply and updates chat"| node_actions
node_reply -->|"writes generated audio"| node_audiofiles
node_actions -->|"calls messaging API"| node_wassenger
node_actions -->|"transcribes audio"| node_openai
node_http -->|"serves and removes audio"| node_audiofiles
node_wassenger -->|"delivers replies"| node_user
node_startup -->|"reads settings"| node_config
node_http -->|"reads settings"| node_config
node_assistant -->|"reads behavior and limits"| node_config
node_actions -->|"reads credentials"| node_config
node_config -->|"provides tool definitions"| node_business
node_actions -->|"loads chat history"| node_memory

click node_startup "https://github.com/wassengerhq/whatsapp-chatgpt-bot/blob/master/main.js"
click node_http "https://github.com/wassengerhq/whatsapp-chatgpt-bot/blob/master/server.js"
click node_eligibility "https://github.com/wassengerhq/whatsapp-chatgpt-bot/blob/master/bot.js"
click node_input "https://github.com/wassengerhq/whatsapp-chatgpt-bot/blob/master/bot.js"
click node_assistant "https://github.com/wassengerhq/whatsapp-chatgpt-bot/blob/master/bot.js"
click node_reply "https://github.com/wassengerhq/whatsapp-chatgpt-bot/blob/master/bot.js"
click node_actions "https://github.com/wassengerhq/whatsapp-chatgpt-bot/blob/master/actions.js"
click node_business "https://github.com/wassengerhq/whatsapp-chatgpt-bot/blob/master/functions.js"
click node_memory "https://github.com/wassengerhq/whatsapp-chatgpt-bot/blob/master/store.js"
click node_config "https://github.com/wassengerhq/whatsapp-chatgpt-bot/blob/master/config.js"
click node_audiofiles "https://github.com/wassengerhq/whatsapp-chatgpt-bot/blob/master/server.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_startup,node_http,node_audiofiles,node_user toneBlue
class node_eligibility,node_input,node_assistant,node_reply,node_business toneAmber
class node_wassenger,node_openai,node_ngrok,node_actions toneMint
class node_memory,node_config toneRose
```

## Components

### Service runtime

- [Startup and setup](https://github.com/wassengerhq/whatsapp-chatgpt-bot/blob/master/main.js): `main.js`
- [Webhook and HTTP routes](https://github.com/wassengerhq/whatsapp-chatgpt-bot/blob/master/server.js): `server.js`
- [Temporary audio files](https://github.com/wassengerhq/whatsapp-chatgpt-bot/blob/master/server.js): `server.js`

### Conversation handling

- [Message filtering](https://github.com/wassengerhq/whatsapp-chatgpt-bot/blob/master/bot.js): `bot.js`
- [Input preparation](https://github.com/wassengerhq/whatsapp-chatgpt-bot/blob/master/bot.js): `bot.js`
- [AI response and tools](https://github.com/wassengerhq/whatsapp-chatgpt-bot/blob/master/bot.js): `bot.js`
- [Reply and handoff](https://github.com/wassengerhq/whatsapp-chatgpt-bot/blob/master/bot.js): `bot.js`
- [Business tool functions](https://github.com/wassengerhq/whatsapp-chatgpt-bot/blob/master/functions.js): `functions.js`

### External integrations

- **Wassenger API**
- **OpenAI services**
- **Ngrok tunnel**
- [Messaging actions](https://github.com/wassengerhq/whatsapp-chatgpt-bot/blob/master/actions.js): `actions.js`

### State and configuration

- [Chat state and cache](https://github.com/wassengerhq/whatsapp-chatgpt-bot/blob/master/store.js): `store.js`
- [Bot configuration](https://github.com/wassengerhq/whatsapp-chatgpt-bot/blob/master/config.js): `config.js`

### Other components

- **WhatsApp user**

## Connections

- WhatsApp user → Wassenger API: sends messages
- Wassenger API → Webhook and HTTP routes: delivers webhook
- Startup and setup → Messaging actions: loads device and setup
- Startup and setup → Webhook and HTTP routes: starts server
- Startup and setup → Ngrok tunnel: creates tunnel
- Startup and setup → Messaging actions: registers webhook
- Webhook and HTTP routes → Messaging actions: serves outbound requests
- Webhook and HTTP routes → Message filtering: dispatches message
- Message filtering → Input preparation: accepts eligible messages
- Input preparation → Messaging actions: transcribes audio
- Input preparation → AI response and tools: provides prepared input
- AI response and tools → Chat state and cache: reads and updates context
- AI response and tools → OpenAI services: requests completions
- AI response and tools → Business tool functions: runs selected tools
- AI response and tools → Reply and handoff: passes generated response
- Reply and handoff → OpenAI services: generates voice audio
- Reply and handoff → Messaging actions: sends reply and updates chat
- Reply and handoff → Temporary audio files: writes generated audio
- Messaging actions → Wassenger API: calls messaging API
- Messaging actions → OpenAI services: transcribes audio
- Webhook and HTTP routes → Temporary audio files: serves and removes audio
- Wassenger API → WhatsApp user: delivers replies
- Startup and setup → Bot configuration: reads settings
- Webhook and HTTP routes → Bot configuration: reads settings
- AI response and tools → Bot configuration: reads behavior and limits
- Messaging actions → Bot configuration: reads credentials
- Bot configuration → Business tool functions: provides tool definitions
- Messaging actions → Chat state and cache: loads chat history
