@im-more/dsh-whatsapp 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/cordis.patch.yml +12 -0
- package/lib/index.js +1694 -0
- package/lib/index.js.map +1 -0
- package/lib/types/bot.d.ts +66 -0
- package/lib/types/bot.d.ts.map +1 -0
- package/lib/types/bot.js +164 -0
- package/lib/types/bot.js.map +1 -0
- package/lib/types/config.d.ts +40 -0
- package/lib/types/config.d.ts.map +1 -0
- package/lib/types/config.js +63 -0
- package/lib/types/config.js.map +1 -0
- package/lib/types/decode.d.ts +64 -0
- package/lib/types/decode.d.ts.map +1 -0
- package/lib/types/decode.js +244 -0
- package/lib/types/decode.js.map +1 -0
- package/lib/types/errors.d.ts +53 -0
- package/lib/types/errors.d.ts.map +1 -0
- package/lib/types/errors.js +149 -0
- package/lib/types/errors.js.map +1 -0
- package/lib/types/identity.d.ts +48 -0
- package/lib/types/identity.d.ts.map +1 -0
- package/lib/types/identity.js +52 -0
- package/lib/types/identity.js.map +1 -0
- package/lib/types/index.d.ts +16 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +15 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/interactive.d.ts +45 -0
- package/lib/types/interactive.d.ts.map +1 -0
- package/lib/types/interactive.js +111 -0
- package/lib/types/interactive.js.map +1 -0
- package/lib/types/internal.d.ts +28 -0
- package/lib/types/internal.d.ts.map +1 -0
- package/lib/types/internal.js +35 -0
- package/lib/types/internal.js.map +1 -0
- package/lib/types/media.d.ts +17 -0
- package/lib/types/media.d.ts.map +1 -0
- package/lib/types/media.js +49 -0
- package/lib/types/media.js.map +1 -0
- package/lib/types/modes/shared.d.ts +112 -0
- package/lib/types/modes/shared.d.ts.map +1 -0
- package/lib/types/modes/shared.js +285 -0
- package/lib/types/modes/shared.js.map +1 -0
- package/lib/types/modes/text.d.ts +19 -0
- package/lib/types/modes/text.d.ts.map +1 -0
- package/lib/types/modes/text.js +126 -0
- package/lib/types/modes/text.js.map +1 -0
- package/lib/types/request.d.ts +61 -0
- package/lib/types/request.d.ts.map +1 -0
- package/lib/types/request.js +193 -0
- package/lib/types/request.js.map +1 -0
- package/lib/types/send.d.ts +47 -0
- package/lib/types/send.d.ts.map +1 -0
- package/lib/types/send.js +74 -0
- package/lib/types/send.js.map +1 -0
- package/lib/types/signature.d.ts +33 -0
- package/lib/types/signature.d.ts.map +1 -0
- package/lib/types/signature.js +46 -0
- package/lib/types/signature.js.map +1 -0
- package/lib/types/transport/webhook.d.ts +50 -0
- package/lib/types/transport/webhook.d.ts.map +1 -0
- package/lib/types/transport/webhook.js +197 -0
- package/lib/types/transport/webhook.js.map +1 -0
- package/lib/types/types.d.ts +198 -0
- package/lib/types/types.d.ts.map +1 -0
- package/lib/types/types.js +2 -0
- package/lib/types/types.js.map +1 -0
- package/package.json +61 -3
- package/src/bot.ts +233 -0
- package/src/config.ts +98 -0
- package/src/decode.ts +335 -0
- package/src/errors.ts +189 -0
- package/src/identity.ts +76 -0
- package/src/index.ts +100 -0
- package/src/interactive.ts +135 -0
- package/src/internal.ts +49 -0
- package/src/media.ts +59 -0
- package/src/modes/shared.ts +354 -0
- package/src/modes/text.ts +174 -0
- package/src/request.ts +238 -0
- package/src/send.ts +120 -0
- package/src/signature.ts +54 -0
- package/src/transport/webhook.ts +267 -0
- package/src/types.ts +244 -0
- package/README.md +0 -3
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { Config, configError, routePath, type Config as WhatsappConfig, } from './config.ts';
|
|
2
|
+
export { WhatsappBot, WhatsappBot as default, type WhatsappModes, } from './bot.ts';
|
|
3
|
+
export { chatRefOf, contextOf, decodeChange, decodeMessage, senderOf, timeOf, type WhatsappContext, type WhatsappReferrer, } from './decode.ts';
|
|
4
|
+
export { classifyWhatsappError, WhatsappApiError, type WhatsappApiErrorInit, } from './errors.ts';
|
|
5
|
+
export { fetchPhoneNumber, userOf, verifyIdentity, WhatsappIdentityError, type PhoneNumberInfo, } from './identity.ts';
|
|
6
|
+
export { Internal } from './internal.ts';
|
|
7
|
+
export { decodeInteractive, decodeReaction, decodeTemplateButton, } from './interactive.ts';
|
|
8
|
+
export { serveMedia } from './media.ts';
|
|
9
|
+
export { assembleDraft, checkDraft, reportMovedMedia, serializeDraft, splitText, SUPPORTED_MEDIA, WHATSAPP_LIMITS, type WhatsappDraft, type WhatsappMediaTag, type WhatsappModeTypes, type WhatsappNode, type WhatsappPayload, } from './modes/shared.ts';
|
|
10
|
+
export { createTextMode } from './modes/text.ts';
|
|
11
|
+
export { WhatsAppRequest } from './request.ts';
|
|
12
|
+
export { createReaction, deleteReaction, sendPayload, type WhatsappSendDeps, } from './send.ts';
|
|
13
|
+
export { constantTimeEqual, matchesSignature, SIGNATURE_HEADER, signatureOf, } from './signature.ts';
|
|
14
|
+
export { WhatsappWebhook, type WebHandlerRoute, type WebServerLike, } from './transport/webhook.ts';
|
|
15
|
+
export type { Button, Change, Entry, MediaType, MessageBody, MessageBodyBase, MessageBodyButton, MessageBodyContacts, MessageBodyInteractive, MessageBodyLocation, MessageBodyMedia, MessageBodyReaction, MessageBodySticker, MessageBodySystem, MessageBodyText, MessageValue, ReceivedMedia, SendButtonMessage, SendMediaMessage, SendMessage, SendMessageBase, SendReactionMessage, SendTextMessage, StatusBody, WebhookBody, } from './types.ts';
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,WAAW,EACX,SAAS,EACT,KAAK,MAAM,IAAI,cAAc,GAC9B,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,WAAW,EACX,WAAW,IAAI,OAAO,EACtB,KAAK,aAAa,GACnB,MAAM,UAAU,CAAA;AACjB,OAAO,EACL,SAAS,EACT,SAAS,EACT,YAAY,EACZ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AAe,EACf,YAAY,EACZ,aAAa,EACb,iBAAiB,EACjB,gBAAgB,EAChB,WAAW,EACX,eAAe,EACf,mBAAmB,EACnB,eAAe,EACf,UAAU,EACV,WAAW,GACZ,MAAM,YAAY,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { Config, configError, routePath, } from "./config.js";
|
|
2
|
+
export { WhatsappBot, WhatsappBot as default, } from "./bot.js";
|
|
3
|
+
export { chatRefOf, contextOf, decodeChange, decodeMessage, senderOf, timeOf, } from "./decode.js";
|
|
4
|
+
export { classifyWhatsappError, WhatsappApiError, } from "./errors.js";
|
|
5
|
+
export { fetchPhoneNumber, userOf, verifyIdentity, WhatsappIdentityError, } from "./identity.js";
|
|
6
|
+
export { Internal } from "./internal.js";
|
|
7
|
+
export { decodeInteractive, decodeReaction, decodeTemplateButton, } from "./interactive.js";
|
|
8
|
+
export { serveMedia } from "./media.js";
|
|
9
|
+
export { assembleDraft, checkDraft, reportMovedMedia, serializeDraft, splitText, SUPPORTED_MEDIA, WHATSAPP_LIMITS, } from "./modes/shared.js";
|
|
10
|
+
export { createTextMode } from "./modes/text.js";
|
|
11
|
+
export { WhatsAppRequest } from "./request.js";
|
|
12
|
+
export { createReaction, deleteReaction, sendPayload, } from "./send.js";
|
|
13
|
+
export { constantTimeEqual, matchesSignature, SIGNATURE_HEADER, signatureOf, } from "./signature.js";
|
|
14
|
+
export { WhatsappWebhook, } from "./transport/webhook.js";
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,WAAW,EACX,SAAS,GAEV,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,WAAW,EACX,WAAW,IAAI,OAAO,GAEvB,MAAM,UAAU,CAAA;AACjB,OAAO,EACL,SAAS,EACT,SAAS,EACT,YAAY,EACZ,aAAa,EACb,QAAQ,EACR,MAAM,GAGP,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,qBAAqB,EACrB,gBAAgB,GAEjB,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,gBAAgB,EAChB,MAAM,EACN,cAAc,EACd,qBAAqB,GAEtB,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,oBAAoB,GACrB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,EACL,aAAa,EACb,UAAU,EACV,gBAAgB,EAChB,cAAc,EACd,SAAS,EACT,eAAe,EACf,eAAe,GAMhB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EACL,cAAc,EACd,cAAc,EACd,WAAW,GAEZ,MAAM,WAAW,CAAA;AAClB,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,WAAW,GACZ,MAAM,gBAAgB,CAAA;AACvB,OAAO,EACL,eAAe,GAGhB,MAAM,wBAAwB,CAAA"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inbound interactions and reactions.
|
|
3
|
+
*
|
|
4
|
+
* A WhatsApp reply button, list pick or template quick reply is not a text message: it answers a message this bot sent
|
|
5
|
+
* (through `context.message_id`), and the host routes it to the callback registered under the id the button carried.
|
|
6
|
+
* A reaction is the platform's only other inbound signal; removing one is an empty emoji.
|
|
7
|
+
*/
|
|
8
|
+
import type { Session } from '@deepseek-ai/cordis-plugin-im-core';
|
|
9
|
+
import type { WhatsappBot } from './bot.ts';
|
|
10
|
+
import type { WhatsappContext } from './decode.ts';
|
|
11
|
+
import type { MessageBodyButton, MessageBodyInteractive, MessageBodyReaction } from './types.ts';
|
|
12
|
+
/**
|
|
13
|
+
* Decode a reaction into `reaction-added` or `reaction-removed`.
|
|
14
|
+
*
|
|
15
|
+
* The reaction names the message it applies to, the reactor and the emoji; the chat is the reactor's own conversation,
|
|
16
|
+
* which is the only chat a reaction payload can come from.
|
|
17
|
+
*
|
|
18
|
+
* @param bot - the receiving adapter.
|
|
19
|
+
* @param message - the reaction message.
|
|
20
|
+
* @param context - the chat, sender and referrer of the payload.
|
|
21
|
+
* @returns the session to publish.
|
|
22
|
+
*/
|
|
23
|
+
export declare function decodeReaction(bot: WhatsappBot, message: MessageBodyReaction, context: WhatsappContext): Session;
|
|
24
|
+
/**
|
|
25
|
+
* Decode a reply button or a list pick.
|
|
26
|
+
*
|
|
27
|
+
* @param bot - the receiving adapter.
|
|
28
|
+
* @param message - the interactive message.
|
|
29
|
+
* @param context - the chat, sender and referrer of the payload.
|
|
30
|
+
* @returns the `interaction/button` or `interaction/select` session.
|
|
31
|
+
*/
|
|
32
|
+
export declare function decodeInteractive(bot: WhatsappBot, message: MessageBodyInteractive, context: WhatsappContext): Session;
|
|
33
|
+
/**
|
|
34
|
+
* Decode a template quick reply.
|
|
35
|
+
*
|
|
36
|
+
* A template's quick reply carries an optional `payload`; a template written without one leaves the button text as the
|
|
37
|
+
* only identity the reply has.
|
|
38
|
+
*
|
|
39
|
+
* @param bot - the receiving adapter.
|
|
40
|
+
* @param message - the `button` message.
|
|
41
|
+
* @param context - the chat, sender and referrer of the payload.
|
|
42
|
+
* @returns the `interaction/button` session.
|
|
43
|
+
*/
|
|
44
|
+
export declare function decodeTemplateButton(bot: WhatsappBot, message: MessageBodyButton, context: WhatsappContext): Session;
|
|
45
|
+
//# sourceMappingURL=interactive.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interactive.d.ts","sourceRoot":"","sources":["../../src/interactive.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oCAAoC,CAAA;AACjE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAC3C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAClD,OAAO,KAAK,EACV,iBAAiB,EACjB,sBAAsB,EACtB,mBAAmB,EACpB,MAAM,YAAY,CAAA;AAEnB;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAC5B,GAAG,EAAE,WAAW,EAChB,OAAO,EAAE,mBAAmB,EAC5B,OAAO,EAAE,eAAe,GACvB,OAAO,CAYT;AAOD;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,WAAW,EAChB,OAAO,EAAE,sBAAsB,EAC/B,OAAO,EAAE,eAAe,GACvB,OAAO,CAsCT;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,WAAW,EAChB,OAAO,EAAE,iBAAiB,EAC1B,OAAO,EAAE,eAAe,GACvB,OAAO,CAgBT"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inbound interactions and reactions.
|
|
3
|
+
*
|
|
4
|
+
* A WhatsApp reply button, list pick or template quick reply is not a text message: it answers a message this bot sent
|
|
5
|
+
* (through `context.message_id`), and the host routes it to the callback registered under the id the button carried.
|
|
6
|
+
* A reaction is the platform's only other inbound signal; removing one is an empty emoji.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Decode a reaction into `reaction-added` or `reaction-removed`.
|
|
10
|
+
*
|
|
11
|
+
* The reaction names the message it applies to, the reactor and the emoji; the chat is the reactor's own conversation,
|
|
12
|
+
* which is the only chat a reaction payload can come from.
|
|
13
|
+
*
|
|
14
|
+
* @param bot - the receiving adapter.
|
|
15
|
+
* @param message - the reaction message.
|
|
16
|
+
* @param context - the chat, sender and referrer of the payload.
|
|
17
|
+
* @returns the session to publish.
|
|
18
|
+
*/
|
|
19
|
+
export function decodeReaction(bot, message, context) {
|
|
20
|
+
return bot.session({
|
|
21
|
+
type: message.reaction.emoji === '' ? 'reaction-removed' : 'reaction-added',
|
|
22
|
+
id: message.id,
|
|
23
|
+
timestamp: context.timestamp,
|
|
24
|
+
reaction: {
|
|
25
|
+
message: { id: message.reaction.message_id, chat: context.chat },
|
|
26
|
+
emoji: message.reaction.emoji,
|
|
27
|
+
user: context.user,
|
|
28
|
+
},
|
|
29
|
+
raw: message,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/** The message an interaction answers: the one it quotes, or its own when the payload names no context. */
|
|
33
|
+
function answeredMessageId(message) {
|
|
34
|
+
return message.context?.id ?? message.id;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Decode a reply button or a list pick.
|
|
38
|
+
*
|
|
39
|
+
* @param bot - the receiving adapter.
|
|
40
|
+
* @param message - the interactive message.
|
|
41
|
+
* @param context - the chat, sender and referrer of the payload.
|
|
42
|
+
* @returns the `interaction/button` or `interaction/select` session.
|
|
43
|
+
*/
|
|
44
|
+
export function decodeInteractive(bot, message, context) {
|
|
45
|
+
const chat = context.chat;
|
|
46
|
+
const answer = { id: answeredMessageId(message), chat };
|
|
47
|
+
switch (message.interactive.type) {
|
|
48
|
+
case 'button_reply':
|
|
49
|
+
return bot.session({
|
|
50
|
+
type: 'interaction/button',
|
|
51
|
+
id: message.id,
|
|
52
|
+
timestamp: context.timestamp,
|
|
53
|
+
button: {
|
|
54
|
+
bot,
|
|
55
|
+
id: message.interactive.button_reply.id,
|
|
56
|
+
user: context.user,
|
|
57
|
+
chat,
|
|
58
|
+
message: answer,
|
|
59
|
+
referrer: context.referrer,
|
|
60
|
+
time: context.timestamp,
|
|
61
|
+
},
|
|
62
|
+
raw: message,
|
|
63
|
+
});
|
|
64
|
+
case 'list_reply':
|
|
65
|
+
return bot.session({
|
|
66
|
+
type: 'interaction/select',
|
|
67
|
+
id: message.id,
|
|
68
|
+
timestamp: context.timestamp,
|
|
69
|
+
select: {
|
|
70
|
+
bot,
|
|
71
|
+
id: message.interactive.list_reply.id,
|
|
72
|
+
values: [message.interactive.list_reply.title],
|
|
73
|
+
user: context.user,
|
|
74
|
+
chat,
|
|
75
|
+
message: answer,
|
|
76
|
+
referrer: context.referrer,
|
|
77
|
+
time: context.timestamp,
|
|
78
|
+
},
|
|
79
|
+
raw: message,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Decode a template quick reply.
|
|
85
|
+
*
|
|
86
|
+
* A template's quick reply carries an optional `payload`; a template written without one leaves the button text as the
|
|
87
|
+
* only identity the reply has.
|
|
88
|
+
*
|
|
89
|
+
* @param bot - the receiving adapter.
|
|
90
|
+
* @param message - the `button` message.
|
|
91
|
+
* @param context - the chat, sender and referrer of the payload.
|
|
92
|
+
* @returns the `interaction/button` session.
|
|
93
|
+
*/
|
|
94
|
+
export function decodeTemplateButton(bot, message, context) {
|
|
95
|
+
return bot.session({
|
|
96
|
+
type: 'interaction/button',
|
|
97
|
+
id: message.id,
|
|
98
|
+
timestamp: context.timestamp,
|
|
99
|
+
button: {
|
|
100
|
+
bot,
|
|
101
|
+
id: message.button.payload ?? message.button.text,
|
|
102
|
+
user: context.user,
|
|
103
|
+
chat: context.chat,
|
|
104
|
+
message: { id: message.context?.id ?? message.id, chat: context.chat },
|
|
105
|
+
referrer: context.referrer,
|
|
106
|
+
time: context.timestamp,
|
|
107
|
+
},
|
|
108
|
+
raw: message,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=interactive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interactive.js","sourceRoot":"","sources":["../../src/interactive.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAWH;;;;;;;;;;GAUG;AACH,MAAM,UAAU,cAAc,CAC5B,GAAgB,EAChB,OAA4B,EAC5B,OAAwB;IAExB,OAAO,GAAG,CAAC,OAAO,CAAC;QACjB,IAAI,EAAE,OAAO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ACxB;QACD,GAAG,EAAE,OAAO;KACb,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { WhatsAppRequest } from './request.ts';
|
|
2
|
+
import { SendMessage } from './types.ts';
|
|
3
|
+
interface PhoneNumber {
|
|
4
|
+
verified_name: string;
|
|
5
|
+
code_verification_status: string;
|
|
6
|
+
display_phone_number: string;
|
|
7
|
+
quality_rating: string;
|
|
8
|
+
id: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class Internal {
|
|
11
|
+
http: WhatsAppRequest;
|
|
12
|
+
constructor(http: WhatsAppRequest);
|
|
13
|
+
getPhoneNumbers(id: string): Promise<PhoneNumber[]>;
|
|
14
|
+
messageReaction(selfId: string, channelId: string, messageId: string, emoji: string): Promise<void>;
|
|
15
|
+
sendMessage(selfId: string, data: SendMessage): Promise<{
|
|
16
|
+
messages: {
|
|
17
|
+
id: string;
|
|
18
|
+
}[];
|
|
19
|
+
}>;
|
|
20
|
+
getMedia(mediaId: string): Promise<{
|
|
21
|
+
url: string;
|
|
22
|
+
}>;
|
|
23
|
+
uploadMedia(selfId: string, form: FormData): Promise<{
|
|
24
|
+
id: string;
|
|
25
|
+
}>;
|
|
26
|
+
}
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=internal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../src/internal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAExC,UAAU,WAAW;IACnB,aAAa,EAAE,MAAM,CAAA;IACrB,wBAAwB,EAAE,MAAM,CAAA;IAChC,oBAAoB,EAAE,MAAM,CAAA;IAC5B,cAAc,EAAE,MAAM,CAAA;IACtB,EAAE,EAAE,MAAM,CAAA;CACX;AAED,qBAAa,QAAQ;IACA,IAAI,EAAE,eAAe;gBAArB,IAAI,EAAE,eAAe;IAElC,eAAe,CAAC,EAAE,EAAE,MAAM;IAM1B,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAcnF,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW;kBAErC;YAAE,EAAE,EAAE,MAAM,CAAA;SAAE,EAAE;;IAK9B,QAAQ,CAAC,OAAO,EAAE,MAAM;aACM,MAAM;;IAGpC,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ;YACZ,MAAM;;CAErC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export class Internal {
|
|
2
|
+
http;
|
|
3
|
+
constructor(http) {
|
|
4
|
+
this.http = http;
|
|
5
|
+
}
|
|
6
|
+
async getPhoneNumbers(id) {
|
|
7
|
+
// https://developers.facebook.com/docs/whatsapp/business-management-api/manage-phone-numbers#all-phone-numbers
|
|
8
|
+
const { data } = await this.http.get(`/${id}/phone_numbers`);
|
|
9
|
+
return data;
|
|
10
|
+
}
|
|
11
|
+
async messageReaction(selfId, channelId, messageId, emoji) {
|
|
12
|
+
// https://developers.facebook.com/docs/whatsapp/cloud-api/guides/send-messages#reaction-messages
|
|
13
|
+
await this.http.post(`/${selfId}/messages`, {
|
|
14
|
+
messaging_product: 'whatsapp',
|
|
15
|
+
to: channelId,
|
|
16
|
+
recipient_type: 'individual',
|
|
17
|
+
type: 'reaction',
|
|
18
|
+
reaction: {
|
|
19
|
+
message_id: messageId,
|
|
20
|
+
emoji,
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
async sendMessage(selfId, data) {
|
|
25
|
+
const response = await this.http.post(`/${selfId}/messages`, data);
|
|
26
|
+
return response;
|
|
27
|
+
}
|
|
28
|
+
getMedia(mediaId) {
|
|
29
|
+
return this.http.get('/' + mediaId);
|
|
30
|
+
}
|
|
31
|
+
uploadMedia(selfId, form) {
|
|
32
|
+
return this.http.post(`/${selfId}/media`, form);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=internal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../src/internal.ts"],"names":[],"mappings":"AAWA,MAAM,OAAO,QAAQ;IACA;IAAnB,YAAmB,IAAqB;QAArB,SAAI,GAAJ,IAAI,CAAiB;IAAI,CAAC;IAE7C,KAAK,CAAC,eAAe,CAAC,EAAU;QAC9B,+GAA+G;QAC/G,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAA0B,IAAI,EAAE,gBAAgB,CAAC,CAAA;QACrF,OAAO,IAAI,CAAA;IACb,CAAC;IAED,KAAK,CAAC,eAAe,CAAC,MAAc,EAAE,SAAiB,EAAE,SAAiB,EAAE,KAAa;QACvF,iGAAiG;QACjG,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,MAAM,WAAW,EAAE;YAC1C,iBAAiB,EAAE,UAAU;YAC7B,EAAE,EAAE,SAAS;YACb,cAAc,EAAE,YAAY;YAC5B,IAAI,EAAE,UAAU;YAChB,QAAQ,EAAE;gBACR,UAAU,EAAE,SAAS;gBACrB,KAAK;aACN;SACF,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,MAAc,EAAE,IAAiB;QACjD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAElC,IAAI,MAAM,WAAW,EAAE,IAAI,CAAC,CAAA;QAC/B,OAAO,QAAQ,CAAA;IACjB,CAAC;IAED,QAAQ,CAAC,OAAe;QACtB,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAkB,GAAG,GAAG,OAAO,CAAC,CAAA;IACtD,CAAC;IAED,WAAW,CAAC,MAAc,EAAE,IAAc;QACxC,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAiB,IAAI,MAAM,QAAQ,EAAE,IAAI,CAAC,CAAA;IACjE,CAAC;CACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inbound media: the `satori:` route behind an image, audio, video or document element.
|
|
3
|
+
*
|
|
4
|
+
* The webhook names a media id, never a URL. Reading the bytes takes two requests: `GET /{mediaId}` resolves a
|
|
5
|
+
* short-lived address, and fetching that address — still with the bearer token — returns the bytes. The address is
|
|
6
|
+
* therefore resolved per request instead of being baked into the stored message.
|
|
7
|
+
*/
|
|
8
|
+
import type { WhatsappBot } from './bot.ts';
|
|
9
|
+
/**
|
|
10
|
+
* Serve the bytes of one received media object.
|
|
11
|
+
*
|
|
12
|
+
* @param bot - the receiving adapter.
|
|
13
|
+
* @param mediaId - the media id the webhook named.
|
|
14
|
+
* @returns the download answer, status and content headers included, or `502` when either step failed.
|
|
15
|
+
*/
|
|
16
|
+
export declare function serveMedia(bot: WhatsappBot, mediaId: string): Promise<Response>;
|
|
17
|
+
//# sourceMappingURL=media.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media.d.ts","sourceRoot":"","sources":["../../src/media.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAO3C;;;;;;GAMG;AACH,wBAAsB,UAAU,CAC9B,GAAG,EAAE,WAAW,EAChB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,QAAQ,CAAC,CAiCnB"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inbound media: the `satori:` route behind an image, audio, video or document element.
|
|
3
|
+
*
|
|
4
|
+
* The webhook names a media id, never a URL. Reading the bytes takes two requests: `GET /{mediaId}` resolves a
|
|
5
|
+
* short-lived address, and fetching that address — still with the bearer token — returns the bytes. The address is
|
|
6
|
+
* therefore resolved per request instead of being baked into the stored message.
|
|
7
|
+
*/
|
|
8
|
+
/** Message of any caught value, for a log line. */
|
|
9
|
+
function messageOf(error) {
|
|
10
|
+
return error instanceof Error ? error.message : String(error);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Serve the bytes of one received media object.
|
|
14
|
+
*
|
|
15
|
+
* @param bot - the receiving adapter.
|
|
16
|
+
* @param mediaId - the media id the webhook named.
|
|
17
|
+
* @returns the download answer, status and content headers included, or `502` when either step failed.
|
|
18
|
+
*/
|
|
19
|
+
export async function serveMedia(bot, mediaId) {
|
|
20
|
+
let address;
|
|
21
|
+
try {
|
|
22
|
+
const resolved = await bot.internal.getMedia(mediaId);
|
|
23
|
+
address = resolved.url;
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
bot.ctx.logger.warn('whatsapp: media %s could not be resolved: %s', mediaId, messageOf(error));
|
|
27
|
+
return new Response(null, { status: 502 });
|
|
28
|
+
}
|
|
29
|
+
let downloaded;
|
|
30
|
+
try {
|
|
31
|
+
downloaded = await bot.request.download(address);
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
bot.ctx.logger.warn('whatsapp: media %s could not be downloaded: %s', mediaId, messageOf(error));
|
|
35
|
+
return new Response(null, { status: 502 });
|
|
36
|
+
}
|
|
37
|
+
const headers = new Headers();
|
|
38
|
+
const mime = downloaded.headers.get('content-type');
|
|
39
|
+
if (mime !== null)
|
|
40
|
+
headers.set('content-type', mime);
|
|
41
|
+
const length = downloaded.headers.get('content-length');
|
|
42
|
+
if (length !== null)
|
|
43
|
+
headers.set('content-length', length);
|
|
44
|
+
return new Response(downloaded.status === 200 ? downloaded.body : null, {
|
|
45
|
+
status: downloaded.status,
|
|
46
|
+
headers,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=media.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media.js","sourceRoot":"","sources":["../../src/media.ts"],"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,IAAI;QAAE,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,IAAI,CAAC,CAAA;IACpD,MAAM,MAAM,GAAG,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAA;IACvD,IAAI,MAAM,KAAK,IAAI;QAAE,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAA;IAC1D,OAAO,IAAI,QAAQ,CAAC,UAAU,CAAC,MAAM,KAAK,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE;QACtE,MAAM,EAAE,UAAU,CAAC,MAAM;QACzB,OAAO;KACR,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared types and the draft machinery of the single `text` mode.
|
|
3
|
+
*
|
|
4
|
+
* One draft is exactly one platform message: WhatsApp has no request that carries several messages, so every draft is
|
|
5
|
+
* a `POST /{phoneNumberId}/messages` of its own. Text accumulates into a body that the platform's inline marks can
|
|
6
|
+
* format, each media element becomes a message of its own, and reply buttons become one interactive message.
|
|
7
|
+
*/
|
|
8
|
+
import type { LimitViolation, ModeTypes, Prepared, RenderContext, ResourceRef, SerializeContext } from '@deepseek-ai/cordis-plugin-im-core';
|
|
9
|
+
import type { Element } from '@deepseek-ai/satori-element';
|
|
10
|
+
import type { MediaType, SendMessage } from '../types.ts';
|
|
11
|
+
/** One node a handler produces. */
|
|
12
|
+
export type WhatsappNode = {
|
|
13
|
+
type: 'text';
|
|
14
|
+
text: string;
|
|
15
|
+
} | {
|
|
16
|
+
type: 'media';
|
|
17
|
+
kind: WhatsappMediaTag;
|
|
18
|
+
ref: ResourceRef;
|
|
19
|
+
name?: string;
|
|
20
|
+
} | {
|
|
21
|
+
type: 'button';
|
|
22
|
+
id: string;
|
|
23
|
+
title: string;
|
|
24
|
+
};
|
|
25
|
+
/** The media kinds the vocabulary carries; `file` becomes a `document` message and `sticker` never leaves the platform. */
|
|
26
|
+
export type WhatsappMediaTag = 'image' | 'audio' | 'video' | 'file' | 'sticker';
|
|
27
|
+
/** One platform message, before resource resolution. */
|
|
28
|
+
export type WhatsappDraft = {
|
|
29
|
+
kind: 'text';
|
|
30
|
+
body: string;
|
|
31
|
+
} | {
|
|
32
|
+
kind: 'media';
|
|
33
|
+
type: MediaType;
|
|
34
|
+
ref: ResourceRef;
|
|
35
|
+
name?: string;
|
|
36
|
+
} | {
|
|
37
|
+
kind: 'buttons';
|
|
38
|
+
body: string;
|
|
39
|
+
buttons: {
|
|
40
|
+
id: string;
|
|
41
|
+
title: string;
|
|
42
|
+
}[];
|
|
43
|
+
};
|
|
44
|
+
/** Exact request body of one `POST /{phoneNumberId}/messages`. */
|
|
45
|
+
export type WhatsappPayload = SendMessage;
|
|
46
|
+
/** Mode types of the `text` mode. */
|
|
47
|
+
export interface WhatsappModeTypes extends ModeTypes {
|
|
48
|
+
node: WhatsappNode;
|
|
49
|
+
draft: WhatsappDraft;
|
|
50
|
+
payload: WhatsappPayload;
|
|
51
|
+
}
|
|
52
|
+
/** The platform's documented bounds. */
|
|
53
|
+
export declare const WHATSAPP_LIMITS: {
|
|
54
|
+
/** One text message body: 4,096 characters. */
|
|
55
|
+
readonly text: 4096;
|
|
56
|
+
/** Reply buttons one interactive message accepts. */
|
|
57
|
+
readonly buttons: 3;
|
|
58
|
+
/** One reply button title: 20 characters. */
|
|
59
|
+
readonly buttonTitle: 20;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* The media types the Cloud API accepts, verbatim from the platform's documented list.
|
|
63
|
+
*
|
|
64
|
+
* The upload endpoint answers `100`/`131009` for anything else, so the adapter refuses an unsupported source before it
|
|
65
|
+
* sends a request. `audio/opus` is the one entry the upstream adapter added to the platform list.
|
|
66
|
+
*/
|
|
67
|
+
export declare const SUPPORTED_MEDIA: readonly string[];
|
|
68
|
+
/** Report inline media that moves out of its text run into a message of its own. */
|
|
69
|
+
export declare function reportMovedMedia(el: Element, ctx: RenderContext<WhatsappModeTypes>): void;
|
|
70
|
+
/**
|
|
71
|
+
* Cut text into chunks a text message accepts.
|
|
72
|
+
*
|
|
73
|
+
* Point cuts prefer a paragraph break, then a line break, then a space, then a code-unit boundary that does not split a
|
|
74
|
+
* surrogate pair. The chunks concatenate back to the input.
|
|
75
|
+
*
|
|
76
|
+
* @param text - the text to cut.
|
|
77
|
+
* @param limit - the maximum chunk length in UTF-16 code units.
|
|
78
|
+
* @returns one or more chunks.
|
|
79
|
+
*/
|
|
80
|
+
export declare function splitText(text: string, limit: number): string[];
|
|
81
|
+
/**
|
|
82
|
+
* Fold a node stream into platform messages.
|
|
83
|
+
*
|
|
84
|
+
* Text accumulates into one body; a media element closes the text body that precedes it and becomes a message of its
|
|
85
|
+
* own; buttons become one interactive message per three, sent before the text that follows the last media element, as
|
|
86
|
+
* the platform shows the body on the first group and nothing on the rest.
|
|
87
|
+
*
|
|
88
|
+
* @param nodes - rendered nodes, in document order.
|
|
89
|
+
* @param ctx - the render context, for the split count.
|
|
90
|
+
* @returns one draft per platform message, in send order; never empty.
|
|
91
|
+
*/
|
|
92
|
+
export declare function assembleDraft(nodes: readonly WhatsappNode[], ctx: RenderContext<WhatsappModeTypes>): WhatsappDraft[];
|
|
93
|
+
/**
|
|
94
|
+
* Build the exact request body of one prepared draft.
|
|
95
|
+
*
|
|
96
|
+
* @param prepared - the draft with its resource keys resolved.
|
|
97
|
+
* @param ctx - the send context: target, part index and quoted message.
|
|
98
|
+
* @param linkPreview - whether a text body asks the client for a link preview.
|
|
99
|
+
* @returns the request body.
|
|
100
|
+
*/
|
|
101
|
+
export declare function serializeDraft(prepared: Prepared<WhatsappDraft>, ctx: SerializeContext, linkPreview: boolean): WhatsappPayload;
|
|
102
|
+
/**
|
|
103
|
+
* Hard platform limits of one draft, checked before any request.
|
|
104
|
+
*
|
|
105
|
+
* Text splitting and button grouping already keep the draft inside the character and count bounds; what `assemble`
|
|
106
|
+
* cannot guarantee without changing the content is a button title over 20 characters, which the platform refuses.
|
|
107
|
+
*
|
|
108
|
+
* @param draft - the assembled draft.
|
|
109
|
+
* @returns every violation the platform would refuse.
|
|
110
|
+
*/
|
|
111
|
+
export declare function checkDraft(draft: WhatsappDraft): LimitViolation[];
|
|
112
|
+
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../../src/modes/shared.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EACV,cAAc,EACd,SAAS,EACT,QAAQ,EACR,aAAa,EACb,WAAW,EACX,gBAAgB,EACjB,MAAM,oCAAoC,CAAA;AAE3C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAA;AAC1D,OAAO,KAAK,EAEV,SAAS,EAET,WAAW,EAEZ,MAAM,aAAa,CAAA;AAEpB,mCAAmC;AACnC,MAAM,MAAM,YAAY,GACpB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC9B;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,gBAAgB,CAAC;IAAC,GAAG,EAAE,WAAW,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GAC1E;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAA;AAEjD,2HAA2H;AAC3H,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,CAAA;AAE/E,wDAAwD;AACxD,MAAM,MAAM,aAAa,GACrB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC9B;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,SAAS,CAAC;IAAC,G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