@realvare/based 2.7.70 → 2.7.71

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.
@@ -0,0 +1,259 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.makeInteractiveSocket = void 0;
7
+ const WAProto_1 = require("../../WAProto");
8
+ const Utils_1 = require("../Utils");
9
+ const messages_send_1 = require("./messages-send");
10
+ const makeInteractiveSocket = (config) => {
11
+ const sock = (0, messages_send_1.makeMessagesSocket)(config);
12
+ const { ev, authState, relayMessage } = sock;
13
+
14
+ /**
15
+ * Send List Message (Native Implementation)
16
+ * Modern interactive list with single_select support
17
+ */
18
+ const sendList = async (jid, buttonText, text, title, footer, sections, options = {}) => {
19
+ const listMessage = {
20
+ interactiveButtons: [{
21
+ name: "single_select",
22
+ buttonParamsJson: JSON.stringify({
23
+ title: buttonText,
24
+ sections: sections
25
+ })
26
+ }],
27
+ text: text,
28
+ title: title,
29
+ footer: footer
30
+ };
31
+
32
+ const fullMsg = await (0, Utils_1.generateWAMessageContent)(listMessage, {
33
+ ...config,
34
+ logger: config.logger
35
+ });
36
+
37
+ return await relayMessage(jid, fullMsg.message, {
38
+ messageId: fullMsg.key.id,
39
+ ...options
40
+ });
41
+ };
42
+
43
+ /**
44
+ * Send Button Message (Native Implementation)
45
+ * Quick reply buttons with optional media
46
+ */
47
+ const sendButton = async (jid, text, buttons, options = {}) => {
48
+ const buttonMessage = {
49
+ text: text,
50
+ footer: options.footer,
51
+ buttons: buttons.map(btn => ({
52
+ buttonId: btn.buttonId,
53
+ buttonText: { displayText: btn.buttonText },
54
+ type: 1
55
+ })),
56
+ headerType: options.headerType || 1,
57
+ ...(options.image && { image: options.image }),
58
+ ...(options.video && { video: options.video }),
59
+ ...(options.document && { document: options.document })
60
+ };
61
+
62
+ const fullMsg = await (0, Utils_1.generateWAMessageContent)(buttonMessage, {
63
+ ...config,
64
+ logger: config.logger
65
+ });
66
+
67
+ return await relayMessage(jid, fullMsg.message, {
68
+ messageId: fullMsg.key.id,
69
+ ...options
70
+ });
71
+ };
72
+
73
+ /**
74
+ * Send Carousel Message (Native Implementation)
75
+ * Multiple interactive cards in one message
76
+ */
77
+ const sendCarousel = async (jid, cards, options = {}) => {
78
+ const carouselMessage = {
79
+ carousel: cards.map(card => ({
80
+ body: card.body || { text: card.text || '' },
81
+ footer: card.footer ? { text: card.footer } : undefined,
82
+ header: {
83
+ title: card.title,
84
+ subtitle: card.subtitle,
85
+ hasMediaAttachment: !!card.media,
86
+ ...(card.media?.image && {
87
+ imageMessage: card.media.image
88
+ }),
89
+ ...(card.media?.video && {
90
+ videoMessage: card.media.video
91
+ })
92
+ },
93
+ nativeFlowMessage: card.buttons ? {
94
+ buttons: card.buttons.map(btn => ({
95
+ name: btn.name,
96
+ buttonParamsJson: btn.buttonParamsJson
97
+ })),
98
+ messageVersion: 1
99
+ } : undefined
100
+ })),
101
+ text: options.text,
102
+ footer: options.footer
103
+ };
104
+
105
+ const fullMsg = await (0, Utils_1.generateWAMessageContent)(carouselMessage, {
106
+ ...config,
107
+ logger: config.logger
108
+ });
109
+
110
+ return await relayMessage(jid, fullMsg.message, {
111
+ messageId: fullMsg.key.id,
112
+ ...options
113
+ });
114
+ };
115
+
116
+ /**
117
+ * Send Interactive Template Message (Native Implementation)
118
+ * For business templates and rich interactive content
119
+ */
120
+ const sendTemplate = async (jid, template, options = {}) => {
121
+ const templateMessage = {
122
+ interactiveButtons: [{
123
+ name: "template_message",
124
+ buttonParamsJson: JSON.stringify(template)
125
+ }],
126
+ text: template.text,
127
+ title: template.title,
128
+ footer: template.footer,
129
+ ...(template.media && { media: template.media })
130
+ };
131
+
132
+ const fullMsg = await (0, Utils_1.generateWAMessageContent)(templateMessage, {
133
+ ...config,
134
+ logger: config.logger
135
+ });
136
+
137
+ return await relayMessage(jid, fullMsg.message, {
138
+ messageId: fullMsg.key.id,
139
+ ...options
140
+ });
141
+ };
142
+
143
+ /**
144
+ * Send Collection Message (Native Implementation)
145
+ * For product collections and business catalogs
146
+ */
147
+ const sendCollection = async (jid, collection, options = {}) => {
148
+ const collectionMessage = {
149
+ collection: {
150
+ bizJid: collection.bizJid,
151
+ id: collection.id,
152
+ messageVersion: collection.messageVersion || 1
153
+ },
154
+ text: collection.text,
155
+ title: collection.title,
156
+ footer: collection.footer
157
+ };
158
+
159
+ const fullMsg = await (0, Utils_1.generateWAMessageContent)(collectionMessage, {
160
+ ...config,
161
+ logger: config.logger
162
+ });
163
+
164
+ return await relayMessage(jid, fullMsg.message, {
165
+ messageId: fullMsg.key.id,
166
+ ...options
167
+ });
168
+ };
169
+
170
+ /**
171
+ * Send Shop Message (Native Implementation)
172
+ * For business storefronts
173
+ */
174
+ const sendShop = async (jid, shop, options = {}) => {
175
+ const shopMessage = {
176
+ shop: {
177
+ surface: shop.surface,
178
+ id: shop.id
179
+ },
180
+ text: shop.text,
181
+ title: shop.title,
182
+ footer: shop.footer,
183
+ ...(shop.media && { media: shop.media })
184
+ };
185
+
186
+ const fullMsg = await (0, Utils_1.generateWAMessageContent)(shopMessage, {
187
+ ...config,
188
+ logger: config.logger
189
+ });
190
+
191
+ return await relayMessage(jid, fullMsg.message, {
192
+ messageId: fullMsg.key.id,
193
+ ...options
194
+ });
195
+ };
196
+
197
+ /**
198
+ * Send Poll Message (Native Implementation)
199
+ * Enhanced poll with multiple options and configurations
200
+ */
201
+ const sendPoll = async (jid, poll, options = {}) => {
202
+ const pollMessage = {
203
+ poll: {
204
+ name: poll.name,
205
+ values: poll.options,
206
+ selectableCount: poll.selectableCount || 1,
207
+ toAnnouncementGroup: poll.toAnnouncementGroup || false,
208
+ messageSecret: poll.messageSecret,
209
+ ...(poll.pollType && { pollType: poll.pollType })
210
+ }
211
+ };
212
+
213
+ const fullMsg = await (0, Utils_1.generateWAMessageContent)(pollMessage, {
214
+ ...config,
215
+ logger: config.logger
216
+ });
217
+
218
+ return await relayMessage(jid, fullMsg.message, {
219
+ messageId: fullMsg.key.id,
220
+ ...options
221
+ });
222
+ };
223
+
224
+ /**
225
+ * Send Event Message (Native Implementation)
226
+ * For event invitations and RSVPs
227
+ */
228
+ const sendEvent = async (jid, event, options = {}) => {
229
+ const eventMessage = {
230
+ event: {
231
+ ...event,
232
+ messageSecret: event.messageSecret
233
+ }
234
+ };
235
+
236
+ const fullMsg = await (0, Utils_1.generateWAMessageContent)(eventMessage, {
237
+ ...config,
238
+ logger: config.logger
239
+ });
240
+
241
+ return await relayMessage(jid, fullMsg.message, {
242
+ messageId: fullMsg.key.id,
243
+ ...options
244
+ });
245
+ };
246
+
247
+ return {
248
+ ...sock,
249
+ sendList,
250
+ sendButton,
251
+ sendCarousel,
252
+ sendTemplate,
253
+ sendCollection,
254
+ sendShop,
255
+ sendPoll,
256
+ sendEvent
257
+ };
258
+ };
259
+ exports.makeInteractiveSocket = makeInteractiveSocket;