bloby-bot 0.26.0 → 0.27.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/dist-bloby/assets/{bloby-BYvWezrE.js → bloby-CqtSjokc.js} +5 -5
- package/dist-bloby/assets/{globals-DpyxaQZD.js → globals-zKQhzQOX.js} +1 -1
- package/dist-bloby/assets/{highlighted-body-OFNGDK62-CXqhfwnV.js → highlighted-body-OFNGDK62-B0W8hCx-.js} +1 -1
- package/dist-bloby/assets/mermaid-GHXKKRXX-Dr8I7wwH.js +1 -0
- package/dist-bloby/assets/{onboard-BcRuwne9.js → onboard-C1yXK8uT.js} +1 -1
- package/dist-bloby/bloby.html +2 -2
- package/dist-bloby/onboard.html +2 -2
- package/package.json +4 -4
- package/shared/config.ts +17 -1
- package/supervisor/channels/manager.ts +73 -13
- package/supervisor/channels/whatsapp.ts +58 -0
- package/supervisor/index.ts +19 -5
- package/dist-bloby/assets/mermaid-GHXKKRXX-AJlBbjxC.js +0 -1
|
@@ -131,6 +131,64 @@ export class WhatsAppChannel implements ChannelProvider {
|
|
|
131
131
|
log.info(`[whatsapp] Sent image to ${jid} (id=${result?.key?.id || 'unknown'})`);
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
+
/** Send an audio file via WhatsApp. Set voiceNote=true for push-to-talk bubble. */
|
|
135
|
+
async sendAudio(to: string, audio: Buffer, opts?: { mimetype?: string; voiceNote?: boolean }): Promise<void> {
|
|
136
|
+
if (!this.sock || !this.connected) {
|
|
137
|
+
log.warn('[whatsapp] Cannot send audio — not connected');
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const jid = to.includes('@') ? to : `${to.replace(/[^0-9]/g, '')}@s.whatsapp.net`;
|
|
141
|
+
this.stopTyping(jid);
|
|
142
|
+
|
|
143
|
+
const msg: any = {
|
|
144
|
+
audio,
|
|
145
|
+
mimetype: opts?.mimetype || 'audio/mpeg',
|
|
146
|
+
ptt: !!opts?.voiceNote,
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
const result = await this.sock.sendMessage(jid, msg);
|
|
150
|
+
if (result?.key?.id) this.trackSentId(result.key.id);
|
|
151
|
+
log.info(`[whatsapp] Sent audio to ${jid} (ptt=${msg.ptt}, mime=${msg.mimetype}, id=${result?.key?.id || 'unknown'})`);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** Send a video via WhatsApp */
|
|
155
|
+
async sendVideo(to: string, video: Buffer, caption?: string, mimetype?: string): Promise<void> {
|
|
156
|
+
if (!this.sock || !this.connected) {
|
|
157
|
+
log.warn('[whatsapp] Cannot send video — not connected');
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
const jid = to.includes('@') ? to : `${to.replace(/[^0-9]/g, '')}@s.whatsapp.net`;
|
|
161
|
+
this.stopTyping(jid);
|
|
162
|
+
|
|
163
|
+
const msg: any = { video, mimetype: mimetype || 'video/mp4' };
|
|
164
|
+
if (caption) msg.caption = caption;
|
|
165
|
+
|
|
166
|
+
const result = await this.sock.sendMessage(jid, msg);
|
|
167
|
+
if (result?.key?.id) this.trackSentId(result.key.id);
|
|
168
|
+
log.info(`[whatsapp] Sent video to ${jid} (id=${result?.key?.id || 'unknown'})`);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** Send a document (PDF, zip, etc.) via WhatsApp */
|
|
172
|
+
async sendDocument(to: string, document: Buffer, fileName: string, mimetype?: string, caption?: string): Promise<void> {
|
|
173
|
+
if (!this.sock || !this.connected) {
|
|
174
|
+
log.warn('[whatsapp] Cannot send document — not connected');
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
const jid = to.includes('@') ? to : `${to.replace(/[^0-9]/g, '')}@s.whatsapp.net`;
|
|
178
|
+
this.stopTyping(jid);
|
|
179
|
+
|
|
180
|
+
const msg: any = {
|
|
181
|
+
document,
|
|
182
|
+
mimetype: mimetype || 'application/octet-stream',
|
|
183
|
+
fileName,
|
|
184
|
+
};
|
|
185
|
+
if (caption) msg.caption = caption;
|
|
186
|
+
|
|
187
|
+
const result = await this.sock.sendMessage(jid, msg);
|
|
188
|
+
if (result?.key?.id) this.trackSentId(result.key.id);
|
|
189
|
+
log.info(`[whatsapp] Sent document to ${jid} (name=${fileName}, id=${result?.key?.id || 'unknown'})`);
|
|
190
|
+
}
|
|
191
|
+
|
|
134
192
|
/** Show "typing..." indicator in a chat. Re-sends every 20s to keep it visible. */
|
|
135
193
|
startTyping(jid: string): void {
|
|
136
194
|
if (!this.sock || !this.connected) return;
|
package/supervisor/index.ts
CHANGED
|
@@ -734,19 +734,33 @@ ${!connected ? `<script>
|
|
|
734
734
|
return;
|
|
735
735
|
}
|
|
736
736
|
|
|
737
|
-
// POST /api/channels/send — send a message via any channel
|
|
737
|
+
// POST /api/channels/send — send a message (and/or media) via any channel
|
|
738
738
|
if (req.method === 'POST' && channelPath === '/api/channels/send') {
|
|
739
739
|
let body = '';
|
|
740
740
|
req.on('data', (chunk: Buffer) => { body += chunk.toString(); });
|
|
741
741
|
req.on('end', async () => {
|
|
742
742
|
try {
|
|
743
|
-
const { channel, to, text } = JSON.parse(body);
|
|
744
|
-
if (!channel || !to
|
|
743
|
+
const { channel, to, text, media } = JSON.parse(body);
|
|
744
|
+
if (!channel || !to) {
|
|
745
745
|
res.writeHead(400);
|
|
746
|
-
res.end(JSON.stringify({ error: 'Missing channel
|
|
746
|
+
res.end(JSON.stringify({ error: 'Missing channel or to' }));
|
|
747
747
|
return;
|
|
748
748
|
}
|
|
749
|
-
|
|
749
|
+
if (!text && !media) {
|
|
750
|
+
res.writeHead(400);
|
|
751
|
+
res.end(JSON.stringify({ error: 'Missing text or media' }));
|
|
752
|
+
return;
|
|
753
|
+
}
|
|
754
|
+
if (media) {
|
|
755
|
+
if (!media.type || !media.path) {
|
|
756
|
+
res.writeHead(400);
|
|
757
|
+
res.end(JSON.stringify({ error: 'media requires { type, path }' }));
|
|
758
|
+
return;
|
|
759
|
+
}
|
|
760
|
+
await channelManager.sendMedia(channel, to, media, text);
|
|
761
|
+
} else {
|
|
762
|
+
await channelManager.sendMessage(channel, to, text);
|
|
763
|
+
}
|
|
750
764
|
res.writeHead(200);
|
|
751
765
|
res.end(JSON.stringify({ ok: true }));
|
|
752
766
|
} catch (err: any) {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{i as e}from"./bloby-BYvWezrE.js";export{e as Mermaid};
|