PTENES
TRACK 6

💬 WhatsApp + Codex AgentKit

Connect GPT-4o to WhatsApp with agentkit: a bot with QR Code, Agent Builder integration, and smart replies for real customers.

6 modules ~50 minutes Node.js · WhatsApp Web · Advanced

Learning path map

Detailed content

🟢 What It Is

O WhatsApp AgentKit is a Node.js bot that connects the GPT-4o to WhatsApp via WhatsApp Web. You scan a QR Code, and any message sent to the connected number goes to the GPT agent and returns as an automatic reply.

💡 Why learn

WhatsApp is the dominant communication channel in Brazil. With this bot, you automate customer service, support, sales, and FAQs with a real AI agent — without paying for expensive official WhatsApp Business APIs.

🔑 Technical Stack

Frontend / Bot
  • • whatsapp-web.js — WA Web connection
  • • Node.js — runtime
  • • qrcode-terminal — QR code in the terminal
AI / Backend
  • • OpenAI API — GPT-4o
  • • Agent Builder — agent workflow
  • • .env — secure configuration

🟢 What It Is

Installing agentkit is simple: clone the repo, install the dependencies with npm, and configure the .env file. In less than 5 minutes, the bot is ready to connect to WhatsApp.

🔑 Step-by-Step Installation

# 1. Clone o repositório
git clone https://github.com/inematds/whatsapp-agentkit
cd whatsapp-agentkit

# 2. Instale as dependências
npm install

# 3. Copie o arquivo de configuração
cp .env.example .env

# 4. Edite o .env com suas credenciais
nano .env

File structure

whatsapp-agentkit/
├── index.js          ← bot principal
├── agent.js          ← chamada ao GPT/Agent Builder
├── .env              ← suas credenciais
├── .env.example      ← template
├── start_dev.bat     ← atalho Windows
└── package.json

🟢 What It Is

The file .env stores your credentials securely. Never commit it to git. The two main variables are the OpenAI API key and the Agent Builder workflow ID.

🔑 Required Variables

.env contents
# Chave da API da OpenAI
OPENAI_API_KEY=sk-proj-...

# ID do workflow do Agent Builder (opcional)
# Se definido, o bot usa o agente configurado
# em vez de GPT-4o direto
WORKFLOW_ID=wf_abc123...

# Nome do bot (aparece nas mensagens)
BOT_NAME=Assistente INEMA
✅ With WORKFLOW_ID

The bot uses the Agent Builder agent with configured guardrails, vector store, and widgets—more customized.

⚪ No WORKFLOW_ID

The bot uses GPT-4o directly via API—simpler, with no extra setup.

⚠️ Security: Add .env to .gitignore. Never share the file containing the API key. The .env.example is already in the project's gitignore.

🟢 What It Is

The connection works like WhatsApp Web: you run the bot, it displays a QR Code in the terminal, and you scan it with your phone in Settings → Linked Devices.

🔑 How to Connect

Ways to start the bot
# Linux / Mac (terminal)
npm run dev

# Windows (duplo clique ou terminal)
npm start
# ou double-click em:
start_dev.bat
1

QR Code appears in the terminal after ~5 seconds

2

On your phone: WhatsApp → ⋮ → Linked Devices → Link a Device

3

Scan the QR Code with your phone’s camera

4

Terminal shows "Client is ready!" — bot is online

5

Send a message to the connected number and see GPT’s response

🟢 What It Is

The most powerful integration: your agent configured in Agent Builder (with Guardrails, Vector Store, and tools) receives WhatsApp messages and responds like a specialized support agent.

🔑 Integration Flow

1
Create or open your agent in Agent Builder

Configure the prompt, guardrails, and tools for customer support

2
Copy the WORKFLOW_ID

In Agent Builder → Deploy → API → copy the workflow ID (format wf_xxx)

3
Add to .env

WORKFLOW_ID=wf_seu_id_aqui

4
Restart the bot and test

WhatsApp messages now go to your custom agent

🟢 Available Commands

CommandFunction
!helpLists the available commands
!statusShows whether the bot is active and connected
!pingTest response latency
!clearClears the conversation history (memory)

⚠️ Known limitations

Not supported
  • • Sending/receiving media (photos, videos)
  • • Group messages
  • • History persists after restart
  • • Multiple accounts simultaneously
✅ Works well
  • • Text messages (1-on-1)
  • • Context within the session
  • • Long responses
  • • Agent Builder integration

💡 Deploy to production

To run 24/7, deploy to a VPS server (AWS, DigitalOcean, Railway):

# Com PM2 (mantém rodando após reinicialização)
npm install -g pm2
pm2 start index.js --name whatsapp-bot
pm2 startup
pm2 save
← T5 Team ← Course Home