2ea837c2aeee13789c48b969ec284677253271a2
This commit introduces a significant refactoring to the whatsapp-router service to improve modularity and extend its capabilities for interacting with OpenWA (nucleo-whatsapp).
Key changes include:
1. **Message Processing Logic**:
* Created a new `messageProcessor.ts` module.
* Moved message mapping (`mapWhatsAppMessageToMsg`), message addition to conversations (`processIncomingMessageForConversation`), and audio transcription handling (`handleAudioMessageTranscription`) into this new module.
* Updated `store/conversation.ts` and `webhook.ts` to utilize `messageProcessor.ts`, streamlining their responsibilities.
2. **OpenWA Client (`nucleoClient.ts`)**:
* Introduced `nucleoClient.ts`, a dedicated module for encapsulating API calls to OpenWA.
* Implemented functions for various OpenWA commands:
* Sending text, image, and file messages.
* Fetching chat and contact information.
* Creating groups.
* Managing the blocklist (get, block, unblock).
* Listing all chats and fetching messages for a specific chat.
* Includes error handling and basic typing for API responses.
3. **New API Endpoints (`routes/nucleoActions.ts`)**:
* Created `nucleoActions.ts` to expose the functionalities of `nucleoClient.ts` via a new set of HTTP API endpoints.
* Endpoints cover all implemented client functions, with request validation and robust error handling.
* These routes are grouped under the `/nucleo` base path.
4. **Route Registration**:
* Registered the new `/nucleo` routes in the main `index.ts` file.
5. **Conversation Store and Routes Review**:
* Reviewed and confirmed that `store/conversation.ts` and `routes/conversations.ts` are correctly integrated with the new `messageProcessor.ts` and remain focused on their core responsibilities.
This refactoring enhances the structure of `whatsapp-router`, making it easier to maintain and extend. It also provides a comprehensive set of API endpoints for more granular control over OpenWA functionalities.
Conversation Layer
This module contains the services that handle messaging for WhatsApp and the web chat interface. All source code is now written in TypeScript. It is composed of four containers:
- openwa – provides access to WhatsApp through the open-wa project.
- whatsapp-router – receives webhook events from openwa and forwards messages to a conversation handler. Handlers can be configured per chat ID in
whatsapp-router/src/chatHandlers.ts. - chat-ui – simple web chat interface that also communicates with the LLM agent.
- conversation-layer-agent – lightweight agent that uses the Gemini SDK to answer questions about this repository.
All services can be launched together with docker-compose.
Usage
- Configure the URL of your LLM agent in
docker-compose.yml(LLM_AGENT_URL). - Set your Gemini API key in
.env(GEMINI_API_KEY) so the conversation-layer-agent can use the Gemini SDK. - Optionally edit
whatsapp-router/src/chatHandlers.tsto map specific chat IDs to different handler URLs or local handlers. By default the chat ID50498554225@c.usis mapped to a built‑in HelloWorld agent for testing andrepo-helper@c.ustalks to the conversation-layer-agent. - Run:
docker-compose up --build
The chat UI will be available on http://localhost:3000. Open-wa exposes its API on port 8080 and the WhatsApp router listens on port 3001.
Alternatively you can run the chat UI and router locally using Make:
make chat # start chat-ui
make router # start whatsapp-router
make agent # start conversation-layer-agent
Both targets read configuration from a .env file if it exists (see .env.example).
Description
Languages
TypeScript
82.7%
JavaScript
14.3%
Dockerfile
1.3%
HTML
1.2%
Makefile
0.5%