@mrlegendbot/baileys 1.2.6 → 1.2.7
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/lib/Socket/index.d.ts +0 -7
- package/lib/Socket/index.js +1 -12
- package/lib/Socket/messages-send.d.ts +1 -0
- package/lib/Socket/messages-send.js +229 -1
- package/lib/index.js +1 -1
- package/package.json +1 -1
- package/lib/Menu/index.d.ts +0 -42
- package/lib/Menu/index.js +0 -283
package/lib/Socket/index.d.ts
CHANGED
|
@@ -255,13 +255,6 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
|
|
|
255
255
|
}[] | undefined>;
|
|
256
256
|
fetchAccountReachoutTimelock: () => Promise<import("../index.js").ReachoutTimelockState>;
|
|
257
257
|
fetchNewChatMessageCap: () => Promise<import("../index.js").NewChatMessageCapInfo>;
|
|
258
|
-
sendNativeFlowMenu: (jid: string, options?: import("../Menu/index.js").MenuNativeFlowOptions) => Promise<any>;
|
|
259
|
-
sendListMenu: (jid: string, options?: any) => Promise<any>;
|
|
260
|
-
sendRichMenu: (jid: string, options?: import("../Menu/index.js").RichMenuOptions) => Promise<any>;
|
|
261
|
-
sendRowMenu: (jid: string, options?: import("../Menu/index.js").RichMenuOptions) => Promise<any>;
|
|
262
|
-
sendCarouselMenu: (jid: string, options?: import("../Menu/index.js").RichMenuOptions) => Promise<any>;
|
|
263
|
-
sendButtonMenu: (jid: string, options?: import("../Menu/index.js").RichMenuOptions) => Promise<any>;
|
|
264
|
-
sendPollMenu: (jid: string, options?: import("../Menu/index.js").MenuPollOptions) => Promise<any>;
|
|
265
258
|
};
|
|
266
259
|
export default makeWASocket;
|
|
267
260
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/Socket/index.js
CHANGED
|
@@ -1,23 +1,12 @@
|
|
|
1
1
|
import { DEFAULT_CONNECTION_CONFIG } from '../Defaults/index.js';
|
|
2
2
|
import { makeCommunitiesSocket } from './communities.js';
|
|
3
|
-
import { sendNativeFlowMenu, sendListMenu, sendRichMenu, sendRowMenu, sendCarouselMenu, sendButtonMenu, sendPollMenu } from '../Menu/index.js';
|
|
4
3
|
// export the last socket layer
|
|
5
4
|
const makeWASocket = (config) => {
|
|
6
5
|
const newConfig = {
|
|
7
6
|
...DEFAULT_CONNECTION_CONFIG,
|
|
8
7
|
...config
|
|
9
8
|
};
|
|
10
|
-
|
|
11
|
-
// Built-in interactive menu helpers. These are bound to this socket so bot code can
|
|
12
|
-
// call sock.sendNativeFlowMenu(jid, options), etc. directly.
|
|
13
|
-
sock.sendNativeFlowMenu = (jid, options) => sendNativeFlowMenu(sock, jid, options);
|
|
14
|
-
sock.sendListMenu = (jid, options) => sendListMenu(sock, jid, options);
|
|
15
|
-
sock.sendRichMenu = (jid, options) => sendRichMenu(sock, jid, options);
|
|
16
|
-
sock.sendRowMenu = (jid, options) => sendRowMenu(sock, jid, options);
|
|
17
|
-
sock.sendCarouselMenu = (jid, options) => sendCarouselMenu(sock, jid, options);
|
|
18
|
-
sock.sendButtonMenu = (jid, options) => sendButtonMenu(sock, jid, options);
|
|
19
|
-
sock.sendPollMenu = (jid, options) => sendPollMenu(sock, jid, options);
|
|
20
|
-
return sock;
|
|
9
|
+
return makeCommunitiesSocket(newConfig);
|
|
21
10
|
};
|
|
22
11
|
export default makeWASocket;
|
|
23
12
|
//# sourceMappingURL=index.js.map
|
|
@@ -33,6 +33,7 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
|
33
33
|
messageRetryManager: MessageRetryManager | null;
|
|
34
34
|
updateMemberLabel: (jid: string, memberLabel: string) => Promise<string>;
|
|
35
35
|
updateMediaMessage: (message: WAMessage) => Promise<WAMessage>;
|
|
36
|
+
richMenu: (target: string, content?: any) => Promise<WAMessage>;
|
|
36
37
|
sendMessage: (jid: string, content: AnyMessageContent, options?: MiscMessageGenerationOptions) => Promise<WAMessage | undefined>;
|
|
37
38
|
newsletterCreate: (name: string, description?: string) => Promise<import("../Types/index.js").NewsletterMetadata>;
|
|
38
39
|
newsletterUpdate: (jid: string, updates: import("../Types/index.js").NewsletterUpdate) => Promise<unknown>;
|
|
@@ -2,7 +2,7 @@ import NodeCache from '@cacheable/node-cache';
|
|
|
2
2
|
import { Boom } from '@hapi/boom';
|
|
3
3
|
import { proto } from '../../WAProto/index.js';
|
|
4
4
|
import { DEFAULT_CACHE_TTLS, WA_DEFAULT_EPHEMERAL } from '../Defaults/index.js';
|
|
5
|
-
import { aggregateMessageKeysNotFromMe, assertMediaContent, assertMeId, bindWaitForEvent, decryptMediaRetryData, DEF_MEDIA_HOST, encodeNewsletterMessage, encodeSignedDeviceIdentity, encodeWAMessage, encryptMediaRetryRequest, extractDeviceJids, generateMessageIDV2, generateParticipantHashV2, generateWAMessage, getStatusCodeForMediaRetry, getUrlFromDirectPath, getWAUploadToServer, MessageRetryManager, normalizeMessageContent, parseAndInjectE2ESessions, unixTimestampSeconds } from '../Utils/index.js';
|
|
5
|
+
import { aggregateMessageKeysNotFromMe, assertMediaContent, assertMeId, bindWaitForEvent, decryptMediaRetryData, DEF_MEDIA_HOST, encodeNewsletterMessage, encodeSignedDeviceIdentity, encodeWAMessage, encryptMediaRetryRequest, extractDeviceJids, generateMessageIDV2, generateParticipantHashV2, generateWAMessage, generateWAMessageFromContent, getStatusCodeForMediaRetry, getUrlFromDirectPath, getWAUploadToServer, MessageRetryManager, normalizeMessageContent, parseAndInjectE2ESessions, unixTimestampSeconds } from '../Utils/index.js';
|
|
6
6
|
import { getUrlInfo } from '../Utils/link-preview.js';
|
|
7
7
|
import { makeKeyedMutex, makeMutex } from '../Utils/make-mutex.js';
|
|
8
8
|
import { getMessageReportingToken, shouldIncludeReportingToken } from '../Utils/reporting-utils.js';
|
|
@@ -1278,6 +1278,233 @@ const sendRichResponseMessage = async (jid, richResponseData, options = {}) => {
|
|
|
1278
1278
|
return await sendMessage(jid, message, options);
|
|
1279
1279
|
};
|
|
1280
1280
|
|
|
1281
|
+
const richMenu = async (target, content = {}) => {
|
|
1282
|
+
let header = content?.header;
|
|
1283
|
+
let body = content?.body;
|
|
1284
|
+
let footer = content?.footer;
|
|
1285
|
+
let dihh = {};
|
|
1286
|
+
let sex = [];
|
|
1287
|
+
if (header) {
|
|
1288
|
+
const {
|
|
1289
|
+
disclaimer = false,
|
|
1290
|
+
disclaimerText = ' ',
|
|
1291
|
+
image = { inline: false },
|
|
1292
|
+
title = ''
|
|
1293
|
+
} = header ?? {};
|
|
1294
|
+
if (disclaimer) {
|
|
1295
|
+
dihh = {
|
|
1296
|
+
messageContextInfo: {
|
|
1297
|
+
botMetadata: {
|
|
1298
|
+
messageDisclaimerText: disclaimerText
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
};
|
|
1302
|
+
}
|
|
1303
|
+
if (title) {
|
|
1304
|
+
sex.push({
|
|
1305
|
+
__typename: 'GenAIUnifiedResponseSection',
|
|
1306
|
+
view_model: {
|
|
1307
|
+
__typename: 'GenAISingleLayoutViewModel',
|
|
1308
|
+
primitive: {
|
|
1309
|
+
__typename: 'FOATextPrimitive',
|
|
1310
|
+
text: '# ' + title
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
});
|
|
1314
|
+
}
|
|
1315
|
+
if (image?.url) {
|
|
1316
|
+
if (image?.inline) {
|
|
1317
|
+
sex.push({
|
|
1318
|
+
__typename: 'GenAIUnifiedResponseSection',
|
|
1319
|
+
view_model: {
|
|
1320
|
+
__typename: 'GenAISingleLayoutViewModel',
|
|
1321
|
+
primitive: {
|
|
1322
|
+
__typename: 'GenAIMarkdownTextUXPrimitive',
|
|
1323
|
+
text: '{{header}}.{{/header}}',
|
|
1324
|
+
inline_entities: [{
|
|
1325
|
+
__typename: 'GenAITextInlineEntity',
|
|
1326
|
+
key: 'header',
|
|
1327
|
+
metadata: {
|
|
1328
|
+
__typename: 'GenAILatexItem',
|
|
1329
|
+
latex_expression: '.',
|
|
1330
|
+
font_height: 24,
|
|
1331
|
+
padding: 4,
|
|
1332
|
+
latex_image: {
|
|
1333
|
+
__typename: 'GenAIMediaItem',
|
|
1334
|
+
mime_type: image.mime_type || 'image/png',
|
|
1335
|
+
url: image.url,
|
|
1336
|
+
url_fallback: image.url,
|
|
1337
|
+
width: image.width || 500,
|
|
1338
|
+
height: image.height || 500,
|
|
1339
|
+
expiration_timestamp_ms: Date.now() + 86400000
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
}]
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
});
|
|
1346
|
+
} else {
|
|
1347
|
+
sex.push({
|
|
1348
|
+
__typename: 'GenAIUnifiedResponseSection',
|
|
1349
|
+
view_model: {
|
|
1350
|
+
__typename: 'GenAISingleLayoutViewModel',
|
|
1351
|
+
primitive: {
|
|
1352
|
+
__typename: 'GenAIImagePrimitive',
|
|
1353
|
+
preview_image: {
|
|
1354
|
+
__typename: 'GenAIMediaItem',
|
|
1355
|
+
mime_type: image.mime_type || 'image/png',
|
|
1356
|
+
url: image.url
|
|
1357
|
+
},
|
|
1358
|
+
full_image: {
|
|
1359
|
+
__typename: 'GenAIMediaItem',
|
|
1360
|
+
mime_type: image.mime_type || 'image/png',
|
|
1361
|
+
url: image.url
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
});
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
}
|
|
1369
|
+
if (body) {
|
|
1370
|
+
const {
|
|
1371
|
+
cards = null,
|
|
1372
|
+
buttons = null,
|
|
1373
|
+
title = '',
|
|
1374
|
+
toast = '',
|
|
1375
|
+
carousel = false,
|
|
1376
|
+
row = false
|
|
1377
|
+
} = body ?? {};
|
|
1378
|
+
if (carousel || row) {
|
|
1379
|
+
if (cards?.length >= 1) {
|
|
1380
|
+
sex.push({
|
|
1381
|
+
__typename: 'GenAIUnifiedResponseSection',
|
|
1382
|
+
view_model: {
|
|
1383
|
+
primitives: cards.map((card, cardIndex) => ({
|
|
1384
|
+
__typename: 'GenAI3PExtWidgetPrimitive',
|
|
1385
|
+
header: {
|
|
1386
|
+
__typename: 'GenAI3PExtWidgetStandardHeader',
|
|
1387
|
+
title: card?.title || ''
|
|
1388
|
+
},
|
|
1389
|
+
body: {
|
|
1390
|
+
__typename: 'GenAI3PExtCalendarEventList',
|
|
1391
|
+
ctas: (card?.buttons || []).map((text, buttonIndex) => ({
|
|
1392
|
+
label: text,
|
|
1393
|
+
state: 'PENDING',
|
|
1394
|
+
kind: 'OTHER',
|
|
1395
|
+
tool_call_id: `${cardIndex}${buttonIndex}`,
|
|
1396
|
+
toast: {
|
|
1397
|
+
label: card?.toast || '',
|
|
1398
|
+
__typename: 'GenAI3PExtWidgetToast'
|
|
1399
|
+
},
|
|
1400
|
+
__typename: 'GenAI3PExtWidgetCTA'
|
|
1401
|
+
})),
|
|
1402
|
+
sections: []
|
|
1403
|
+
}
|
|
1404
|
+
})),
|
|
1405
|
+
__typename: carousel ? 'GenAIHScrollLayoutViewModel' : 'GenAIActionRowLayoutViewModel'
|
|
1406
|
+
}
|
|
1407
|
+
});
|
|
1408
|
+
}
|
|
1409
|
+
} else if (buttons?.length) {
|
|
1410
|
+
sex.push({
|
|
1411
|
+
__typename: 'GenAIUnifiedResponseSection',
|
|
1412
|
+
view_model: {
|
|
1413
|
+
primitive: {
|
|
1414
|
+
__typename: 'GenAI3PExtWidgetPrimitive',
|
|
1415
|
+
header: {
|
|
1416
|
+
__typename: 'GenAI3PExtWidgetStandardHeader',
|
|
1417
|
+
title: title || ''
|
|
1418
|
+
},
|
|
1419
|
+
body: {
|
|
1420
|
+
__typename: 'GenAI3PExtCalendarEventList',
|
|
1421
|
+
ctas: buttons.map((text, buttonIndex) => ({
|
|
1422
|
+
label: text,
|
|
1423
|
+
state: 'PENDING',
|
|
1424
|
+
kind: 'OTHER',
|
|
1425
|
+
tool_call_id: `${buttonIndex}`,
|
|
1426
|
+
toast: {
|
|
1427
|
+
label: toast,
|
|
1428
|
+
__typename: 'GenAI3PExtWidgetToast'
|
|
1429
|
+
},
|
|
1430
|
+
__typename: 'GenAI3PExtWidgetCTA'
|
|
1431
|
+
})),
|
|
1432
|
+
sections: []
|
|
1433
|
+
}
|
|
1434
|
+
},
|
|
1435
|
+
__typename: 'GenAISingleLayoutViewModel'
|
|
1436
|
+
}
|
|
1437
|
+
});
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
if (footer) {
|
|
1441
|
+
const {
|
|
1442
|
+
text = '',
|
|
1443
|
+
url = '',
|
|
1444
|
+
image = {}
|
|
1445
|
+
} = footer ?? {};
|
|
1446
|
+
let img = [];
|
|
1447
|
+
if (image?.url) {
|
|
1448
|
+
img.push({
|
|
1449
|
+
__typename: 'GenAIMarkdownTextUXPrimitive',
|
|
1450
|
+
text: '{{header}}.{{/header}}',
|
|
1451
|
+
inline_entities: [{
|
|
1452
|
+
__typename: 'GenAITextInlineEntity',
|
|
1453
|
+
key: 'header',
|
|
1454
|
+
metadata: {
|
|
1455
|
+
__typename: 'GenAILatexItem',
|
|
1456
|
+
latex_expression: '.',
|
|
1457
|
+
font_height: 24,
|
|
1458
|
+
padding: -5,
|
|
1459
|
+
latex_image: {
|
|
1460
|
+
__typename: 'GenAIMediaItem',
|
|
1461
|
+
mime_type: image.mime_type || 'image/png',
|
|
1462
|
+
url: image.url,
|
|
1463
|
+
url_fallback: image.url,
|
|
1464
|
+
width: image.width || 100,
|
|
1465
|
+
height: image.height || 100,
|
|
1466
|
+
expiration_timestamp_ms: Date.now() + 86400000
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
}]
|
|
1470
|
+
});
|
|
1471
|
+
}
|
|
1472
|
+
sex.push({
|
|
1473
|
+
view_model: {
|
|
1474
|
+
primitives: [{
|
|
1475
|
+
cta_text: text || 'Tg',
|
|
1476
|
+
cta_type: 'OPEN_URL',
|
|
1477
|
+
cta_url: url || 't.me/thesatanicmirror',
|
|
1478
|
+
__typename: 'GenAIFooterActionPrimitive'
|
|
1479
|
+
}, ...img],
|
|
1480
|
+
__typename: 'GenAIActionRowLayoutViewModel'
|
|
1481
|
+
}
|
|
1482
|
+
});
|
|
1483
|
+
}
|
|
1484
|
+
const waMsg = generateWAMessageFromContent(target, {
|
|
1485
|
+
...dihh,
|
|
1486
|
+
botForwardedMessage: {
|
|
1487
|
+
message: {
|
|
1488
|
+
richResponseMessage: {
|
|
1489
|
+
unifiedResponse: {
|
|
1490
|
+
data: Buffer.from(JSON.stringify({
|
|
1491
|
+
sections: sex
|
|
1492
|
+
})).toString('base64')
|
|
1493
|
+
},
|
|
1494
|
+
contextInfo: {
|
|
1495
|
+
isForwarded: true,
|
|
1496
|
+
forwardOrigin: 4,
|
|
1497
|
+
...(content?.contextInfo ?? {})
|
|
1498
|
+
}
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1502
|
+
}, {});
|
|
1503
|
+
await relayMessage(target, waMsg.message, {
|
|
1504
|
+
messageId: waMsg.key.id
|
|
1505
|
+
});
|
|
1506
|
+
return waMsg;
|
|
1507
|
+
};
|
|
1281
1508
|
const sendMessage = async (jid, content, options = {}) => {
|
|
1282
1509
|
if (content.groupStatusMessage || content.groupStatus) {
|
|
1283
1510
|
const statusContent = content.groupStatusMessage || content.groupStatus;
|
|
@@ -2388,6 +2615,7 @@ const sendRichResponseMessage = async (jid, richResponseData, options = {}) => {
|
|
|
2388
2615
|
ev.emit('messages.update', [{ key: message.key, update: { message: message.message } }]);
|
|
2389
2616
|
return message;
|
|
2390
2617
|
},
|
|
2618
|
+
richMenu,
|
|
2391
2619
|
sendRichResponseMessage,
|
|
2392
2620
|
createQuickReplyButton,
|
|
2393
2621
|
createUrlButton,
|
package/lib/index.js
CHANGED
package/package.json
CHANGED
package/lib/Menu/index.d.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { proto } from '../../WAProto/index.js';
|
|
2
|
-
|
|
3
|
-
export interface MenuNativeFlowOptions {
|
|
4
|
-
text?: string;
|
|
5
|
-
title?: string;
|
|
6
|
-
footer?: string;
|
|
7
|
-
buttons?: any[];
|
|
8
|
-
image?: Buffer | { url: string };
|
|
9
|
-
mentions?: string[];
|
|
10
|
-
quoted?: proto.IWebMessageInfo;
|
|
11
|
-
contextInfo?: any;
|
|
12
|
-
}
|
|
13
|
-
export interface MenuPollOptions {
|
|
14
|
-
name?: string;
|
|
15
|
-
values?: string[];
|
|
16
|
-
selectableCount?: number;
|
|
17
|
-
mentions?: string[];
|
|
18
|
-
quoted?: proto.IWebMessageInfo;
|
|
19
|
-
}
|
|
20
|
-
export interface RichMenuOptions {
|
|
21
|
-
header?: any;
|
|
22
|
-
body?: any;
|
|
23
|
-
footer?: any;
|
|
24
|
-
contextInfo?: any;
|
|
25
|
-
}
|
|
26
|
-
export function sendNativeFlowMenu(sock: any, jid: string, options?: MenuNativeFlowOptions): Promise<any>;
|
|
27
|
-
export function sendPollMenu(sock: any, jid: string, options?: MenuPollOptions): Promise<any>;
|
|
28
|
-
export function sendRichMenu(sock: any, jid: string, options?: RichMenuOptions): Promise<any>;
|
|
29
|
-
export function sendRowMenu(sock: any, jid: string, options?: RichMenuOptions): Promise<any>;
|
|
30
|
-
export function sendCarouselMenu(sock: any, jid: string, options?: RichMenuOptions): Promise<any>;
|
|
31
|
-
export function sendButtonMenu(sock: any, jid: string, options?: RichMenuOptions): Promise<any>;
|
|
32
|
-
export function sendListMenu(sock: any, jid: string, options?: any): Promise<any>;
|
|
33
|
-
export function menuQuickReply(displayText: string, id: string, extra?: any): any;
|
|
34
|
-
export function menuList(displayText: string, sections?: any[]): any;
|
|
35
|
-
export function menuUrl(displayText: string, url: string): any;
|
|
36
|
-
export function menuCopy(displayText: string, id: string, copyCode: string): any;
|
|
37
|
-
export function menuCall(displayText: string, phoneNumber: string): any;
|
|
38
|
-
export const createMenuButton: typeof menuQuickReply;
|
|
39
|
-
export const createMenuList: typeof menuList;
|
|
40
|
-
export const createMenuUrl: typeof menuUrl;
|
|
41
|
-
export const createMenuCopy: typeof menuCopy;
|
|
42
|
-
export const createMenuCall: typeof menuCall;
|
package/lib/Menu/index.js
DELETED
|
@@ -1,283 +0,0 @@
|
|
|
1
|
-
import { generateWAMessageFromContent, prepareWAMessageMedia } from '../Utils/messages.js'
|
|
2
|
-
import { proto } from '../../WAProto/index.js'
|
|
3
|
-
|
|
4
|
-
const asButton = (display_text, id, extra = {}) => ({
|
|
5
|
-
name: 'quick_reply',
|
|
6
|
-
buttonParamsJson: JSON.stringify({ display_text, id, ...extra })
|
|
7
|
-
})
|
|
8
|
-
|
|
9
|
-
const asList = (display_text, sections = []) => ({
|
|
10
|
-
name: 'single_select',
|
|
11
|
-
buttonParamsJson: JSON.stringify({ title: display_text, sections })
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
const asUrl = (display_text, url) => ({
|
|
15
|
-
name: 'cta_url',
|
|
16
|
-
buttonParamsJson: JSON.stringify({ display_text, url })
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
const asCopy = (display_text, id, copy_code) => ({
|
|
20
|
-
name: 'cta_copy',
|
|
21
|
-
buttonParamsJson: JSON.stringify({ display_text, id, copy_code })
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
const asCall = (display_text, phone_number) => ({
|
|
25
|
-
name: 'cta_call',
|
|
26
|
-
buttonParamsJson: JSON.stringify({
|
|
27
|
-
display_text,
|
|
28
|
-
id: `call_${phone_number}`,
|
|
29
|
-
phone_number
|
|
30
|
-
})
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
const nativeFlowNode = () => [{
|
|
34
|
-
tag: 'biz',
|
|
35
|
-
attrs: {},
|
|
36
|
-
content: [{
|
|
37
|
-
tag: 'interactive',
|
|
38
|
-
attrs: { type: 'native_flow', v: '1' },
|
|
39
|
-
content: [{ tag: 'native_flow', attrs: { name: 'mixed', v: '9' } }]
|
|
40
|
-
}]
|
|
41
|
-
}]
|
|
42
|
-
|
|
43
|
-
export async function sendNativeFlowMenu(sock, jid, {
|
|
44
|
-
text = '',
|
|
45
|
-
title,
|
|
46
|
-
footer = '',
|
|
47
|
-
buttons = [],
|
|
48
|
-
image,
|
|
49
|
-
mentions = [],
|
|
50
|
-
quoted,
|
|
51
|
-
contextInfo = {}
|
|
52
|
-
} = {}) {
|
|
53
|
-
|
|
54
|
-
let header = {}
|
|
55
|
-
if (image) {
|
|
56
|
-
header = await prepareWAMessageMedia(
|
|
57
|
-
{ image: Buffer.isBuffer(image) ? image : image },
|
|
58
|
-
{ upload: sock.waUploadToServer }
|
|
59
|
-
)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const message = generateWAMessageFromContent(jid, {
|
|
63
|
-
viewOnceMessage: {
|
|
64
|
-
message: {
|
|
65
|
-
messageContextInfo: {
|
|
66
|
-
deviceListMetadata: {},
|
|
67
|
-
deviceListMetadataVersion: 2
|
|
68
|
-
},
|
|
69
|
-
interactiveMessage: proto.Message.InteractiveMessage.create({
|
|
70
|
-
contextInfo: { ...contextInfo, mentionedJid: mentions.length ? mentions : undefined },
|
|
71
|
-
header: (title || image) ? proto.Message.InteractiveMessage.Header.create({
|
|
72
|
-
...header,
|
|
73
|
-
title: image ? undefined : title,
|
|
74
|
-
hasMediaAttachment: !!image
|
|
75
|
-
}) : undefined,
|
|
76
|
-
body: proto.Message.InteractiveMessage.Body.create({ text }),
|
|
77
|
-
footer: proto.Message.InteractiveMessage.Footer.create({ text: footer }),
|
|
78
|
-
nativeFlowMessage: proto.Message.InteractiveMessage.NativeFlowMessage.create({ buttons })
|
|
79
|
-
})
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}, { quoted, userJid: sock.user?.id })
|
|
83
|
-
|
|
84
|
-
await sock.relayMessage(jid, message.message, {
|
|
85
|
-
messageId: message.key.id,
|
|
86
|
-
additionalNodes: nativeFlowNode()
|
|
87
|
-
})
|
|
88
|
-
return message
|
|
89
|
-
}
|
|
90
|
-
export async function sendPollMenu(sock, jid, {
|
|
91
|
-
name = '',
|
|
92
|
-
values = [],
|
|
93
|
-
selectableCount = 1,
|
|
94
|
-
mentions = [],
|
|
95
|
-
quoted
|
|
96
|
-
} = {}) {
|
|
97
|
-
const message = await sock.sendMessage(jid, {
|
|
98
|
-
poll: { name, values, selectableCount },
|
|
99
|
-
mentions
|
|
100
|
-
}, { quoted })
|
|
101
|
-
return message
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export async function sendRichMenu(sock, jid, {
|
|
105
|
-
header = {},
|
|
106
|
-
body = {},
|
|
107
|
-
footer = {},
|
|
108
|
-
contextInfo = {}
|
|
109
|
-
} = {}) {
|
|
110
|
-
const sections = []
|
|
111
|
-
const {
|
|
112
|
-
disclaimer = false,
|
|
113
|
-
disclaimerText = ' ',
|
|
114
|
-
image = {},
|
|
115
|
-
title = ''
|
|
116
|
-
} = header || {}
|
|
117
|
-
|
|
118
|
-
if (disclaimer) {
|
|
119
|
-
sections.push({ __typename: 'GenAIUnifiedResponseSection',
|
|
120
|
-
view_model: { __typename: 'GenAISingleLayoutViewModel',
|
|
121
|
-
primitive: { __typename: 'FOATextPrimitive', text: disclaimerText } } })
|
|
122
|
-
}
|
|
123
|
-
if (title) {
|
|
124
|
-
sections.push({
|
|
125
|
-
__typename: 'GenAIUnifiedResponseSection',
|
|
126
|
-
view_model: {
|
|
127
|
-
__typename: 'GenAISingleLayoutViewModel',
|
|
128
|
-
primitive: { __typename: 'FOATextPrimitive', text: '# ' + title }
|
|
129
|
-
}
|
|
130
|
-
})
|
|
131
|
-
}
|
|
132
|
-
if (image?.url) {
|
|
133
|
-
sections.push({
|
|
134
|
-
__typename: 'GenAIUnifiedResponseSection',
|
|
135
|
-
view_model: {
|
|
136
|
-
__typename: 'GenAISingleLayoutViewModel',
|
|
137
|
-
primitive: image.inline ? {
|
|
138
|
-
__typename: 'GenAIMarkdownTextUXPrimitive',
|
|
139
|
-
text: '{{header}}.{{/header}}',
|
|
140
|
-
inline_entities: [{
|
|
141
|
-
__typename: 'GenAITextInlineEntity',
|
|
142
|
-
key: 'header',
|
|
143
|
-
metadata: {
|
|
144
|
-
__typename: 'GenAILatexItem',
|
|
145
|
-
latex_expression: '.',
|
|
146
|
-
font_height: 24,
|
|
147
|
-
padding: 4,
|
|
148
|
-
latex_image: {
|
|
149
|
-
__typename: 'GenAIMediaItem',
|
|
150
|
-
mime_type: image.mime_type || 'image/png',
|
|
151
|
-
url: image.url,
|
|
152
|
-
url_fallback: image.url,
|
|
153
|
-
width: image.width || 500,
|
|
154
|
-
height: image.height || 500,
|
|
155
|
-
expiration_timestamp_ms: Date.now() + 86400000
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}]
|
|
159
|
-
} : {
|
|
160
|
-
__typename: 'GenAIImagePrimitive',
|
|
161
|
-
preview_image: { __typename: 'GenAIMediaItem', mime_type: image.mime_type || 'image/png', url: image.url },
|
|
162
|
-
full_image: { __typename: 'GenAIMediaItem', mime_type: image.mime_type || 'image/png', url: image.url }
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
})
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
const {
|
|
169
|
-
cards = [],
|
|
170
|
-
buttons = [],
|
|
171
|
-
title: bodyTitle = '',
|
|
172
|
-
toast = '',
|
|
173
|
-
carousel = false,
|
|
174
|
-
row = false
|
|
175
|
-
} = body || {}
|
|
176
|
-
|
|
177
|
-
if ((carousel || row) && cards.length) {
|
|
178
|
-
sections.push({
|
|
179
|
-
__typename: 'GenAIUnifiedResponseSection',
|
|
180
|
-
view_model: {
|
|
181
|
-
primitives: cards.map((card, cardIndex) => ({
|
|
182
|
-
__typename: 'GenAI3PExtWidgetPrimitive',
|
|
183
|
-
header: {
|
|
184
|
-
__typename: 'GenAI3PExtWidgetStandardHeader',
|
|
185
|
-
title: card?.title || ''
|
|
186
|
-
},
|
|
187
|
-
body: {
|
|
188
|
-
__typename: 'GenAI3PExtCalendarEventList',
|
|
189
|
-
ctas: (card?.buttons || []).map((label, buttonIndex) => ({
|
|
190
|
-
label,
|
|
191
|
-
state: 'PENDING',
|
|
192
|
-
kind: 'OTHER',
|
|
193
|
-
tool_call_id: `${cardIndex}${buttonIndex}`,
|
|
194
|
-
toast: { label: card?.toast || toast, __typename: 'GenAI3PExtWidgetToast' },
|
|
195
|
-
__typename: 'GenAI3PExtWidgetCTA'
|
|
196
|
-
})),
|
|
197
|
-
sections: []
|
|
198
|
-
}
|
|
199
|
-
})),
|
|
200
|
-
__typename: carousel ? 'GenAIHScrollLayoutViewModel' : 'GenAIActionRowLayoutViewModel'
|
|
201
|
-
}
|
|
202
|
-
})
|
|
203
|
-
} else if (buttons.length) {
|
|
204
|
-
sections.push({
|
|
205
|
-
__typename: 'GenAIUnifiedResponseSection',
|
|
206
|
-
view_model: {
|
|
207
|
-
primitive: {
|
|
208
|
-
__typename: 'GenAI3PExtWidgetPrimitive',
|
|
209
|
-
header: { __typename: 'GenAI3PExtWidgetStandardHeader', title: bodyTitle },
|
|
210
|
-
body: {
|
|
211
|
-
__typename: 'GenAI3PExtCalendarEventList',
|
|
212
|
-
ctas: buttons.map((label, index) => ({
|
|
213
|
-
label,
|
|
214
|
-
state: 'PENDING',
|
|
215
|
-
kind: 'OTHER',
|
|
216
|
-
tool_call_id: `${index}`,
|
|
217
|
-
toast: { label: toast, __typename: 'GenAI3PExtWidgetToast' },
|
|
218
|
-
__typename: 'GenAI3PExtWidgetCTA'
|
|
219
|
-
})),
|
|
220
|
-
sections: []
|
|
221
|
-
}
|
|
222
|
-
},
|
|
223
|
-
__typename: 'GenAISingleLayoutViewModel'
|
|
224
|
-
}
|
|
225
|
-
})
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
if (footer?.text || footer?.url) {
|
|
229
|
-
sections.push({
|
|
230
|
-
view_model: {
|
|
231
|
-
primitives: [{
|
|
232
|
-
cta_text: footer.text || 'Open',
|
|
233
|
-
cta_type: 'OPEN_URL',
|
|
234
|
-
cta_url: footer.url || '',
|
|
235
|
-
__typename: 'GenAIFooterActionPrimitive'
|
|
236
|
-
}],
|
|
237
|
-
__typename: 'GenAIActionRowLayoutViewModel'
|
|
238
|
-
}
|
|
239
|
-
})
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
const message = generateWAMessageFromContent(jid, {
|
|
243
|
-
richResponseMessage: {
|
|
244
|
-
unifiedResponse: {
|
|
245
|
-
data: Buffer.from(JSON.stringify({ sections })).toString('base64')
|
|
246
|
-
},
|
|
247
|
-
contextInfo
|
|
248
|
-
}
|
|
249
|
-
}, { quoted: undefined, userJid: sock.user?.id })
|
|
250
|
-
|
|
251
|
-
await sock.relayMessage(jid, message.message, { messageId: message.key.id })
|
|
252
|
-
return message
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
export const sendRowMenu = (sock, jid, options = {}) =>
|
|
256
|
-
sendRichMenu(sock, jid, { ...options, body: { ...(options.body || {}), row: true, carousel: false } })
|
|
257
|
-
|
|
258
|
-
export const sendCarouselMenu = (sock, jid, options = {}) =>
|
|
259
|
-
sendRichMenu(sock, jid, { ...options, body: { ...(options.body || {}), carousel: true, row: false } })
|
|
260
|
-
|
|
261
|
-
export const sendButtonMenu = (sock, jid, options = {}) =>
|
|
262
|
-
sendRichMenu(sock, jid, { ...options, body: { ...(options.body || {}), carousel: false, row: false } })
|
|
263
|
-
|
|
264
|
-
export const sendListMenu = (sock, jid, {
|
|
265
|
-
title = 'Menu',
|
|
266
|
-
sections = [],
|
|
267
|
-
...rest
|
|
268
|
-
} = {}) => sendNativeFlowMenu(sock, jid, {
|
|
269
|
-
...rest,
|
|
270
|
-
buttons: [asList(title, sections)]
|
|
271
|
-
})
|
|
272
|
-
|
|
273
|
-
export const menuQuickReply = asButton
|
|
274
|
-
export const menuList = asList
|
|
275
|
-
export const menuUrl = asUrl
|
|
276
|
-
export const menuCopy = asCopy
|
|
277
|
-
export const menuCall = asCall
|
|
278
|
-
|
|
279
|
-
export const createMenuButton = asButton
|
|
280
|
-
export const createMenuList = asList
|
|
281
|
-
export const createMenuUrl = asUrl
|
|
282
|
-
export const createMenuCopy = asCopy
|
|
283
|
-
export const createMenuCall = asCall
|