@laburen/openclaw-plugin-whatsapp-api 0.4.0 → 0.5.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/index.js +66 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -419,6 +419,48 @@ async function sendWhatsAppApiMedia(params) {
|
|
|
419
419
|
}
|
|
420
420
|
});
|
|
421
421
|
}
|
|
422
|
+
/**
|
|
423
|
+
* Marks a message as read in the WhatsApp Cloud API.
|
|
424
|
+
*
|
|
425
|
+
* @param params.messageId - The WhatsApp message ID to mark as read
|
|
426
|
+
* @param params.account - Resolved account for Graph auth
|
|
427
|
+
* @returns Graph message id (usually just "unknown" or empty for read marks)
|
|
428
|
+
*/
|
|
429
|
+
async function sendWhatsAppApiReadMark(params) {
|
|
430
|
+
const { phoneNumberId, accessToken } = resolveGraphAuth(params.account);
|
|
431
|
+
return await sendWithRetry({
|
|
432
|
+
endpoint: `https://graph.facebook.com/${params.account.outboundApiVersion}/${phoneNumberId}/messages`,
|
|
433
|
+
account: params.account,
|
|
434
|
+
accessToken,
|
|
435
|
+
payload: {
|
|
436
|
+
messaging_product: "whatsapp",
|
|
437
|
+
status: "read",
|
|
438
|
+
message_id: params.messageId
|
|
439
|
+
}
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Shows/hides the typing indicator in the WhatsApp Cloud API.
|
|
444
|
+
*
|
|
445
|
+
* @param params.to - Recipient WhatsApp ID
|
|
446
|
+
* @param params.typing - `true` for "typing_on", `false` for "typing_off"
|
|
447
|
+
* @param params.account - Resolved account for Graph auth
|
|
448
|
+
* @returns Graph message id
|
|
449
|
+
*/
|
|
450
|
+
async function sendWhatsAppApiTypingIndicator(params) {
|
|
451
|
+
const { phoneNumberId, accessToken } = resolveGraphAuth(params.account);
|
|
452
|
+
return await sendWithRetry({
|
|
453
|
+
endpoint: `https://graph.facebook.com/${params.account.outboundApiVersion}/${phoneNumberId}/messages`,
|
|
454
|
+
account: params.account,
|
|
455
|
+
accessToken,
|
|
456
|
+
payload: {
|
|
457
|
+
messaging_product: "whatsapp",
|
|
458
|
+
recipient_type: "individual",
|
|
459
|
+
to: normalizeRecipient(params.to),
|
|
460
|
+
sender_action: params.typing ? "typing_on" : "typing_off"
|
|
461
|
+
}
|
|
462
|
+
});
|
|
463
|
+
}
|
|
422
464
|
async function sendWhatsAppApiLocation(params) {
|
|
423
465
|
const { phoneNumberId, accessToken } = resolveGraphAuth(params.account);
|
|
424
466
|
return await sendWithRetry({
|
|
@@ -1181,9 +1223,33 @@ async function dispatchInboundToAgent(params) {
|
|
|
1181
1223
|
OriginatingTo: to
|
|
1182
1224
|
});
|
|
1183
1225
|
const dispatchFn = replyApi.dispatchReplyWithBufferedBlockDispatcher;
|
|
1226
|
+
sendWhatsAppApiReadMark({
|
|
1227
|
+
messageId: message.messageId,
|
|
1228
|
+
account
|
|
1229
|
+
}).catch((err) => log$3.warn("failed to mark read", {
|
|
1230
|
+
error: String(err),
|
|
1231
|
+
messageId: message.messageId
|
|
1232
|
+
}));
|
|
1184
1233
|
await dispatchFn({
|
|
1185
1234
|
ctx: ctxPayload,
|
|
1186
1235
|
cfg,
|
|
1236
|
+
typing: {
|
|
1237
|
+
start: async () => {
|
|
1238
|
+
await sendWhatsAppApiTypingIndicator({
|
|
1239
|
+
to: message.from,
|
|
1240
|
+
typing: true,
|
|
1241
|
+
account
|
|
1242
|
+
});
|
|
1243
|
+
},
|
|
1244
|
+
stop: async () => {
|
|
1245
|
+
await sendWhatsAppApiTypingIndicator({
|
|
1246
|
+
to: message.from,
|
|
1247
|
+
typing: false,
|
|
1248
|
+
account
|
|
1249
|
+
});
|
|
1250
|
+
},
|
|
1251
|
+
onStartError: (err) => log$3.warn("failed to start typing", { error: String(err) })
|
|
1252
|
+
},
|
|
1187
1253
|
dispatcherOptions: {
|
|
1188
1254
|
deliver: async (payload) => {
|
|
1189
1255
|
const account = resolveAccount(cfg, accountId);
|