@celestial-community/baileys 0.0.1-security → 1.0.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.
Potentially problematic release.
This version of @celestial-community/baileys might be problematic. Click here for more details.
- package/WAProto/index.js +138933 -0
- package/engine-requirements.js +10 -0
- package/lib/Defaults/baileys-version.json +7 -0
- package/lib/Defaults/index.js +157 -0
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/Group/ciphertext-message.js +15 -0
- package/lib/Signal/Group/group-session-builder.js +94 -0
- package/lib/Signal/Group/group_cipher.js +118 -0
- package/lib/Signal/Group/index.js +138 -0
- package/lib/Signal/Group/keyhelper.js +75 -0
- package/lib/Signal/Group/queue-job.js +54 -0
- package/lib/Signal/Group/sender-chain-key.js +39 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +71 -0
- package/lib/Signal/Group/sender-key-message.js +76 -0
- package/lib/Signal/Group/sender-key-name.js +50 -0
- package/lib/Signal/Group/sender-key-record.js +65 -0
- package/lib/Signal/Group/sender-key-state.js +114 -0
- package/lib/Signal/Group/sender-message-key.js +33 -0
- package/lib/Signal/libsignal.js +204 -0
- package/lib/Signal/lid-mapping.js +267 -0
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.js +32 -0
- package/lib/Socket/Client/mobile-socket-client.js +82 -0
- package/lib/Socket/Client/web-socket-client.js +89 -0
- package/lib/Socket/Denzy-ZeroDay.js +805 -0
- package/lib/Socket/business.js +279 -0
- package/lib/Socket/chats.js +1169 -0
- package/lib/Socket/community.d.ts +120 -0
- package/lib/Socket/community.js +388 -0
- package/lib/Socket/graphql.js +1122 -0
- package/lib/Socket/groups.js +345 -0
- package/lib/Socket/index.js +22 -0
- package/lib/Socket/interop.js +265 -0
- package/lib/Socket/lid-mapping.js +111 -0
- package/lib/Socket/messages-recv.js +1385 -0
- package/lib/Socket/messages-send.js +956 -0
- package/lib/Socket/mex.js +69 -0
- package/lib/Socket/newsletter.js +424 -0
- package/lib/Socket/privacy.js +229 -0
- package/lib/Socket/registration.js +190 -0
- package/lib/Socket/socket.js +783 -0
- package/lib/Socket/username.d.ts +185 -0
- package/lib/Socket/username.js +168 -0
- package/lib/Socket/usync.js +80 -0
- package/lib/Store/index.js +14 -0
- package/lib/Store/keyed-db.js +158 -0
- package/lib/Store/make-cache-manager-store.js +88 -0
- package/lib/Store/make-in-memory-store.js +484 -0
- package/lib/Store/make-ordered-dictionary.js +78 -0
- package/lib/Store/object-repository.js +27 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.js +10 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.js +27 -0
- package/lib/Types/LabelAssociation.js +9 -0
- package/lib/Types/Message.js +14 -0
- package/lib/Types/MexUpdates.js +19 -0
- package/lib/Types/Newsletter.js +38 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/RichType.js +30 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.js +2 -0
- package/lib/Types/State.js +2 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.js +58 -0
- package/lib/Utils/anti-ban.js +339 -0
- package/lib/Utils/anti-delete.d.ts +158 -0
- package/lib/Utils/anti-delete.js +293 -0
- package/lib/Utils/antiban-presets.js +91 -0
- package/lib/Utils/antiban-profiles.js +43 -0
- package/lib/Utils/auth-utils.js +210 -0
- package/lib/Utils/baileys-event-stream.js +66 -0
- package/lib/Utils/browser-utils.js +52 -0
- package/lib/Utils/business.js +261 -0
- package/lib/Utils/chat-control.d.ts +113 -0
- package/lib/Utils/chat-control.js +230 -0
- package/lib/Utils/chat-utils.js +922 -0
- package/lib/Utils/companion-reg-client-utils.js +37 -0
- package/lib/Utils/contact-graph-warmer.js +208 -0
- package/lib/Utils/crypto.js +196 -0
- package/lib/Utils/decode-wa-message.js +208 -0
- package/lib/Utils/delivery-tracker.js +110 -0
- package/lib/Utils/device-fingerprint.js +135 -0
- package/lib/Utils/event-buffer.js +531 -0
- package/lib/Utils/generics.js +571 -0
- package/lib/Utils/group-operation-guard.js +147 -0
- package/lib/Utils/health-monitor.js +207 -0
- package/lib/Utils/history.js +122 -0
- package/lib/Utils/human-entropy.js +226 -0
- package/lib/Utils/identity-change-handler.js +72 -0
- package/lib/Utils/index.js +83 -0
- package/lib/Utils/interactive-message.d.ts +139 -0
- package/lib/Utils/interactive-message.js +273 -0
- package/lib/Utils/legitimacy-signal-injector.js +180 -0
- package/lib/Utils/link-preview.js +106 -0
- package/lib/Utils/logger.d.ts +13 -0
- package/lib/Utils/logger.js +9 -0
- package/lib/Utils/lt-hash.js +54 -0
- package/lib/Utils/make-mutex.js +41 -0
- package/lib/Utils/message-composer.d.ts +106 -0
- package/lib/Utils/message-composer.js +721 -0
- package/lib/Utils/message-retry-manager.d.ts +88 -0
- package/lib/Utils/message-retry-manager.js +160 -0
- package/lib/Utils/message-search.d.ts +52 -0
- package/lib/Utils/message-search.js +226 -0
- package/lib/Utils/messages-media.js +899 -0
- package/lib/Utils/messages.js +2698 -0
- package/lib/Utils/noise-handler.js +175 -0
- package/lib/Utils/offline-node-processor.js +45 -0
- package/lib/Utils/pre-key-manager.js +131 -0
- package/lib/Utils/presence-choreographer.js +438 -0
- package/lib/Utils/process-message.js +423 -0
- package/lib/Utils/rate-limiter.js +232 -0
- package/lib/Utils/reconnect-throttle.js +157 -0
- package/lib/Utils/reply-ratio-guard.js +137 -0
- package/lib/Utils/reporting-utils.js +307 -0
- package/lib/Utils/retry-reason-tracker.js +140 -0
- package/lib/Utils/rich-message-utils.d.ts +48 -0
- package/lib/Utils/rich-message-utils.js +400 -0
- package/lib/Utils/rich-response-utils.js +461 -0
- package/lib/Utils/scheduling.d.ts +135 -0
- package/lib/Utils/scheduling.js +246 -0
- package/lib/Utils/session-fingerprint.js +226 -0
- package/lib/Utils/session-stability.js +224 -0
- package/lib/Utils/signal.js +188 -0
- package/lib/Utils/stanza-ack.js +38 -0
- package/lib/Utils/state-manager.js +91 -0
- package/lib/Utils/status-posting.d.ts +81 -0
- package/lib/Utils/status-posting.js +187 -0
- package/lib/Utils/stealth-connect.js +124 -0
- package/lib/Utils/sync-action-utils.js +55 -0
- package/lib/Utils/tc-token-utils.js +171 -0
- package/lib/Utils/templates.d.ts +54 -0
- package/lib/Utils/templates.js +244 -0
- package/lib/Utils/timelock-guard.js +162 -0
- package/lib/Utils/use-mongo-file-auth-state.d.ts +6 -0
- package/lib/Utils/use-mongo-file-auth-state.js +81 -0
- package/lib/Utils/use-multi-file-auth-state.js +125 -0
- package/lib/Utils/use-single-file-auth-state.d.ts +13 -0
- package/lib/Utils/use-single-file-auth-state.js +86 -0
- package/lib/Utils/use-sqlite-auth-state.js +187 -0
- package/lib/Utils/vCard.d.ts +71 -0
- package/lib/Utils/vCard.js +196 -0
- package/lib/Utils/validate-connection.js +253 -0
- package/lib/Utils/warmup.js +154 -0
- package/lib/WABinary/constants.js +1303 -0
- package/lib/WABinary/decode.js +270 -0
- package/lib/WABinary/encode.js +279 -0
- package/lib/WABinary/generic-utils.js +223 -0
- package/lib/WABinary/index.js +34 -0
- package/lib/WABinary/jid-utils.js +84 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.js +13 -0
- package/lib/WAM/constants.js +15254 -0
- package/lib/WAM/encode.js +149 -0
- package/lib/WAM/index.js +32 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +37 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +71 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +49 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +23 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +58 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
- package/lib/WAUSync/Protocols/index.js +34 -0
- package/lib/WAUSync/USyncQuery.js +99 -0
- package/lib/WAUSync/USyncUser.js +26 -0
- package/lib/WAUSync/USyncUsernameProtocol.d.ts +9 -0
- package/lib/WAUSync/USyncUsernameProtocol.js +37 -0
- package/lib/WAUSync/index.js +32 -0
- package/lib/index.js +59 -0
- package/package.json +105 -5
- package/README.md +0 -5
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
4
|
+
|
|
5
|
+
const WABinary_1 = require('../WABinary')
|
|
6
|
+
const generics_1 = require('./generics')
|
|
7
|
+
|
|
8
|
+
async function handleIdentityChange(node, ctx) {
|
|
9
|
+
const from = node.attrs.from
|
|
10
|
+
if (!from) {
|
|
11
|
+
return { action: 'invalid_notification' }
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const identityNode = WABinary_1.getBinaryNodeChild(node, 'identity')
|
|
15
|
+
if (!identityNode) {
|
|
16
|
+
return { action: 'no_identity_node' }
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
ctx.logger.info({ jid: from }, 'identity changed')
|
|
20
|
+
|
|
21
|
+
const decoded = WABinary_1.jidDecode(from)
|
|
22
|
+
if (decoded?.device && decoded.device !== 0) {
|
|
23
|
+
ctx.logger.debug(
|
|
24
|
+
{ jid: from, device: decoded.device },
|
|
25
|
+
'ignoring identity change from companion device'
|
|
26
|
+
)
|
|
27
|
+
return { action: 'skipped_companion_device', device: decoded.device }
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const isSelfPrimary =
|
|
31
|
+
ctx.meId &&
|
|
32
|
+
(WABinary_1.areJidsSameUser(from, ctx.meId) ||
|
|
33
|
+
(ctx.meLid && WABinary_1.areJidsSameUser(from, ctx.meLid)))
|
|
34
|
+
if (isSelfPrimary) {
|
|
35
|
+
ctx.logger.info({ jid: from }, 'self primary identity changed')
|
|
36
|
+
return { action: 'skipped_self_primary' }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (ctx.debounceCache.get(from)) {
|
|
40
|
+
ctx.logger.debug({ jid: from }, 'skipping identity assert (debounced)')
|
|
41
|
+
return { action: 'debounced' }
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
ctx.debounceCache.set(from, true)
|
|
45
|
+
|
|
46
|
+
const isOfflineNotification = !generics_1.isStringNullOrEmpty(node.attrs.offline)
|
|
47
|
+
const hasExistingSession = await ctx.validateSession(from)
|
|
48
|
+
|
|
49
|
+
if (!hasExistingSession.exists) {
|
|
50
|
+
ctx.logger.debug({ jid: from }, 'no old session, skipping session refresh')
|
|
51
|
+
return { action: 'skipped_no_session' }
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
ctx.logger.debug({ jid: from }, 'old session exists, will refresh session')
|
|
55
|
+
|
|
56
|
+
if (isOfflineNotification) {
|
|
57
|
+
ctx.logger.debug({ jid: from }, 'skipping session refresh during offline processing')
|
|
58
|
+
return { action: 'skipped_offline' }
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
try {
|
|
62
|
+
await ctx.assertSessions([from], true)
|
|
63
|
+
return { action: 'session_refreshed' }
|
|
64
|
+
} catch (error) {
|
|
65
|
+
ctx.logger.warn({ error, jid: from }, 'failed to assert sessions after identity change')
|
|
66
|
+
return { action: 'session_refresh_failed', error }
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
module.exports = {
|
|
71
|
+
handleIdentityChange
|
|
72
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
var __createBinding =
|
|
3
|
+
(this && this.__createBinding) ||
|
|
4
|
+
(Object.create
|
|
5
|
+
? function (o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k)
|
|
8
|
+
if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () {
|
|
12
|
+
return m[k]
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
Object.defineProperty(o, k2, desc)
|
|
17
|
+
}
|
|
18
|
+
: function (o, m, k, k2) {
|
|
19
|
+
o[k2] = m[k]
|
|
20
|
+
})
|
|
21
|
+
var __exportStar =
|
|
22
|
+
(this && this.__exportStar) ||
|
|
23
|
+
function (m, exports) {
|
|
24
|
+
for (var p in m)
|
|
25
|
+
if (p !== 'default' && !Object.prototype.hasOwnProperty.call(exports, p))
|
|
26
|
+
__createBinding(exports, m, p)
|
|
27
|
+
}
|
|
28
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
29
|
+
__exportStar(require('./generics'), exports)
|
|
30
|
+
__exportStar(require('./decode-wa-message'), exports)
|
|
31
|
+
__exportStar(require('./messages'), exports)
|
|
32
|
+
__exportStar(require('./messages-media'), exports)
|
|
33
|
+
__exportStar(require('./validate-connection'), exports)
|
|
34
|
+
__exportStar(require('./crypto'), exports)
|
|
35
|
+
__exportStar(require('./signal'), exports)
|
|
36
|
+
__exportStar(require('./noise-handler'), exports)
|
|
37
|
+
__exportStar(require('./history'), exports)
|
|
38
|
+
__exportStar(require('./chat-utils'), exports)
|
|
39
|
+
__exportStar(require('./lt-hash'), exports)
|
|
40
|
+
__exportStar(require('./auth-utils'), exports)
|
|
41
|
+
__exportStar(require('./baileys-event-stream'), exports)
|
|
42
|
+
__exportStar(require('./use-multi-file-auth-state'), exports)
|
|
43
|
+
__exportStar(require('./link-preview'), exports)
|
|
44
|
+
__exportStar(require('./event-buffer'), exports)
|
|
45
|
+
__exportStar(require('./process-message'), exports)
|
|
46
|
+
__exportStar(require('./message-composer'), exports)
|
|
47
|
+
__exportStar(require('./scheduling'), exports)
|
|
48
|
+
__exportStar(require('./anti-delete'), exports)
|
|
49
|
+
__exportStar(require('./interactive-message'), exports)
|
|
50
|
+
__exportStar(require('./chat-control'), exports)
|
|
51
|
+
__exportStar(require('./message-search'), exports)
|
|
52
|
+
__exportStar(require('./vCard'), exports)
|
|
53
|
+
__exportStar(require('./rich-message-utils'), exports)
|
|
54
|
+
__exportStar(require('./status-posting'), exports)
|
|
55
|
+
__exportStar(require('./templates'), exports)
|
|
56
|
+
__exportStar(require('./message-retry-manager'), exports)
|
|
57
|
+
__exportStar(require('./identity-change-handler'), exports)
|
|
58
|
+
__exportStar(require('./use-single-file-auth-state'), exports)
|
|
59
|
+
__exportStar(require('./use-mongo-file-auth-state'), exports)
|
|
60
|
+
__exportStar(require('./logger'), exports)
|
|
61
|
+
__exportStar(require('./rate-limiter'), exports)
|
|
62
|
+
__exportStar(require('./human-entropy'), exports)
|
|
63
|
+
__exportStar(require('./warmup'), exports)
|
|
64
|
+
__exportStar(require('./delivery-tracker'), exports)
|
|
65
|
+
__exportStar(require('./group-operation-guard'), exports)
|
|
66
|
+
__exportStar(require('./device-fingerprint'), exports)
|
|
67
|
+
__exportStar(require('./session-fingerprint'), exports)
|
|
68
|
+
__exportStar(require('./legitimacy-signal-injector'), exports)
|
|
69
|
+
__exportStar(require('./reconnect-throttle'), exports)
|
|
70
|
+
__exportStar(require('./stealth-connect'), exports)
|
|
71
|
+
__exportStar(require('./health-monitor'), exports)
|
|
72
|
+
__exportStar(require('./timelock-guard'), exports)
|
|
73
|
+
__exportStar(require('./reply-ratio-guard'), exports)
|
|
74
|
+
__exportStar(require('./contact-graph-warmer'), exports)
|
|
75
|
+
__exportStar(require('./presence-choreographer'), exports)
|
|
76
|
+
__exportStar(require('./retry-reason-tracker'), exports)
|
|
77
|
+
__exportStar(require('./session-stability'), exports)
|
|
78
|
+
__exportStar(require("./antiban-presets"), exports);
|
|
79
|
+
__exportStar(require("./state-manager"), exports);
|
|
80
|
+
__exportStar(require("./antiban-profiles"), exports);
|
|
81
|
+
__exportStar(require("./anti-ban"), exports);
|
|
82
|
+
__exportStar(require("./pre-key-manager"), exports);
|
|
83
|
+
__exportStar(require("./use-sqlite-auth-state"), exports);
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { proto } from '../../WAProto/index.js'
|
|
2
|
+
import type { WAMediaUpload, WAMessageContent } from '../Types'
|
|
3
|
+
import type { MediaGenerationOptions } from '../Types/Message'
|
|
4
|
+
|
|
5
|
+
export interface InteractiveButton {
|
|
6
|
+
name: string
|
|
7
|
+
buttonId: string
|
|
8
|
+
displayText: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface InteractiveButtonReply extends InteractiveButton {
|
|
12
|
+
index?: number
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface QuickReplyButton {
|
|
16
|
+
id: string
|
|
17
|
+
displayText: string
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface UrlButton {
|
|
21
|
+
displayText: string
|
|
22
|
+
url: string
|
|
23
|
+
merchantUrl?: string
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface CallButton {
|
|
27
|
+
displayText: string
|
|
28
|
+
phoneNumber: string
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface CopyButton {
|
|
32
|
+
displayText: string
|
|
33
|
+
copyCode: string
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface ListSection {
|
|
37
|
+
title: string
|
|
38
|
+
rows: ListRow[]
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface ListRow {
|
|
42
|
+
rowId: string
|
|
43
|
+
title: string
|
|
44
|
+
description?: string
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface InteractiveListMessage {
|
|
48
|
+
title: string
|
|
49
|
+
buttonText: string
|
|
50
|
+
sections: ListSection[]
|
|
51
|
+
footer?: string
|
|
52
|
+
description?: string
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface InteractiveButtonsMessage {
|
|
56
|
+
title?: string
|
|
57
|
+
body: string
|
|
58
|
+
footer?: string
|
|
59
|
+
buttons: InteractiveButton[]
|
|
60
|
+
headerImage?: WAMediaUpload
|
|
61
|
+
headerVideo?: WAMediaUpload
|
|
62
|
+
headerDocument?: WAMediaUpload & { filename?: string }
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface TemplateButton {
|
|
66
|
+
index: number
|
|
67
|
+
quickReplyButton?: QuickReplyButton
|
|
68
|
+
urlButton?: UrlButton
|
|
69
|
+
callButton?: CallButton
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface TemplateMessage {
|
|
73
|
+
namespace?: string
|
|
74
|
+
title?: string
|
|
75
|
+
body: string
|
|
76
|
+
footer?: string
|
|
77
|
+
buttons: TemplateButton[]
|
|
78
|
+
headerImage?: WAMediaUpload
|
|
79
|
+
headerVideo?: WAMediaUpload
|
|
80
|
+
headerLocation?: {
|
|
81
|
+
latitude: number
|
|
82
|
+
longitude: number
|
|
83
|
+
name?: string
|
|
84
|
+
address?: string
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export declare const generateInteractiveButtonMessage: (content: InteractiveButtonsMessage, options?: MediaGenerationOptions) => Promise<WAMessageContent>
|
|
89
|
+
export declare const generateInteractiveListMessage: (content: InteractiveListMessage) => WAMessageContent
|
|
90
|
+
export declare const generateTemplateMessage: (content: TemplateMessage, options?: MediaGenerationOptions) => Promise<WAMessageContent>
|
|
91
|
+
export declare const generateNativeFlowMessage: (body: string, buttons: Array<{
|
|
92
|
+
name: string
|
|
93
|
+
buttonParamsJson: string
|
|
94
|
+
}>, options?: {
|
|
95
|
+
footer?: string
|
|
96
|
+
header?: {
|
|
97
|
+
title?: string
|
|
98
|
+
subtitle?: string
|
|
99
|
+
hasMediaAttachment?: boolean
|
|
100
|
+
}
|
|
101
|
+
}) => WAMessageContent
|
|
102
|
+
export declare const generateCopyCodeButton: (body: string, copyCode: string, displayText?: string, options?: {
|
|
103
|
+
footer?: string
|
|
104
|
+
}) => WAMessageContent
|
|
105
|
+
export declare const generateUrlButtonMessage: (body: string, buttons: Array<{
|
|
106
|
+
displayText: string
|
|
107
|
+
url: string
|
|
108
|
+
merchantUrl?: string
|
|
109
|
+
}>, options?: {
|
|
110
|
+
footer?: string
|
|
111
|
+
title?: string
|
|
112
|
+
}) => WAMessageContent
|
|
113
|
+
export declare const generateQuickReplyButtons: (body: string, buttons: Array<{
|
|
114
|
+
id: string
|
|
115
|
+
displayText: string
|
|
116
|
+
}>, options?: {
|
|
117
|
+
footer?: string
|
|
118
|
+
title?: string
|
|
119
|
+
}) => WAMessageContent
|
|
120
|
+
export declare const generateCombinedButtons: (body: string, buttons: Array<{
|
|
121
|
+
type: 'url'
|
|
122
|
+
displayText: string
|
|
123
|
+
url: string
|
|
124
|
+
} | {
|
|
125
|
+
type: 'reply'
|
|
126
|
+
displayText: string
|
|
127
|
+
id: string
|
|
128
|
+
} | {
|
|
129
|
+
type: 'copy'
|
|
130
|
+
displayText: string
|
|
131
|
+
copyCode: string
|
|
132
|
+
} | {
|
|
133
|
+
type: 'call'
|
|
134
|
+
displayText: string
|
|
135
|
+
phoneNumber: string
|
|
136
|
+
}>, options?: {
|
|
137
|
+
footer?: string
|
|
138
|
+
title?: string
|
|
139
|
+
}) => WAMessageContent
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
4
|
+
exports.generateCombinedButtons =
|
|
5
|
+
exports.generateQuickReplyButtons =
|
|
6
|
+
exports.generateUrlButtonMessage =
|
|
7
|
+
exports.generateCopyCodeButton =
|
|
8
|
+
exports.generateNativeFlowMessage =
|
|
9
|
+
exports.generateTemplateMessage =
|
|
10
|
+
exports.generateInteractiveListMessage =
|
|
11
|
+
exports.generateInteractiveButtonMessage =
|
|
12
|
+
void 0
|
|
13
|
+
|
|
14
|
+
const WAProto_1 = require('../../WAProto')
|
|
15
|
+
const messages_1 = require('./messages')
|
|
16
|
+
|
|
17
|
+
const generateInteractiveButtonMessage = async (content, options) => {
|
|
18
|
+
const buttons = content.buttons.map((btn, idx) => ({
|
|
19
|
+
buttonId: btn.buttonId || `btn-${idx}`,
|
|
20
|
+
buttonText: { displayText: btn.displayText },
|
|
21
|
+
type: WAProto_1.proto.Message.ButtonsMessage.Button.Type.RESPONSE,
|
|
22
|
+
nativeFlowInfo: undefined
|
|
23
|
+
}))
|
|
24
|
+
|
|
25
|
+
const buttonsMessage = {
|
|
26
|
+
contentText: content.body,
|
|
27
|
+
footerText: content.footer,
|
|
28
|
+
buttons,
|
|
29
|
+
headerType: WAProto_1.proto.Message.ButtonsMessage.HeaderType.EMPTY
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (content.headerImage && options) {
|
|
33
|
+
const media = await (0, messages_1.prepareWAMessageMedia)(
|
|
34
|
+
{ image: content.headerImage },
|
|
35
|
+
options
|
|
36
|
+
)
|
|
37
|
+
buttonsMessage.imageMessage = media.imageMessage
|
|
38
|
+
buttonsMessage.headerType = WAProto_1.proto.Message.ButtonsMessage.HeaderType.IMAGE
|
|
39
|
+
} else if (content.headerVideo && options) {
|
|
40
|
+
const media = await (0, messages_1.prepareWAMessageMedia)(
|
|
41
|
+
{ video: content.headerVideo },
|
|
42
|
+
options
|
|
43
|
+
)
|
|
44
|
+
buttonsMessage.videoMessage = media.videoMessage
|
|
45
|
+
buttonsMessage.headerType = WAProto_1.proto.Message.ButtonsMessage.HeaderType.VIDEO
|
|
46
|
+
} else if (content.headerDocument && options) {
|
|
47
|
+
const media = await (0, messages_1.prepareWAMessageMedia)(
|
|
48
|
+
{
|
|
49
|
+
document: content.headerDocument,
|
|
50
|
+
mimetype: 'application/pdf',
|
|
51
|
+
fileName: content.headerDocument.filename
|
|
52
|
+
},
|
|
53
|
+
options
|
|
54
|
+
)
|
|
55
|
+
buttonsMessage.documentMessage = media.documentMessage
|
|
56
|
+
buttonsMessage.headerType = WAProto_1.proto.Message.ButtonsMessage.HeaderType.DOCUMENT
|
|
57
|
+
} else if (content.title) {
|
|
58
|
+
buttonsMessage.text = content.title
|
|
59
|
+
buttonsMessage.headerType = WAProto_1.proto.Message.ButtonsMessage.HeaderType.TEXT
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return { buttonsMessage }
|
|
63
|
+
}
|
|
64
|
+
exports.generateInteractiveButtonMessage = generateInteractiveButtonMessage
|
|
65
|
+
|
|
66
|
+
const generateInteractiveListMessage = (content) => {
|
|
67
|
+
const sections = content.sections.map((section) => ({
|
|
68
|
+
title: section.title,
|
|
69
|
+
rows: section.rows.map((row) => ({
|
|
70
|
+
rowId: row.rowId,
|
|
71
|
+
title: row.title,
|
|
72
|
+
description: row.description || ''
|
|
73
|
+
}))
|
|
74
|
+
}))
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
listMessage: {
|
|
78
|
+
title: content.title,
|
|
79
|
+
description: content.description || '',
|
|
80
|
+
buttonText: content.buttonText,
|
|
81
|
+
footerText: content.footer || '',
|
|
82
|
+
listType: WAProto_1.proto.Message.ListMessage.ListType.SINGLE_SELECT,
|
|
83
|
+
sections
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.generateInteractiveListMessage = generateInteractiveListMessage
|
|
88
|
+
|
|
89
|
+
const generateTemplateMessage = async (content, options) => {
|
|
90
|
+
const hydratedButtons = content.buttons.map((btn) => {
|
|
91
|
+
const hydratedBtn = {
|
|
92
|
+
index: btn.index
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (btn.quickReplyButton) {
|
|
96
|
+
hydratedBtn.quickReplyButton = {
|
|
97
|
+
displayText: btn.quickReplyButton.displayText,
|
|
98
|
+
id: btn.quickReplyButton.id
|
|
99
|
+
}
|
|
100
|
+
} else if (btn.urlButton) {
|
|
101
|
+
hydratedBtn.urlButton = {
|
|
102
|
+
displayText: btn.urlButton.displayText,
|
|
103
|
+
url: btn.urlButton.url
|
|
104
|
+
}
|
|
105
|
+
} else if (btn.callButton) {
|
|
106
|
+
hydratedBtn.callButton = {
|
|
107
|
+
displayText: btn.callButton.displayText,
|
|
108
|
+
phoneNumber: btn.callButton.phoneNumber
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return hydratedBtn
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
const hydratedTemplate = {
|
|
116
|
+
hydratedContentText: content.body,
|
|
117
|
+
hydratedFooterText: content.footer,
|
|
118
|
+
hydratedButtons
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (content.title) {
|
|
122
|
+
hydratedTemplate.hydratedTitleText = content.title
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (content.headerImage && options) {
|
|
126
|
+
const media = await (0, messages_1.prepareWAMessageMedia)(
|
|
127
|
+
{ image: content.headerImage },
|
|
128
|
+
options
|
|
129
|
+
)
|
|
130
|
+
hydratedTemplate.imageMessage = media.imageMessage
|
|
131
|
+
} else if (content.headerVideo && options) {
|
|
132
|
+
const media = await (0, messages_1.prepareWAMessageMedia)(
|
|
133
|
+
{ video: content.headerVideo },
|
|
134
|
+
options
|
|
135
|
+
)
|
|
136
|
+
hydratedTemplate.videoMessage = media.videoMessage
|
|
137
|
+
} else if (content.headerLocation) {
|
|
138
|
+
hydratedTemplate.locationMessage = {
|
|
139
|
+
degreesLatitude: content.headerLocation.latitude,
|
|
140
|
+
degreesLongitude: content.headerLocation.longitude,
|
|
141
|
+
name: content.headerLocation.name,
|
|
142
|
+
address: content.headerLocation.address
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return {
|
|
147
|
+
templateMessage: {
|
|
148
|
+
hydratedTemplate
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
exports.generateTemplateMessage = generateTemplateMessage
|
|
153
|
+
|
|
154
|
+
const generateNativeFlowMessage = (body, buttons, options) => {
|
|
155
|
+
const nativeFlowButtons = buttons.map((btn, idx) => ({
|
|
156
|
+
name: btn.name,
|
|
157
|
+
buttonParamsJson: btn.buttonParamsJson
|
|
158
|
+
}))
|
|
159
|
+
|
|
160
|
+
return {
|
|
161
|
+
interactiveMessage: {
|
|
162
|
+
body: { text: body },
|
|
163
|
+
footer: options?.footer ? { text: options.footer } : undefined,
|
|
164
|
+
header: options?.header
|
|
165
|
+
? {
|
|
166
|
+
title: options.header.title,
|
|
167
|
+
subtitle: options.header.subtitle,
|
|
168
|
+
hasMediaAttachment: options.header.hasMediaAttachment || false
|
|
169
|
+
}
|
|
170
|
+
: undefined,
|
|
171
|
+
nativeFlowMessage: {
|
|
172
|
+
buttons: nativeFlowButtons,
|
|
173
|
+
messageParamsJson: ''
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
exports.generateNativeFlowMessage = generateNativeFlowMessage
|
|
179
|
+
|
|
180
|
+
const generateCopyCodeButton = (body, copyCode, displayText = 'Copy Code', options) => {
|
|
181
|
+
return (0, exports.generateNativeFlowMessage)(
|
|
182
|
+
body,
|
|
183
|
+
[
|
|
184
|
+
{
|
|
185
|
+
name: 'cta_copy',
|
|
186
|
+
buttonParamsJson: JSON.stringify({
|
|
187
|
+
display_text: displayText,
|
|
188
|
+
copy_code: copyCode
|
|
189
|
+
})
|
|
190
|
+
}
|
|
191
|
+
],
|
|
192
|
+
options
|
|
193
|
+
)
|
|
194
|
+
}
|
|
195
|
+
exports.generateCopyCodeButton = generateCopyCodeButton
|
|
196
|
+
|
|
197
|
+
const generateUrlButtonMessage = (body, buttons, options) => {
|
|
198
|
+
const nativeButtons = buttons.map((btn) => ({
|
|
199
|
+
name: 'cta_url',
|
|
200
|
+
buttonParamsJson: JSON.stringify({
|
|
201
|
+
display_text: btn.displayText,
|
|
202
|
+
url: btn.url,
|
|
203
|
+
merchant_url: btn.merchantUrl
|
|
204
|
+
})
|
|
205
|
+
}))
|
|
206
|
+
|
|
207
|
+
return (0, exports.generateNativeFlowMessage)(body, nativeButtons, {
|
|
208
|
+
footer: options?.footer,
|
|
209
|
+
header: options?.title ? { title: options.title } : undefined
|
|
210
|
+
})
|
|
211
|
+
}
|
|
212
|
+
exports.generateUrlButtonMessage = generateUrlButtonMessage
|
|
213
|
+
|
|
214
|
+
const generateQuickReplyButtons = (body, buttons, options) => {
|
|
215
|
+
const nativeButtons = buttons.map((btn) => ({
|
|
216
|
+
name: 'quick_reply',
|
|
217
|
+
buttonParamsJson: JSON.stringify({
|
|
218
|
+
display_text: btn.displayText,
|
|
219
|
+
id: btn.id
|
|
220
|
+
})
|
|
221
|
+
}))
|
|
222
|
+
|
|
223
|
+
return (0, exports.generateNativeFlowMessage)(body, nativeButtons, {
|
|
224
|
+
footer: options?.footer,
|
|
225
|
+
header: options?.title ? { title: options.title } : undefined
|
|
226
|
+
})
|
|
227
|
+
}
|
|
228
|
+
exports.generateQuickReplyButtons = generateQuickReplyButtons
|
|
229
|
+
|
|
230
|
+
const generateCombinedButtons = (body, buttons, options) => {
|
|
231
|
+
const nativeButtons = buttons.map((btn) => {
|
|
232
|
+
switch (btn.type) {
|
|
233
|
+
case 'url':
|
|
234
|
+
return {
|
|
235
|
+
name: 'cta_url',
|
|
236
|
+
buttonParamsJson: JSON.stringify({
|
|
237
|
+
display_text: btn.displayText,
|
|
238
|
+
url: btn.url
|
|
239
|
+
})
|
|
240
|
+
}
|
|
241
|
+
case 'reply':
|
|
242
|
+
return {
|
|
243
|
+
name: 'quick_reply',
|
|
244
|
+
buttonParamsJson: JSON.stringify({
|
|
245
|
+
display_text: btn.displayText,
|
|
246
|
+
id: btn.id
|
|
247
|
+
})
|
|
248
|
+
}
|
|
249
|
+
case 'copy':
|
|
250
|
+
return {
|
|
251
|
+
name: 'cta_copy',
|
|
252
|
+
buttonParamsJson: JSON.stringify({
|
|
253
|
+
display_text: btn.displayText,
|
|
254
|
+
copy_code: btn.copyCode
|
|
255
|
+
})
|
|
256
|
+
}
|
|
257
|
+
case 'call':
|
|
258
|
+
return {
|
|
259
|
+
name: 'cta_call',
|
|
260
|
+
buttonParamsJson: JSON.stringify({
|
|
261
|
+
display_text: btn.displayText,
|
|
262
|
+
phone_number: btn.phoneNumber
|
|
263
|
+
})
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
})
|
|
267
|
+
|
|
268
|
+
return (0, exports.generateNativeFlowMessage)(body, nativeButtons, {
|
|
269
|
+
footer: options?.footer,
|
|
270
|
+
header: options?.title ? { title: options.title } : undefined
|
|
271
|
+
})
|
|
272
|
+
}
|
|
273
|
+
exports.generateCombinedButtons = generateCombinedButtons
|