@sixcore/baileys 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.
- package/LICENSE +21 -0
- package/README.md +606 -0
- package/WAProto/GenerateStatics.sh +4 -0
- package/WAProto/WAProto.proto +4357 -0
- package/WAProto/index.d.ts +50383 -0
- package/WAProto/index.js +155693 -0
- package/WASignalGroup/GroupProtocol.js +1697 -0
- package/WASignalGroup/ciphertext_message.js +16 -0
- package/WASignalGroup/generate-proto.sh +1 -0
- package/WASignalGroup/group.proto +42 -0
- package/WASignalGroup/group_cipher.js +120 -0
- package/WASignalGroup/group_session_builder.js +46 -0
- package/WASignalGroup/index.js +5 -0
- package/WASignalGroup/keyhelper.js +21 -0
- package/WASignalGroup/protobufs.js +3 -0
- package/WASignalGroup/queue_job.js +69 -0
- package/WASignalGroup/sender_chain_key.js +50 -0
- package/WASignalGroup/sender_key_distribution_message.js +78 -0
- package/WASignalGroup/sender_key_message.js +92 -0
- package/WASignalGroup/sender_key_name.js +70 -0
- package/WASignalGroup/sender_key_record.js +56 -0
- package/WASignalGroup/sender_key_state.js +129 -0
- package/WASignalGroup/sender_message_key.js +39 -0
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.d.ts +53 -0
- package/lib/Defaults/index.js +108 -0
- package/lib/Signal/libsignal.d.ts +3 -0
- package/lib/Signal/libsignal.js +152 -0
- package/lib/Socket/Client/abstract-socket-client.d.ts +17 -0
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/index.js +19 -0
- package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/web-socket-client.d.ts +12 -0
- package/lib/Socket/Client/web-socket-client.js +62 -0
- package/lib/Socket/business.d.ts +170 -0
- package/lib/Socket/business.js +260 -0
- package/lib/Socket/chats.d.ts +81 -0
- package/lib/Socket/chats.js +950 -0
- package/lib/Socket/groups.d.ts +115 -0
- package/lib/Socket/groups.js +315 -0
- package/lib/Socket/index.d.ts +172 -0
- package/lib/Socket/index.js +10 -0
- package/lib/Socket/messages-recv.d.ts +158 -0
- package/lib/Socket/messages-recv.js +972 -0
- package/lib/Socket/messages-send.d.ts +155 -0
- package/lib/Socket/messages-send.js +1087 -0
- package/lib/Socket/newsletter.d.ts +132 -0
- package/lib/Socket/newsletter.js +236 -0
- package/lib/Socket/registration.d.ts +264 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +44 -0
- package/lib/Socket/socket.js +643 -0
- package/lib/Socket/usync.d.ts +37 -0
- package/lib/Socket/usync.js +70 -0
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/index.js +10 -0
- package/lib/Store/make-cache-manager-store.d.ts +14 -0
- package/lib/Store/make-cache-manager-store.js +83 -0
- package/lib/Store/make-in-memory-store.d.ts +118 -0
- package/lib/Store/make-in-memory-store.js +431 -0
- package/lib/Store/make-ordered-dictionary.d.ts +13 -0
- package/lib/Store/make-ordered-dictionary.js +81 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Store/object-repository.js +27 -0
- package/lib/Types/Auth.d.ts +109 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Call.d.ts +13 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.d.ts +107 -0
- package/lib/Types/Chat.js +4 -0
- package/lib/Types/Contact.d.ts +19 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.d.ts +172 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/GroupMetadata.d.ts +56 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.d.ts +46 -0
- package/lib/Types/Label.js +27 -0
- package/lib/Types/LabelAssociation.d.ts +29 -0
- package/lib/Types/LabelAssociation.js +9 -0
- package/lib/Types/Message.d.ts +433 -0
- package/lib/Types/Message.js +9 -0
- package/lib/Types/Newsletter.d.ts +92 -0
- package/lib/Types/Newsletter.js +32 -0
- package/lib/Types/Product.d.ts +78 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Signal.d.ts +57 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.d.ts +116 -0
- package/lib/Types/Socket.js +2 -0
- package/lib/Types/State.d.ts +27 -0
- package/lib/Types/State.js +2 -0
- package/lib/Types/USync.d.ts +25 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.d.ts +66 -0
- package/lib/Types/index.js +42 -0
- package/lib/Utils/auth-utils.d.ts +18 -0
- package/lib/Utils/auth-utils.js +227 -0
- package/lib/Utils/baileys-event-stream.d.ts +16 -0
- package/lib/Utils/baileys-event-stream.js +63 -0
- package/lib/Utils/business.d.ts +22 -0
- package/lib/Utils/business.js +234 -0
- package/lib/Utils/chat-utils.d.ts +70 -0
- package/lib/Utils/chat-utils.js +745 -0
- package/lib/Utils/crypto.d.ts +40 -0
- package/lib/Utils/crypto.js +199 -0
- package/lib/Utils/decode-wa-message.d.ts +36 -0
- package/lib/Utils/decode-wa-message.js +234 -0
- package/lib/Utils/event-buffer.d.ts +35 -0
- package/lib/Utils/event-buffer.js +517 -0
- package/lib/Utils/generics.d.ts +88 -0
- package/lib/Utils/generics.js +402 -0
- package/lib/Utils/history.d.ts +19 -0
- package/lib/Utils/history.js +94 -0
- package/lib/Utils/index.d.ts +17 -0
- package/lib/Utils/index.js +33 -0
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/link-preview.js +93 -0
- package/lib/Utils/logger.d.ts +2 -0
- package/lib/Utils/logger.js +7 -0
- package/lib/Utils/lt-hash.d.ts +12 -0
- package/lib/Utils/lt-hash.js +51 -0
- package/lib/Utils/make-mutex.d.ts +7 -0
- package/lib/Utils/make-mutex.js +43 -0
- package/lib/Utils/messages-media.d.ts +113 -0
- package/lib/Utils/messages-media.js +643 -0
- package/lib/Utils/messages.d.ts +77 -0
- package/lib/Utils/messages.js +1221 -0
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/noise-handler.js +160 -0
- package/lib/Utils/process-message.d.ts +41 -0
- package/lib/Utils/process-message.js +373 -0
- package/lib/Utils/signal.d.ts +33 -0
- package/lib/Utils/signal.js +159 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +12 -0
- package/lib/Utils/use-multi-file-auth-state.js +295 -0
- package/lib/Utils/use-single-file-auth-state.d.ts +12 -0
- package/lib/Utils/use-single-file-auth-state.js +75 -0
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/lib/Utils/validate-connection.js +205 -0
- package/lib/WABinary/constants.d.ts +27 -0
- package/lib/WABinary/constants.js +40 -0
- package/lib/WABinary/decode.d.ts +6 -0
- package/lib/WABinary/decode.js +264 -0
- package/lib/WABinary/encode.d.ts +2 -0
- package/lib/WABinary/encode.js +252 -0
- package/lib/WABinary/generic-utils.d.ts +14 -0
- package/lib/WABinary/generic-utils.js +110 -0
- package/lib/WABinary/index.d.ts +5 -0
- package/lib/WABinary/index.js +21 -0
- package/lib/WABinary/jid-utils.d.ts +31 -0
- package/lib/WABinary/jid-utils.js +62 -0
- package/lib/WABinary/types.d.ts +18 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.d.ts +8 -0
- package/lib/WAM/BinaryInfo.js +13 -0
- package/lib/WAM/constants.d.ts +38 -0
- package/lib/WAM/constants.js +15350 -0
- package/lib/WAM/encode.d.ts +2 -0
- package/lib/WAM/encode.js +155 -0
- package/lib/WAM/index.d.ts +3 -0
- package/lib/WAM/index.js +19 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +8 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
- package/lib/WAUSync/Protocols/index.d.ts +4 -0
- package/lib/WAUSync/Protocols/index.js +20 -0
- package/lib/WAUSync/USyncQuery.d.ts +28 -0
- package/lib/WAUSync/USyncQuery.js +89 -0
- package/lib/WAUSync/USyncUser.d.ts +10 -0
- package/lib/WAUSync/USyncUser.js +26 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/WAUSync/index.js +19 -0
- package/lib/index.js +31 -0
- package/package.json +51 -0
- package/src/Defaults/baileys-version.json +3 -0
- package/src/Defaults/index.ts +133 -0
- package/src/Signal/Group/ciphertext-message.ts +9 -0
- package/src/Signal/Group/group-session-builder.ts +56 -0
- package/src/Signal/Group/group_cipher.ts +117 -0
- package/src/Signal/Group/index.ts +11 -0
- package/src/Signal/Group/keyhelper.ts +28 -0
- package/src/Signal/Group/sender-chain-key.ts +34 -0
- package/src/Signal/Group/sender-key-distribution-message.ts +95 -0
- package/src/Signal/Group/sender-key-message.ts +96 -0
- package/src/Signal/Group/sender-key-name.ts +66 -0
- package/src/Signal/Group/sender-key-record.ts +69 -0
- package/src/Signal/Group/sender-key-state.ts +134 -0
- package/src/Signal/Group/sender-message-key.ts +36 -0
- package/src/Signal/libsignal.ts +447 -0
- package/src/Signal/lid-mapping.ts +209 -0
- package/src/Socket/Client/index.ts +2 -0
- package/src/Socket/Client/types.ts +22 -0
- package/src/Socket/Client/websocket.ts +56 -0
- package/src/Socket/business.ts +421 -0
- package/src/Socket/chats.ts +1223 -0
- package/src/Socket/communities.ts +477 -0
- package/src/Socket/groups.ts +361 -0
- package/src/Socket/index.ts +22 -0
- package/src/Socket/messages-recv.ts +1563 -0
- package/src/Socket/messages-send.ts +1210 -0
- package/src/Socket/mex.ts +58 -0
- package/src/Socket/newsletter.ts +229 -0
- package/src/Socket/socket.ts +1072 -0
- package/src/Types/Auth.ts +115 -0
- package/src/Types/Bussines.ts +20 -0
- package/src/Types/Call.ts +14 -0
- package/src/Types/Chat.ts +138 -0
- package/src/Types/Contact.ts +24 -0
- package/src/Types/Events.ts +132 -0
- package/src/Types/GroupMetadata.ts +70 -0
- package/src/Types/Label.ts +48 -0
- package/src/Types/LabelAssociation.ts +35 -0
- package/src/Types/Message.ts +424 -0
- package/src/Types/Newsletter.ts +98 -0
- package/src/Types/Product.ts +85 -0
- package/src/Types/Signal.ts +76 -0
- package/src/Types/Socket.ts +150 -0
- package/src/Types/State.ts +43 -0
- package/src/Types/USync.ts +27 -0
- package/src/Types/globals.d.ts +8 -0
- package/src/Types/index.ts +67 -0
- package/src/Utils/auth-utils.ts +331 -0
- package/src/Utils/browser-utils.ts +31 -0
- package/src/Utils/business.ts +286 -0
- package/src/Utils/chat-utils.ts +933 -0
- package/src/Utils/crypto.ts +184 -0
- package/src/Utils/decode-wa-message.ts +355 -0
- package/src/Utils/event-buffer.ts +662 -0
- package/src/Utils/generics.ts +470 -0
- package/src/Utils/history.ts +114 -0
- package/src/Utils/index.ts +18 -0
- package/src/Utils/link-preview.ts +111 -0
- package/src/Utils/logger.ts +13 -0
- package/src/Utils/lt-hash.ts +65 -0
- package/src/Utils/make-mutex.ts +45 -0
- package/src/Utils/message-retry-manager.ts +229 -0
- package/src/Utils/messages-media.ts +820 -0
- package/src/Utils/messages.ts +1137 -0
- package/src/Utils/noise-handler.ts +192 -0
- package/src/Utils/pre-key-manager.ts +126 -0
- package/src/Utils/process-message.ts +622 -0
- package/src/Utils/signal.ts +214 -0
- package/src/Utils/use-multi-file-auth-state.ts +136 -0
- package/src/Utils/validate-connection.ts +253 -0
- package/src/WABinary/constants.ts +1305 -0
- package/src/WABinary/decode.ts +281 -0
- package/src/WABinary/encode.ts +253 -0
- package/src/WABinary/generic-utils.ts +127 -0
- package/src/WABinary/index.ts +5 -0
- package/src/WABinary/jid-utils.ts +128 -0
- package/src/WABinary/types.ts +17 -0
- package/src/WAM/BinaryInfo.ts +12 -0
- package/src/WAM/constants.ts +22889 -0
- package/src/WAM/encode.ts +169 -0
- package/src/WAM/index.ts +3 -0
- package/src/WAUSync/Protocols/USyncContactProtocol.ts +32 -0
- package/src/WAUSync/Protocols/USyncDeviceProtocol.ts +78 -0
- package/src/WAUSync/Protocols/USyncDisappearingModeProtocol.ts +35 -0
- package/src/WAUSync/Protocols/USyncStatusProtocol.ts +44 -0
- package/src/WAUSync/Protocols/UsyncBotProfileProtocol.ts +76 -0
- package/src/WAUSync/Protocols/UsyncLIDProtocol.ts +33 -0
- package/src/WAUSync/Protocols/index.ts +4 -0
- package/src/WAUSync/USyncQuery.ts +133 -0
- package/src/WAUSync/USyncUser.ts +32 -0
- package/src/WAUSync/index.ts +3 -0
- package/src/index.ts +13 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import WebSocket from 'ws'
|
|
2
|
+
import { DEFAULT_ORIGIN } from '../../Defaults'
|
|
3
|
+
import { AbstractSocketClient } from './types'
|
|
4
|
+
|
|
5
|
+
export class WebSocketClient extends AbstractSocketClient {
|
|
6
|
+
protected socket: WebSocket | null = null
|
|
7
|
+
|
|
8
|
+
get isOpen(): boolean {
|
|
9
|
+
return this.socket?.readyState === WebSocket.OPEN
|
|
10
|
+
}
|
|
11
|
+
get isClosed(): boolean {
|
|
12
|
+
return this.socket === null || this.socket?.readyState === WebSocket.CLOSED
|
|
13
|
+
}
|
|
14
|
+
get isClosing(): boolean {
|
|
15
|
+
return this.socket === null || this.socket?.readyState === WebSocket.CLOSING
|
|
16
|
+
}
|
|
17
|
+
get isConnecting(): boolean {
|
|
18
|
+
return this.socket?.readyState === WebSocket.CONNECTING
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
connect() {
|
|
22
|
+
if (this.socket) {
|
|
23
|
+
return
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
this.socket = new WebSocket(this.url, {
|
|
27
|
+
origin: DEFAULT_ORIGIN,
|
|
28
|
+
headers: this.config.options?.headers as {},
|
|
29
|
+
handshakeTimeout: this.config.connectTimeoutMs,
|
|
30
|
+
timeout: this.config.connectTimeoutMs,
|
|
31
|
+
agent: this.config.agent
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
this.socket.setMaxListeners(0)
|
|
35
|
+
|
|
36
|
+
const events = ['close', 'error', 'upgrade', 'message', 'open', 'ping', 'pong', 'unexpected-response']
|
|
37
|
+
|
|
38
|
+
for (const event of events) {
|
|
39
|
+
this.socket?.on(event, (...args: any[]) => this.emit(event, ...args))
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
close() {
|
|
44
|
+
if (!this.socket) {
|
|
45
|
+
return
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
this.socket.close()
|
|
49
|
+
this.socket = null
|
|
50
|
+
}
|
|
51
|
+
send(str: string | Uint8Array, cb?: (err?: Error) => void): boolean {
|
|
52
|
+
this.socket?.send(str, cb)
|
|
53
|
+
|
|
54
|
+
return Boolean(this.socket)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
import type { GetCatalogOptions, ProductCreate, ProductUpdate, SocketConfig, WAMediaUpload } from '../Types'
|
|
2
|
+
import type { UpdateBussinesProfileProps } from '../Types/Bussines'
|
|
3
|
+
import { getRawMediaUploadData } from '../Utils'
|
|
4
|
+
import {
|
|
5
|
+
parseCatalogNode,
|
|
6
|
+
parseCollectionsNode,
|
|
7
|
+
parseOrderDetailsNode,
|
|
8
|
+
parseProductNode,
|
|
9
|
+
toProductNode,
|
|
10
|
+
uploadingNecessaryImagesOfProduct
|
|
11
|
+
} from '../Utils/business'
|
|
12
|
+
import { type BinaryNode, jidNormalizedUser, S_WHATSAPP_NET } from '../WABinary'
|
|
13
|
+
import { getBinaryNodeChild } from '../WABinary/generic-utils'
|
|
14
|
+
import { makeMessagesRecvSocket } from './messages-recv'
|
|
15
|
+
|
|
16
|
+
export const makeBusinessSocket = (config: SocketConfig) => {
|
|
17
|
+
const sock = makeMessagesRecvSocket(config)
|
|
18
|
+
const { authState, query, waUploadToServer } = sock
|
|
19
|
+
|
|
20
|
+
const updateBussinesProfile = async (args: UpdateBussinesProfileProps) => {
|
|
21
|
+
const node: BinaryNode[] = []
|
|
22
|
+
const simpleFields: (keyof UpdateBussinesProfileProps)[] = ['address', 'email', 'description']
|
|
23
|
+
|
|
24
|
+
node.push(
|
|
25
|
+
...simpleFields
|
|
26
|
+
.filter(key => args[key])
|
|
27
|
+
.map(key => ({
|
|
28
|
+
tag: key,
|
|
29
|
+
attrs: {},
|
|
30
|
+
content: args[key] as string
|
|
31
|
+
}))
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
if (args.websites) {
|
|
35
|
+
node.push(
|
|
36
|
+
...args.websites.map(website => ({
|
|
37
|
+
tag: 'website',
|
|
38
|
+
attrs: {},
|
|
39
|
+
content: website
|
|
40
|
+
}))
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (args.hours) {
|
|
45
|
+
node.push({
|
|
46
|
+
tag: 'business_hours',
|
|
47
|
+
attrs: { timezone: args.hours.timezone },
|
|
48
|
+
content: args.hours.days.map(config => {
|
|
49
|
+
const base = {
|
|
50
|
+
tag: 'business_hours_config',
|
|
51
|
+
attrs: { day_of_week: config.day, mode: config.mode }
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (config.mode === 'specific_hours') {
|
|
55
|
+
return {
|
|
56
|
+
...base,
|
|
57
|
+
attrs: {
|
|
58
|
+
...base.attrs,
|
|
59
|
+
open_time: config.openTimeInMinutes,
|
|
60
|
+
close_time: config.closeTimeInMinutes
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return base
|
|
66
|
+
})
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const result = await query({
|
|
71
|
+
tag: 'iq',
|
|
72
|
+
attrs: {
|
|
73
|
+
to: S_WHATSAPP_NET,
|
|
74
|
+
type: 'set',
|
|
75
|
+
xmlns: 'w:biz'
|
|
76
|
+
},
|
|
77
|
+
content: [
|
|
78
|
+
{
|
|
79
|
+
tag: 'business_profile',
|
|
80
|
+
attrs: {
|
|
81
|
+
v: '3',
|
|
82
|
+
mutation_type: 'delta'
|
|
83
|
+
},
|
|
84
|
+
content: node
|
|
85
|
+
}
|
|
86
|
+
]
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
return result
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const updateCoverPhoto = async (photo: WAMediaUpload) => {
|
|
93
|
+
const { fileSha256, filePath } = await getRawMediaUploadData(photo, 'biz-cover-photo')
|
|
94
|
+
const fileSha256B64 = fileSha256.toString('base64')
|
|
95
|
+
|
|
96
|
+
const { meta_hmac, fbid, ts } = await waUploadToServer(filePath, {
|
|
97
|
+
fileEncSha256B64: fileSha256B64,
|
|
98
|
+
mediaType: 'biz-cover-photo'
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
await query({
|
|
102
|
+
tag: 'iq',
|
|
103
|
+
attrs: {
|
|
104
|
+
to: S_WHATSAPP_NET,
|
|
105
|
+
type: 'set',
|
|
106
|
+
xmlns: 'w:biz'
|
|
107
|
+
},
|
|
108
|
+
content: [
|
|
109
|
+
{
|
|
110
|
+
tag: 'business_profile',
|
|
111
|
+
attrs: {
|
|
112
|
+
v: '3',
|
|
113
|
+
mutation_type: 'delta'
|
|
114
|
+
},
|
|
115
|
+
content: [
|
|
116
|
+
{
|
|
117
|
+
tag: 'cover_photo',
|
|
118
|
+
attrs: { id: String(fbid), op: 'update', token: meta_hmac!, ts: String(ts) }
|
|
119
|
+
}
|
|
120
|
+
]
|
|
121
|
+
}
|
|
122
|
+
]
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
return fbid!
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const removeCoverPhoto = async (id: string) => {
|
|
129
|
+
return await query({
|
|
130
|
+
tag: 'iq',
|
|
131
|
+
attrs: {
|
|
132
|
+
to: S_WHATSAPP_NET,
|
|
133
|
+
type: 'set',
|
|
134
|
+
xmlns: 'w:biz'
|
|
135
|
+
},
|
|
136
|
+
content: [
|
|
137
|
+
{
|
|
138
|
+
tag: 'business_profile',
|
|
139
|
+
attrs: {
|
|
140
|
+
v: '3',
|
|
141
|
+
mutation_type: 'delta'
|
|
142
|
+
},
|
|
143
|
+
content: [
|
|
144
|
+
{
|
|
145
|
+
tag: 'cover_photo',
|
|
146
|
+
attrs: { op: 'delete', id }
|
|
147
|
+
}
|
|
148
|
+
]
|
|
149
|
+
}
|
|
150
|
+
]
|
|
151
|
+
})
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const getCatalog = async ({ jid, limit, cursor }: GetCatalogOptions) => {
|
|
155
|
+
jid = jid || authState.creds.me?.id
|
|
156
|
+
jid = jidNormalizedUser(jid)
|
|
157
|
+
|
|
158
|
+
const queryParamNodes: BinaryNode[] = [
|
|
159
|
+
{
|
|
160
|
+
tag: 'limit',
|
|
161
|
+
attrs: {},
|
|
162
|
+
content: Buffer.from((limit || 10).toString())
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
tag: 'width',
|
|
166
|
+
attrs: {},
|
|
167
|
+
content: Buffer.from('100')
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
tag: 'height',
|
|
171
|
+
attrs: {},
|
|
172
|
+
content: Buffer.from('100')
|
|
173
|
+
}
|
|
174
|
+
]
|
|
175
|
+
|
|
176
|
+
if (cursor) {
|
|
177
|
+
queryParamNodes.push({
|
|
178
|
+
tag: 'after',
|
|
179
|
+
attrs: {},
|
|
180
|
+
content: cursor
|
|
181
|
+
})
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const result = await query({
|
|
185
|
+
tag: 'iq',
|
|
186
|
+
attrs: {
|
|
187
|
+
to: S_WHATSAPP_NET,
|
|
188
|
+
type: 'get',
|
|
189
|
+
xmlns: 'w:biz:catalog'
|
|
190
|
+
},
|
|
191
|
+
content: [
|
|
192
|
+
{
|
|
193
|
+
tag: 'product_catalog',
|
|
194
|
+
attrs: {
|
|
195
|
+
jid,
|
|
196
|
+
allow_shop_source: 'true'
|
|
197
|
+
},
|
|
198
|
+
content: queryParamNodes
|
|
199
|
+
}
|
|
200
|
+
]
|
|
201
|
+
})
|
|
202
|
+
return parseCatalogNode(result)
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const getCollections = async (jid?: string, limit = 51) => {
|
|
206
|
+
jid = jid || authState.creds.me?.id
|
|
207
|
+
jid = jidNormalizedUser(jid)
|
|
208
|
+
const result = await query({
|
|
209
|
+
tag: 'iq',
|
|
210
|
+
attrs: {
|
|
211
|
+
to: S_WHATSAPP_NET,
|
|
212
|
+
type: 'get',
|
|
213
|
+
xmlns: 'w:biz:catalog',
|
|
214
|
+
smax_id: '35'
|
|
215
|
+
},
|
|
216
|
+
content: [
|
|
217
|
+
{
|
|
218
|
+
tag: 'collections',
|
|
219
|
+
attrs: {
|
|
220
|
+
biz_jid: jid
|
|
221
|
+
},
|
|
222
|
+
content: [
|
|
223
|
+
{
|
|
224
|
+
tag: 'collection_limit',
|
|
225
|
+
attrs: {},
|
|
226
|
+
content: Buffer.from(limit.toString())
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
tag: 'item_limit',
|
|
230
|
+
attrs: {},
|
|
231
|
+
content: Buffer.from(limit.toString())
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
tag: 'width',
|
|
235
|
+
attrs: {},
|
|
236
|
+
content: Buffer.from('100')
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
tag: 'height',
|
|
240
|
+
attrs: {},
|
|
241
|
+
content: Buffer.from('100')
|
|
242
|
+
}
|
|
243
|
+
]
|
|
244
|
+
}
|
|
245
|
+
]
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
return parseCollectionsNode(result)
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const getOrderDetails = async (orderId: string, tokenBase64: string) => {
|
|
252
|
+
const result = await query({
|
|
253
|
+
tag: 'iq',
|
|
254
|
+
attrs: {
|
|
255
|
+
to: S_WHATSAPP_NET,
|
|
256
|
+
type: 'get',
|
|
257
|
+
xmlns: 'fb:thrift_iq',
|
|
258
|
+
smax_id: '5'
|
|
259
|
+
},
|
|
260
|
+
content: [
|
|
261
|
+
{
|
|
262
|
+
tag: 'order',
|
|
263
|
+
attrs: {
|
|
264
|
+
op: 'get',
|
|
265
|
+
id: orderId
|
|
266
|
+
},
|
|
267
|
+
content: [
|
|
268
|
+
{
|
|
269
|
+
tag: 'image_dimensions',
|
|
270
|
+
attrs: {},
|
|
271
|
+
content: [
|
|
272
|
+
{
|
|
273
|
+
tag: 'width',
|
|
274
|
+
attrs: {},
|
|
275
|
+
content: Buffer.from('100')
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
tag: 'height',
|
|
279
|
+
attrs: {},
|
|
280
|
+
content: Buffer.from('100')
|
|
281
|
+
}
|
|
282
|
+
]
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
tag: 'token',
|
|
286
|
+
attrs: {},
|
|
287
|
+
content: Buffer.from(tokenBase64)
|
|
288
|
+
}
|
|
289
|
+
]
|
|
290
|
+
}
|
|
291
|
+
]
|
|
292
|
+
})
|
|
293
|
+
|
|
294
|
+
return parseOrderDetailsNode(result)
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
const productUpdate = async (productId: string, update: ProductUpdate) => {
|
|
298
|
+
update = await uploadingNecessaryImagesOfProduct(update, waUploadToServer)
|
|
299
|
+
const editNode = toProductNode(productId, update)
|
|
300
|
+
|
|
301
|
+
const result = await query({
|
|
302
|
+
tag: 'iq',
|
|
303
|
+
attrs: {
|
|
304
|
+
to: S_WHATSAPP_NET,
|
|
305
|
+
type: 'set',
|
|
306
|
+
xmlns: 'w:biz:catalog'
|
|
307
|
+
},
|
|
308
|
+
content: [
|
|
309
|
+
{
|
|
310
|
+
tag: 'product_catalog_edit',
|
|
311
|
+
attrs: { v: '1' },
|
|
312
|
+
content: [
|
|
313
|
+
editNode,
|
|
314
|
+
{
|
|
315
|
+
tag: 'width',
|
|
316
|
+
attrs: {},
|
|
317
|
+
content: '100'
|
|
318
|
+
},
|
|
319
|
+
{
|
|
320
|
+
tag: 'height',
|
|
321
|
+
attrs: {},
|
|
322
|
+
content: '100'
|
|
323
|
+
}
|
|
324
|
+
]
|
|
325
|
+
}
|
|
326
|
+
]
|
|
327
|
+
})
|
|
328
|
+
|
|
329
|
+
const productCatalogEditNode = getBinaryNodeChild(result, 'product_catalog_edit')
|
|
330
|
+
const productNode = getBinaryNodeChild(productCatalogEditNode, 'product')
|
|
331
|
+
|
|
332
|
+
return parseProductNode(productNode!)
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
const productCreate = async (create: ProductCreate) => {
|
|
336
|
+
// ensure isHidden is defined
|
|
337
|
+
create.isHidden = !!create.isHidden
|
|
338
|
+
create = await uploadingNecessaryImagesOfProduct(create, waUploadToServer)
|
|
339
|
+
const createNode = toProductNode(undefined, create)
|
|
340
|
+
|
|
341
|
+
const result = await query({
|
|
342
|
+
tag: 'iq',
|
|
343
|
+
attrs: {
|
|
344
|
+
to: S_WHATSAPP_NET,
|
|
345
|
+
type: 'set',
|
|
346
|
+
xmlns: 'w:biz:catalog'
|
|
347
|
+
},
|
|
348
|
+
content: [
|
|
349
|
+
{
|
|
350
|
+
tag: 'product_catalog_add',
|
|
351
|
+
attrs: { v: '1' },
|
|
352
|
+
content: [
|
|
353
|
+
createNode,
|
|
354
|
+
{
|
|
355
|
+
tag: 'width',
|
|
356
|
+
attrs: {},
|
|
357
|
+
content: '100'
|
|
358
|
+
},
|
|
359
|
+
{
|
|
360
|
+
tag: 'height',
|
|
361
|
+
attrs: {},
|
|
362
|
+
content: '100'
|
|
363
|
+
}
|
|
364
|
+
]
|
|
365
|
+
}
|
|
366
|
+
]
|
|
367
|
+
})
|
|
368
|
+
|
|
369
|
+
const productCatalogAddNode = getBinaryNodeChild(result, 'product_catalog_add')
|
|
370
|
+
const productNode = getBinaryNodeChild(productCatalogAddNode, 'product')
|
|
371
|
+
|
|
372
|
+
return parseProductNode(productNode!)
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
const productDelete = async (productIds: string[]) => {
|
|
376
|
+
const result = await query({
|
|
377
|
+
tag: 'iq',
|
|
378
|
+
attrs: {
|
|
379
|
+
to: S_WHATSAPP_NET,
|
|
380
|
+
type: 'set',
|
|
381
|
+
xmlns: 'w:biz:catalog'
|
|
382
|
+
},
|
|
383
|
+
content: [
|
|
384
|
+
{
|
|
385
|
+
tag: 'product_catalog_delete',
|
|
386
|
+
attrs: { v: '1' },
|
|
387
|
+
content: productIds.map(id => ({
|
|
388
|
+
tag: 'product',
|
|
389
|
+
attrs: {},
|
|
390
|
+
content: [
|
|
391
|
+
{
|
|
392
|
+
tag: 'id',
|
|
393
|
+
attrs: {},
|
|
394
|
+
content: Buffer.from(id)
|
|
395
|
+
}
|
|
396
|
+
]
|
|
397
|
+
}))
|
|
398
|
+
}
|
|
399
|
+
]
|
|
400
|
+
})
|
|
401
|
+
|
|
402
|
+
const productCatalogDelNode = getBinaryNodeChild(result, 'product_catalog_delete')
|
|
403
|
+
return {
|
|
404
|
+
deleted: +(productCatalogDelNode?.attrs.deleted_count || 0)
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
return {
|
|
409
|
+
...sock,
|
|
410
|
+
logger: config.logger,
|
|
411
|
+
getOrderDetails,
|
|
412
|
+
getCatalog,
|
|
413
|
+
getCollections,
|
|
414
|
+
productCreate,
|
|
415
|
+
productDelete,
|
|
416
|
+
productUpdate,
|
|
417
|
+
updateBussinesProfile,
|
|
418
|
+
updateCoverPhoto,
|
|
419
|
+
removeCoverPhoto
|
|
420
|
+
}
|
|
421
|
+
}
|