bloby-bot 0.24.4 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/shared/config.ts +2 -2
- package/supervisor/channels/manager.ts +192 -3
- package/supervisor/channels/types.ts +3 -3
- package/workspace/skills/whatsapp/.claude-plugin/plugin.json +6 -0
- package/workspace/skills/whatsapp/SKILL.md +227 -0
- package/workspace/skills/whatsapp/skill.json +15 -0
package/package.json
CHANGED
package/shared/config.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { paths, DATA_DIR } from './paths.js';
|
|
|
3
3
|
|
|
4
4
|
export interface ChannelConfig {
|
|
5
5
|
enabled: boolean;
|
|
6
|
-
/** 'channel' = just talk to me (self-chat only), 'business' = admin/customer mode */
|
|
7
|
-
mode: 'channel' | 'business';
|
|
6
|
+
/** 'channel' = just talk to me (self-chat only), 'business' = admin/customer mode, 'assistant' = personal assistant in conversations */
|
|
7
|
+
mode: 'channel' | 'business' | 'assistant';
|
|
8
8
|
/** Phone numbers with admin access (owner, secretary, etc.) — business mode only */
|
|
9
9
|
admins?: string[];
|
|
10
10
|
/** Active skill for customer-facing mode (folder name in workspace/skills/) */
|
|
@@ -13,6 +13,9 @@
|
|
|
13
13
|
* All other messages are ignored — it's the user's personal WhatsApp.
|
|
14
14
|
* - business: Bloby has its own number. Numbers in the admins array get the main
|
|
15
15
|
* system prompt. Everyone else gets the customer support prompt.
|
|
16
|
+
* - assistant: Personal assistant in conversations. Self-chat = admin channel.
|
|
17
|
+
* Others' messages stored for context. Only responds when the owner
|
|
18
|
+
* triggers with @botname in someone else's chat.
|
|
16
19
|
*/
|
|
17
20
|
|
|
18
21
|
import fs from 'fs';
|
|
@@ -275,6 +278,21 @@ export class ChannelManager {
|
|
|
275
278
|
// ── Business mode: filter outgoing (except self-chat) ──
|
|
276
279
|
if (mode === 'business' && fromMe && !isSelfChat) return;
|
|
277
280
|
|
|
281
|
+
// ── Assistant mode ──
|
|
282
|
+
// Self-chat: falls through to debounce (processed as admin)
|
|
283
|
+
// Others' messages or my untriggered messages: store for context, don't invoke
|
|
284
|
+
// My messages with @botname trigger: falls through to debounce → agent
|
|
285
|
+
if (mode === 'assistant' && !(fromMe && isSelfChat)) {
|
|
286
|
+
// Store every message for context (both mine and theirs)
|
|
287
|
+
this.storeAssistantContext(channel, sender, senderName, text, fromMe);
|
|
288
|
+
|
|
289
|
+
// Only continue if it's me AND the message has the trigger
|
|
290
|
+
const botName = loadConfig().username || 'bloby';
|
|
291
|
+
const triggerPattern = new RegExp(`^@${botName}[:\\s]`, 'i');
|
|
292
|
+
if (!fromMe || !triggerPattern.test(text)) return;
|
|
293
|
+
// Falls through to debounce → flushDebounce → handleAssistantMessage
|
|
294
|
+
}
|
|
295
|
+
|
|
278
296
|
// Debounce: accumulate rapid messages from the same sender
|
|
279
297
|
const debounceKey = `${channel}:${sender}`;
|
|
280
298
|
const existing = this.debounceBuffers.get(debounceKey);
|
|
@@ -319,8 +337,8 @@ export class ChannelManager {
|
|
|
319
337
|
const mode = channelConfig.mode || 'channel';
|
|
320
338
|
|
|
321
339
|
// Route based on mode and role
|
|
322
|
-
if (mode === 'channel' || (mode === 'business' && fromMe && isSelfChat)) {
|
|
323
|
-
// Admin (self-chat in
|
|
340
|
+
if (mode === 'channel' || (mode === 'business' && fromMe && isSelfChat) || (mode === 'assistant' && fromMe && isSelfChat)) {
|
|
341
|
+
// Admin (self-chat in any mode)
|
|
324
342
|
const message: InboundMessage = {
|
|
325
343
|
channel,
|
|
326
344
|
sender: sender.replace(/@.*/, ''),
|
|
@@ -331,12 +349,30 @@ export class ChannelManager {
|
|
|
331
349
|
attachments: attachments.length > 0 ? attachments : undefined,
|
|
332
350
|
};
|
|
333
351
|
|
|
334
|
-
const modeLabel = mode === 'channel' ? 'Channel mode | self-chat'
|
|
352
|
+
const modeLabel = mode === 'channel' ? 'Channel mode | self-chat'
|
|
353
|
+
: mode === 'assistant' ? 'Assistant mode | self-chat | admin'
|
|
354
|
+
: 'Business mode | self-chat | admin';
|
|
335
355
|
log.info(`[channels] ${modeLabel} | "${combinedText.slice(0, 60)}"`);
|
|
336
356
|
await this.handleAdminMessage(message);
|
|
337
357
|
return;
|
|
338
358
|
}
|
|
339
359
|
|
|
360
|
+
// Assistant mode — triggered message in someone else's chat
|
|
361
|
+
if (mode === 'assistant') {
|
|
362
|
+
const message: InboundMessage = {
|
|
363
|
+
channel,
|
|
364
|
+
sender: sender.replace(/@.*/, ''),
|
|
365
|
+
senderName,
|
|
366
|
+
role: 'assistant',
|
|
367
|
+
text: combinedText,
|
|
368
|
+
rawSender: sender,
|
|
369
|
+
attachments: attachments.length > 0 ? attachments : undefined,
|
|
370
|
+
};
|
|
371
|
+
log.info(`[channels] Assistant mode | triggered in chat with ${message.sender} | "${combinedText.slice(0, 60)}"`);
|
|
372
|
+
await this.handleAssistantMessage(message, channelConfig);
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
|
|
340
376
|
// Business mode — incoming message
|
|
341
377
|
const role = this.resolveBusinessRole(channelConfig, sender);
|
|
342
378
|
|
|
@@ -637,6 +673,159 @@ export class ChannelManager {
|
|
|
637
673
|
);
|
|
638
674
|
}
|
|
639
675
|
|
|
676
|
+
/** Store a message in the assistant context buffer (for conversation history when triggered) */
|
|
677
|
+
private storeAssistantContext(
|
|
678
|
+
channel: ChannelType,
|
|
679
|
+
sender: string,
|
|
680
|
+
senderName: string | undefined,
|
|
681
|
+
text: string,
|
|
682
|
+
fromMe: boolean,
|
|
683
|
+
) {
|
|
684
|
+
const bufferKey = `${channel}:${sender}`;
|
|
685
|
+
let buffer = this.customerBuffers.get(bufferKey);
|
|
686
|
+
if (!buffer) {
|
|
687
|
+
buffer = [];
|
|
688
|
+
this.customerBuffers.set(bufferKey, buffer);
|
|
689
|
+
}
|
|
690
|
+
const label = fromMe ? 'me' : (senderName || sender.replace(/@.*/, ''));
|
|
691
|
+
buffer.push({ role: 'user', content: `[${label}]: ${text}` });
|
|
692
|
+
if (buffer.length > MAX_BUFFER_MESSAGES) {
|
|
693
|
+
buffer.splice(0, buffer.length - MAX_BUFFER_MESSAGES);
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
/** Handle a triggered assistant message — runs one-shot agent with conversation context */
|
|
698
|
+
private async handleAssistantMessage(msg: InboundMessage, channelConfig: ChannelConfig) {
|
|
699
|
+
const agentKey = `${msg.channel}:${msg.sender}`;
|
|
700
|
+
|
|
701
|
+
// Check concurrent limit
|
|
702
|
+
if (this.activeAgents.size >= MAX_CONCURRENT_AGENTS && !this.activeAgents.has(agentKey)) {
|
|
703
|
+
log.info(`[channels] Max concurrent agents reached — queuing assistant message for ${msg.sender}`);
|
|
704
|
+
this.messageQueue.push(msg);
|
|
705
|
+
return;
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
const { workerApi, getModel } = this.opts;
|
|
709
|
+
const model = getModel();
|
|
710
|
+
|
|
711
|
+
// Strip trigger prefix: "@bloby: do X" → "do X"
|
|
712
|
+
const config = loadConfig();
|
|
713
|
+
const botName = config.username || 'bloby';
|
|
714
|
+
const triggerRegex = new RegExp(`^@${botName}[:\\s]+`, 'i');
|
|
715
|
+
const cleanText = msg.text.replace(triggerRegex, '').trim();
|
|
716
|
+
|
|
717
|
+
// Load SCRIPT.md from configured skill
|
|
718
|
+
const scriptPrompt = this.loadActiveScript(channelConfig);
|
|
719
|
+
|
|
720
|
+
// Fetch agent name
|
|
721
|
+
let agentBotName = 'Bloby', humanName = 'Human';
|
|
722
|
+
try {
|
|
723
|
+
const status = await workerApi('/api/onboard/status');
|
|
724
|
+
agentBotName = status.agentName || 'Bloby';
|
|
725
|
+
humanName = status.userName || 'Human';
|
|
726
|
+
} catch {}
|
|
727
|
+
|
|
728
|
+
// Get conversation buffer (already populated by storeAssistantContext)
|
|
729
|
+
let buffer = this.customerBuffers.get(agentKey);
|
|
730
|
+
if (!buffer) {
|
|
731
|
+
buffer = [];
|
|
732
|
+
this.customerBuffers.set(agentKey, buffer);
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
// All buffered messages are context for the agent
|
|
736
|
+
const recentMessages: RecentMessage[] = buffer.map((m) => ({
|
|
737
|
+
role: m.role,
|
|
738
|
+
content: m.content,
|
|
739
|
+
}));
|
|
740
|
+
|
|
741
|
+
// Load per-contact memory from the skill's customer_data directory
|
|
742
|
+
let contactMemory = '';
|
|
743
|
+
try {
|
|
744
|
+
const customerDataDir = this.getSkillCustomerDataDir(channelConfig);
|
|
745
|
+
if (customerDataDir) {
|
|
746
|
+
const memoryPath = path.join(WORKSPACE_DIR, customerDataDir, `${msg.sender}.md`);
|
|
747
|
+
if (fs.existsSync(memoryPath)) {
|
|
748
|
+
contactMemory = fs.readFileSync(memoryPath, 'utf-8').trim();
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
} catch {}
|
|
752
|
+
|
|
753
|
+
// Build enriched script with contact memory
|
|
754
|
+
let enrichedScript = scriptPrompt;
|
|
755
|
+
if (contactMemory && enrichedScript) {
|
|
756
|
+
enrichedScript += `\n\n---\n# Contact History (${msg.sender})\n\n${contactMemory}`;
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
const channelContext = `[WhatsApp | ${msg.sender} | assistant${msg.senderName ? ` | ${msg.senderName}` : ''}]\n`;
|
|
760
|
+
|
|
761
|
+
// Convert inbound attachments to agent format
|
|
762
|
+
const agentAttachments: AgentAttachment[] | undefined = msg.attachments?.map((att) => ({
|
|
763
|
+
type: 'image' as const,
|
|
764
|
+
name: `whatsapp_image.${att.mediaType.split('/')[1] || 'jpg'}`,
|
|
765
|
+
mediaType: att.mediaType,
|
|
766
|
+
data: att.data,
|
|
767
|
+
}));
|
|
768
|
+
|
|
769
|
+
// Stable convId per contact
|
|
770
|
+
const convId = `channel-${agentKey}`;
|
|
771
|
+
|
|
772
|
+
this.activeAgents.set(agentKey, { sender: msg.sender, channel: msg.channel });
|
|
773
|
+
|
|
774
|
+
// Show "typing..." while the agent processes
|
|
775
|
+
this.startTyping(msg.channel, msg.rawSender);
|
|
776
|
+
|
|
777
|
+
// Track text chunks for WhatsApp
|
|
778
|
+
let waChunkBuf = '';
|
|
779
|
+
|
|
780
|
+
startBlobyAgentQuery(
|
|
781
|
+
convId,
|
|
782
|
+
channelContext + cleanText,
|
|
783
|
+
model,
|
|
784
|
+
(type, eventData) => {
|
|
785
|
+
// Accumulate text tokens
|
|
786
|
+
if (type === 'bot:token' && eventData.token) {
|
|
787
|
+
waChunkBuf += eventData.token;
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
// Agent paused to use a tool — send accumulated text as intermediate message
|
|
791
|
+
if (type === 'bot:tool' && waChunkBuf.trim()) {
|
|
792
|
+
this.sendMessage(msg.channel, msg.rawSender, waChunkBuf.trim()).catch((err) => {
|
|
793
|
+
log.warn(`[channels] Failed to send assistant chunk: ${err.message}`);
|
|
794
|
+
});
|
|
795
|
+
waChunkBuf = '';
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
if (type === 'bot:response' && eventData.content) {
|
|
799
|
+
// Add response to buffer for continuity across triggers
|
|
800
|
+
buffer!.push({ role: 'assistant', content: eventData.content });
|
|
801
|
+
if (buffer!.length > MAX_BUFFER_MESSAGES) {
|
|
802
|
+
buffer!.splice(0, buffer!.length - MAX_BUFFER_MESSAGES);
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
// Send remaining text
|
|
806
|
+
const remaining = waChunkBuf.trim();
|
|
807
|
+
if (remaining) {
|
|
808
|
+
this.sendMessage(msg.channel, msg.rawSender, remaining).catch((err) => {
|
|
809
|
+
log.warn(`[channels] Failed to send assistant reply: ${err.message}`);
|
|
810
|
+
});
|
|
811
|
+
waChunkBuf = '';
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
if (type === 'bot:done') {
|
|
816
|
+
this.activeAgents.delete(agentKey);
|
|
817
|
+
if (eventData.usedFileTools) this.opts.restartBackend();
|
|
818
|
+
this.processQueue();
|
|
819
|
+
}
|
|
820
|
+
},
|
|
821
|
+
agentAttachments,
|
|
822
|
+
undefined,
|
|
823
|
+
{ botName: agentBotName, humanName },
|
|
824
|
+
recentMessages,
|
|
825
|
+
enrichedScript,
|
|
826
|
+
);
|
|
827
|
+
}
|
|
828
|
+
|
|
640
829
|
/** Transcribe audio via the existing whisper endpoint */
|
|
641
830
|
private async transcribeAudio(audioBase64: string): Promise<string | null> {
|
|
642
831
|
try {
|
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
export type ChannelType = 'whatsapp' | 'telegram';
|
|
6
|
-
export type SenderRole = 'admin' | 'customer';
|
|
6
|
+
export type SenderRole = 'admin' | 'customer' | 'assistant';
|
|
7
7
|
|
|
8
8
|
export interface ChannelConfig {
|
|
9
9
|
enabled: boolean;
|
|
10
|
-
/** 'channel' = just talk to me (self-chat only), 'business' = admin/customer mode */
|
|
11
|
-
mode: 'channel' | 'business';
|
|
10
|
+
/** 'channel' = just talk to me (self-chat only), 'business' = admin/customer mode, 'assistant' = personal assistant in conversations */
|
|
11
|
+
mode: 'channel' | 'business' | 'assistant';
|
|
12
12
|
/** Phone numbers with admin access (owner, secretary, etc.) — business mode only */
|
|
13
13
|
admins?: string[];
|
|
14
14
|
/** Active skill for customer-facing mode (folder name in workspace/skills/) */
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
# WhatsApp
|
|
2
|
+
|
|
3
|
+
## What This Is
|
|
4
|
+
|
|
5
|
+
Gives your agent a WhatsApp number. Connect via QR code, send and receive messages, handle voice notes, and switch between personal (channel) and business modes. Built on Baileys — no Meta Business API needed.
|
|
6
|
+
|
|
7
|
+
## Dependencies
|
|
8
|
+
|
|
9
|
+
None.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## How Responses Work
|
|
14
|
+
|
|
15
|
+
**Your text response IS the WhatsApp reply.** When you receive a message tagged with `[WhatsApp | ...]`, the supervisor takes whatever you respond with and sends it directly to WhatsApp. You do NOT need to use curl or `/api/channels/send` to reply — just respond normally.
|
|
16
|
+
|
|
17
|
+
**Do NOT use `/api/channels/send` to reply to incoming WhatsApp messages.** That endpoint is ONLY for proactive messages (during pulse, cron, or when you want to initiate a conversation). If you use it to reply, the person will get duplicate messages.
|
|
18
|
+
|
|
19
|
+
**Adjust your style for WhatsApp:** Keep messages shorter and more conversational than chat. No markdown headers, no code blocks unless asked. Think texting, not email.
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## How Messages Arrive
|
|
24
|
+
|
|
25
|
+
When a message arrives via WhatsApp, the supervisor wraps it with context:
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
[WhatsApp | 5511999888777 | customer | Alice]
|
|
29
|
+
Hi, I'd like to schedule an appointment.
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
The format is: `[WhatsApp | phone | role | name (optional)]`
|
|
33
|
+
|
|
34
|
+
- **role=admin**: This is your human or an authorized admin. Use your normal personality, full capabilities, main system prompt.
|
|
35
|
+
- **role=customer**: This is someone else messaging. Follow the instructions from the active skill's SCRIPT.md (loaded as your system prompt for that conversation).
|
|
36
|
+
- **role=assistant**: Your human triggered you with `@botname:` inside a conversation with this person. You have the full conversation history as context. Execute the task and respond concisely — your reply goes directly into that chat. The SCRIPT.md from the active skill is loaded as your system prompt.
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Channel Config
|
|
41
|
+
|
|
42
|
+
Your channel configuration is injected into your context (if any channels are configured). It comes from `~/.bloby/config.json` — a file OUTSIDE your workspace that the supervisor manages.
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## Modes
|
|
47
|
+
|
|
48
|
+
**Channel Mode** (default): Your human's own WhatsApp number. Only self-chat (messages your human sends to themselves) triggers you — messages from other people are completely ignored. This is "just talk to me" mode.
|
|
49
|
+
|
|
50
|
+
**Business Mode**: Bloby has its own dedicated WhatsApp number. Numbers in the `admins` array get admin access (main system prompt). Everyone else is a customer and gets the support prompt from the active skill's SCRIPT.md.
|
|
51
|
+
|
|
52
|
+
**Assistant Mode**: Your personal assistant inside your own conversations. Self-chat works as a normal admin channel. When other people message you, their messages are silently stored for context. When YOU type `@botname:` followed by a command in someone's chat, the agent activates with full conversation context and responds in that chat. The trigger uses the bot's configured name (from `config.json` `username` field) and is case-insensitive. Nobody else can trigger the agent — only you (the account owner). Uses the active skill's SCRIPT.md for the system prompt and `customer_data/` for per-contact memory.
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## Setup
|
|
57
|
+
|
|
58
|
+
### 1. Connect WhatsApp
|
|
59
|
+
|
|
60
|
+
When your human asks to configure WhatsApp:
|
|
61
|
+
|
|
62
|
+
1. Start the connection:
|
|
63
|
+
```bash
|
|
64
|
+
curl -s -X POST http://localhost:7400/api/channels/whatsapp/connect
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
2. Tell them to open the QR page: `/api/channels/whatsapp/qr-page`
|
|
68
|
+
(Send this as a relative URL — their browser is already on the correct domain. Don't mention the URL until you are actually starting the connection)
|
|
69
|
+
|
|
70
|
+
3. They scan the QR with their WhatsApp app
|
|
71
|
+
|
|
72
|
+
4. The default mode is **channel** (self-chat only)
|
|
73
|
+
|
|
74
|
+
If the QR page doesn't load, make sure you initiated the connection first (step 1).
|
|
75
|
+
|
|
76
|
+
**On mobile?** The QR page also offers a "Link with phone number instead" option. The user enters their phone number, gets an 8-character code, and types it into WhatsApp (Settings > Linked Devices > Link a Device > "Link with phone number instead"). No camera needed.
|
|
77
|
+
|
|
78
|
+
### 2. Choose a Mode
|
|
79
|
+
|
|
80
|
+
**Channel mode** (default) — personal assistant. Only self-chat triggers the agent:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
curl -s -X POST http://localhost:7400/api/channels/whatsapp/configure \
|
|
84
|
+
-H "Content-Type: application/json" \
|
|
85
|
+
-d '{"mode":"channel"}'
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
**Business mode** — customer-facing. The agent responds to incoming messages from customers using a skill's SCRIPT.md. Admin numbers get full agent access:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
curl -s -X POST http://localhost:7400/api/channels/whatsapp/configure \
|
|
92
|
+
-H "Content-Type: application/json" \
|
|
93
|
+
-d '{"mode":"business","admins":["ADMIN_PHONE_1","ADMIN_PHONE_2"],"skill":"SKILL_FOLDER_NAME"}'
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Replace `ADMIN_PHONE_1` with the human's phone number (digits only, with country code, e.g. `5511999887766`). Replace `SKILL_FOLDER_NAME` with the skill that should handle customer conversations (e.g. `whatsapp-clinic-secretary`).
|
|
97
|
+
|
|
98
|
+
**Assistant mode** — personal assistant in your conversations. Self-chat works normally. Other people's messages are stored silently. Type `@botname: <command>` in any chat to trigger the agent:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
curl -s -X POST http://localhost:7400/api/channels/whatsapp/configure \
|
|
102
|
+
-H "Content-Type: application/json" \
|
|
103
|
+
-d '{"mode":"assistant","skill":"SKILL_FOLDER_NAME"}'
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
The trigger uses the bot's name from `config.json` `username` field (e.g. if username is "bloby", trigger is `@bloby:`). Only the account owner can trigger — other people's messages are context only.
|
|
107
|
+
|
|
108
|
+
### 3. Verify
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
curl -s http://localhost:7400/api/channels/status
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Expected: `"channel":"whatsapp","connected":true`
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
## Business Mode — Active Skill
|
|
119
|
+
|
|
120
|
+
Only ONE skill can be active for customer-facing mode at a time. The active skill is set in the channel config (`channels.whatsapp.skill`). When your human asks to switch skills:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
curl -s -X POST http://localhost:7400/api/channels/whatsapp/configure \
|
|
124
|
+
-H "Content-Type: application/json" -d '{"skill":"whatsapp-clinic"}'
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
The active skill should have:
|
|
128
|
+
- `SCRIPT.md` — the customer-facing system prompt (loaded automatically for customer conversations)
|
|
129
|
+
- Optionally a `customer_data/` directory — per-customer memory files (named by phone number, e.g. `5511999887766.md`)
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
## Sending Proactive Messages
|
|
134
|
+
|
|
135
|
+
To INITIATE a WhatsApp message (during pulse, cron, or when you want to reach out first):
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
curl -s -X POST http://localhost:7400/api/channels/send \
|
|
139
|
+
-H "Content-Type: application/json" \
|
|
140
|
+
-d '{"channel":"whatsapp","to":"5511999888777","text":"Your appointment is confirmed for tomorrow at 2pm."}'
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Phone number format: digits with country code (e.g. `5511999887766`). The system normalizes to WhatsApp JID format automatically.
|
|
144
|
+
|
|
145
|
+
**Remember:** This is ONLY for starting new conversations or sending unprompted messages. When replying to an incoming message, just respond normally — the supervisor handles delivery.
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## Customer Conversation Logs
|
|
150
|
+
|
|
151
|
+
When you finish a conversation with a **customer** via WhatsApp, save a summary to `whatsapp/{phone}.md`:
|
|
152
|
+
- Key details from the conversation
|
|
153
|
+
- Outcome (appointment scheduled, question answered, etc.)
|
|
154
|
+
- Any follow-ups needed
|
|
155
|
+
- Timestamp
|
|
156
|
+
|
|
157
|
+
This is your memory of that customer. Next time they message, read their file first.
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## Voice Notes
|
|
162
|
+
|
|
163
|
+
Voice messages are automatically transcribed via Whisper and delivered as text. No extra setup needed if Whisper is configured on the supervisor.
|
|
164
|
+
|
|
165
|
+
## Typing Indicator
|
|
166
|
+
|
|
167
|
+
The agent automatically shows "typing..." to the recipient while composing a response. This is handled by the supervisor — no action needed from you.
|
|
168
|
+
|
|
169
|
+
## Message Buffering (Business Mode)
|
|
170
|
+
|
|
171
|
+
In business mode, rapid messages from the same customer are debounced (4-second window) and delivered together. The system maintains a 30-message conversation buffer per customer.
|
|
172
|
+
|
|
173
|
+
## Concurrent Conversations (Business Mode)
|
|
174
|
+
|
|
175
|
+
Up to 5 customer conversations can run in parallel. Additional messages queue automatically.
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## Account Management
|
|
180
|
+
|
|
181
|
+
**Disconnect** (keep credentials for later):
|
|
182
|
+
```bash
|
|
183
|
+
curl -s -X POST http://localhost:7400/api/channels/whatsapp/disconnect
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
**Logout** (delete credentials, requires new QR scan):
|
|
187
|
+
```bash
|
|
188
|
+
curl -s -X POST http://localhost:7400/api/channels/whatsapp/logout
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
**Switch accounts** (relink): Use the "Relink" button on the QR page, or logout + connect again.
|
|
192
|
+
|
|
193
|
+
---
|
|
194
|
+
|
|
195
|
+
## Human Interaction
|
|
196
|
+
|
|
197
|
+
- The human must scan the QR code with their phone — this cannot be automated
|
|
198
|
+
- If WhatsApp disconnects (phone lost, account switched), the human needs to re-scan
|
|
199
|
+
- In business mode, explain to the human that admin numbers get full agent access while all other numbers get the customer-facing skill
|
|
200
|
+
- If the human asks about privacy: credentials are stored locally at `~/.bloby/channels/whatsapp/auth/`, never sent to external servers
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## API Reference
|
|
205
|
+
|
|
206
|
+
| Endpoint | Method | Purpose |
|
|
207
|
+
|----------|--------|---------|
|
|
208
|
+
| `/api/channels/status` | GET | List all channel statuses |
|
|
209
|
+
| `/api/channels/whatsapp/qr` | GET | Get current QR code SVG |
|
|
210
|
+
| `/api/channels/whatsapp/qr-page` | GET | Standalone QR scanning page |
|
|
211
|
+
| `/api/channels/whatsapp/connect` | POST | Start WhatsApp (triggers QR if needed) |
|
|
212
|
+
| `/api/channels/whatsapp/disconnect` | POST | Disconnect WhatsApp |
|
|
213
|
+
| `/api/channels/whatsapp/logout` | POST | Disconnect + delete credentials |
|
|
214
|
+
| `/api/channels/whatsapp/configure` | POST | Set mode + admins + skill |
|
|
215
|
+
| `/api/channels/whatsapp/pairing-code` | POST | Get 8-char pairing code (mobile linking) |
|
|
216
|
+
| `/api/channels/send` | POST | Send proactive message via channel |
|
|
217
|
+
|
|
218
|
+
All endpoints use `http://localhost:7400` for internal API calls (curl from your terminal). For URLs shown to your human, use relative paths (e.g. `/api/channels/whatsapp/qr-page`) — their browser is already on the correct domain.
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
## Technical Notes
|
|
223
|
+
|
|
224
|
+
- Baileys is a reverse-engineering of WhatsApp Web. It can break if WhatsApp changes their protocol. Reconnection is automatic on network drops.
|
|
225
|
+
- If you get error 401 (loggedOut), credentials were invalidated — the human needs to re-scan QR.
|
|
226
|
+
- If you get error 440 (connectionReplaced), another device/instance took over — do NOT auto-reconnect, ask the human.
|
|
227
|
+
- LID (Local ID) vs phone number: WhatsApp uses internal IDs. The system translates them automatically — use phone numbers in all your API calls.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "whatsapp",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"type": "skill",
|
|
5
|
+
"bloby_human": "Bruno Bertapeli",
|
|
6
|
+
"bloby": "bloby-bruno",
|
|
7
|
+
"author": "newbot-official",
|
|
8
|
+
"description": "WhatsApp channel for your agent via Baileys. QR auth, messaging, voice transcription, channel and business modes.",
|
|
9
|
+
"depends": [],
|
|
10
|
+
"env_keys": [],
|
|
11
|
+
"has_telemetry": false,
|
|
12
|
+
"size": "12KB",
|
|
13
|
+
"contains_binaries": false,
|
|
14
|
+
"tags": ["whatsapp", "channel", "messaging"]
|
|
15
|
+
}
|