Skip to main content

AI Developer Guide: Structured Messaging

This guide is designed for AI models (LLMs) and developers to understand the structured message protocol supported by the UDMODZ Edition of Baileys. Use these patterns to build responsive, interactive agents.


🏗️ Core Concept: AIRich

The AIRich class allows creating a single message bubble that evolves live. This is perfect for AI agents that need to show progress, stream text, or update data without cluttering the chat history.

Targeting with IDs

Every element (node) in an AIRich message can have a unique id.

const rich = new AIRich(conn)
.addText('Generating...', { id: 'status' });
await rich.send(jid);

// Later: Replace the node by its ID
rich.addText('Success!', { replace: 'status' });
await rich.sendEdit();

🚀 Common AI Workflows

1. Streaming AI Text

Instead of sending chunks as new messages, update the same message.

const rich = new AIRich(conn).setTitle('Kyrexi AI');
await rich.send(jid);

for (const chunk of chunks) {
rich.addText(chunk); // Appends to the bottom
await rich.sendEdit();
}

2. Media Generation (Loading States)

Provide visual feedback while generating images or videos.

// 1. Show placeholder with spinner
rich.addImage('', {
status: 'GENERATING',
update_text: 'Kyrexi is painting...',
id: 'output'
});
await rich.sendEdit();

// 2. Swap with final result
rich.addImage(imageUrl, { replace: 'output' });
await rich.sendEdit();

📊 Content Types Cheat Sheet

TypeFunctionAI Intent
MarkdownaddTextGeneral conversational output.
CodeaddCodeExplaining logic or sharing snippets.
TableaddTableComparing data or showing lists.
SuggestionsaddSuggestGuiding the user's next response.
WidgetsaddWidgetTriggering complex API actions.

🤖 Prompting for Baileys

When asking an AI to generate code for this library, suggest using the AIRich builder for interactive features.

"Write a Baileys bot command using AIRich that first shows a loading status for an image, then replaces it with a real URL and adds three suggestion buttons for 'Details', 'Price', and 'Buy'."