@gamastudio/sendwave-provider 1.0.0 → 1.0.1

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/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # 📖 Sendwave Provider
1
+ # 📖 Sendwaves Provider
2
2
 
3
3
  **A dynamic library for integrating and managing Sendwave instances for WhatsApp bot development.**
4
4
 
@@ -23,80 +23,90 @@ const provider = createSendWaveProvider({
23
23
 
24
24
  // Initialize the provider
25
25
  await provider.initAll(provider.globalVendorArgs.port);
26
- await provider.initVendor();
27
26
  ```
28
27
 
29
- ### Complete Configuration Options
28
+ ## 📤 Sending Messages
29
+
30
+ ### Text Messages
30
31
 
31
32
  ```typescript
32
- import { createSendWaveProvider, type GlobalVendorArgs } from "@gamastudio/sendwave-provider";
33
-
34
- const config: Partial<GlobalVendorArgs> = {
35
- name: "MyBot", // Instance identifier
36
- apiKey: "your-api-key", // Sendwave API key
37
- port: 3000, // HTTP server port
38
- delay: 1000, // Default delay between messages (ms)
39
- linkPreview: true, // Enable/disable link previews
40
- message: {
41
- mergeMessage: false, // Enable message buffering
42
- timeMergeMessage: 3, // Buffer timeout in seconds
43
- },
44
- queueFlow: {
45
- enabled: true, // Enable queue flow system
46
- warningTimeout: 30 * 60 * 1000, // 30 minutes before warning
47
- endTimeout: 2 * 60 * 1000, // 2 minutes after warning to end session
48
- warningMessage: "⏳ You seem to be inactive. Are you still there?",
49
- },
50
- };
33
+ await provider.sendText({
34
+ from: "573123456789",
35
+ text: "Hello! Welcome to our service.",
36
+ });
37
+ ```
38
+
39
+ ### Interactive Polls (New! 📊)
51
40
 
52
- const provider = createSendWaveProvider(config);
41
+ ```typescript
42
+ await provider.sendPoll({
43
+ from: "573123456789",
44
+ poll: {
45
+ name: "¿Qué te parece el nuevo proveedor?",
46
+ values: ["Excelente", "Bueno", "Mejorable"],
47
+ selectableCount: 1 // Optional, default: 1
48
+ }
49
+ });
53
50
  ```
54
51
 
55
- ## 📤 Sending Messages
52
+ ### Intelligent Buttons (Easier! 🔘)
56
53
 
57
- ### Text Messages
54
+ The provider is now "intelligent" and accepts multiple formats for buttons.
58
55
 
59
56
  ```typescript
60
- await provider.sendText({
57
+ // 1. Super Simple (Quick Replies)
58
+ await provider.sendButton({
61
59
  from: "573123456789",
62
- text: "Hello! Welcome to our service.",
60
+ title: "Main Menu",
61
+ buttons: ["🛒 Catalog", "🎁 Promotions", "📞 Support"]
62
+ });
63
+
64
+ // 2. Mixed Format (Text & Functional buttons)
65
+ await provider.sendButton({
66
+ from: "573123456789",
67
+ title: "Payment Options",
68
+ body: "Select your preferred method",
69
+ buttons: [
70
+ { type: "reply", displayText: "Cash" },
71
+ { type: "url", displayText: "Visit Web", url: "https://example.com" },
72
+ { type: "copy", displayText: "Copy Coupon", copyText: "SAVE20" },
73
+ { type: "pix", displayText: "Pay with Pix", keyType: "email", key: "pix@bot.com" }
74
+ ]
63
75
  });
64
76
  ```
65
77
 
66
- ### Interactive Lists
78
+ **Supported Button Types:**
79
+ - `reply`: Standard quick reply button.
80
+ - `url`: Opens a website.
81
+ - `call`: Triggers a phone call.
82
+ - `copy`: Copies text or code to clipboard.
83
+ - `pix`: Brazilian payment system integration.
84
+
85
+ ### Intelligent Lists (Simple & Advanced 📜)
67
86
 
68
87
  ```typescript
88
+ // Simple List (Array of strings)
69
89
  await provider.sendList({
70
90
  from: "573123456789",
71
91
  list: {
72
92
  title: "Select an option",
73
- description: "Choose from the following options:",
74
- button: "View Menu",
75
- content: ["🛒 Catalog", "🎁 Promotions", "📞 Support"],
76
- footerText: "Powered by Sendwave", // Optional
93
+ button: "View Options",
94
+ content: ["Option 1", "Option 2", "Option 3"],
77
95
  },
78
96
  });
79
97
 
80
- // Advanced list with sections
98
+ // Advanced List with sections
81
99
  await provider.sendList({
82
100
  from: "573123456789",
83
101
  list: {
84
102
  title: "Product Categories",
85
- description: "Browse our products by category",
86
103
  button: "Select Category",
87
104
  content: [
88
105
  {
89
106
  title: "Electronics",
90
107
  rows: [
91
- { title: "Smartphones", description: "Latest models available" },
92
- { title: "Laptops", description: "Gaming and office laptops" },
93
- ],
94
- },
95
- {
96
- title: "Clothing",
97
- rows: [
98
- { title: "Men's Fashion" },
99
- { title: "Women's Fashion" },
108
+ { title: "Smartphones", description: "Latest models" },
109
+ { title: "Laptops", description: "Gaming and office" },
100
110
  ],
101
111
  },
102
112
  ],
@@ -107,268 +117,43 @@ await provider.sendList({
107
117
  ### Media Messages
108
118
 
109
119
  ```typescript
110
- // Images
111
- await provider.sendImage({
112
- from: "573123456789",
113
- url: "https://example.com/image.jpg",
114
- text: "Check out this product!",
115
- });
116
-
117
- // Videos
118
- await provider.sendVideo({
119
- from: "573123456789",
120
- url: "https://example.com/video.mp4",
121
- text: "Product demonstration",
122
- });
123
-
124
- // Documents
125
- await provider.sendFile({
126
- from: "573123456789",
127
- url: "https://example.com/catalog.pdf",
128
- fileName: "Product Catalog 2024.pdf",
129
- text: "Here's our complete catalog",
130
- });
131
-
132
- // Voice Messages
133
- await provider.sendVoice({
134
- from: "573123456789",
135
- url: "https://example.com/audio.mp3",
136
- });
137
- ```
138
-
139
- ### Button Messages
140
-
141
- ```typescript
142
- await provider.sendButton({
143
- from: "573123456789",
144
- title: "Customer Support",
145
- body: "How can we help you today?",
146
- description: "Choose one of the options below",
147
- footer: "We're here to help!",
148
- buttons: [
149
- { type: "reply", text: "Technical Support" },
150
- { type: "reply", text: "Billing Questions" },
151
- { type: "url", text: "Visit Website" },
152
- ],
153
- });
120
+ // Images, Videos, Documents, and Voice
121
+ await provider.sendImage({ from: "573123456789", url: "https://...", text: "Caption" });
122
+ await provider.sendVideo({ from: "573123456789", url: "https://...", text: "Caption" });
123
+ await provider.sendFile({ from: "573123456789", url: "https://...", fileName: "file.pdf" });
124
+ await provider.sendVoice({ from: "573123456789", url: "https://..." });
154
125
  ```
155
126
 
156
- ## 🔄 Queue Flow System
157
-
158
- The Queue Flow system **automatically** manages user sessions, handling timeouts and inactive users to optimize bot performance. Just enable it in the configuration and everything works automatically.
127
+ ## 🔄 Queue Flow System (100% Automatic)
159
128
 
160
- ### Enable Queue Flow (100% Automatic)
129
+ The Queue Flow system manages user sessions, handling timeouts and inactive users automatically.
161
130
 
162
131
  ```typescript
163
132
  const provider = createSendWaveProvider({
164
133
  name: "MyBot",
165
134
  apiKey: "your-key",
166
135
  queueFlow: {
167
- enabled: true, // 🚀 That's it! Everything else is automatic
168
- warningTimeout: 30 * 60 * 1000, // 30 minutes (optional)
169
- endTimeout: 2 * 60 * 1000, // 2 minutes (optional)
170
- warningMessage: "⏳ You seem inactive. Still there?", // (optional)
136
+ enabled: true,
137
+ warningTimeout: 30 * 60 * 1000, // 30 mins
138
+ endTimeout: 2 * 60 * 1000, // 2 mins after warning
139
+ warningMessage: "⏳ You seem inactive. Still there?",
171
140
  },
172
141
  });
173
142
  ```
174
143
 
175
- **✨ What happens automatically when enabled:**
176
- - User timeouts are reset on every message (no code needed)
177
- - Warning messages are sent after inactivity period
178
- - Users are automatically removed from queue after timeout
179
- - `END_FLOW` event is triggered for BuilderBot integration
180
- - No additional code required in your flows!
181
-
182
- ### Queue Flow Methods
183
-
184
- ```typescript
185
- // Reset user timeout (called automatically on user messages)
186
- provider.resetUserTimeout("573123456789", "John Doe");
187
-
188
- // Clear user timeout manually
189
- provider.clearUserTimeout("573123456789");
190
-
191
- // Force remove user from system
192
- provider.forceClearUser("573123456789");
193
-
194
- // Check if user is ignored
195
- const isIgnored = provider.isUserIgnored("573123456789");
196
-
197
- // Get system statistics
198
- const stats = provider.getQueueFlowStats();
199
- console.log(stats); // { activeTimeouts: 5, ignoredUsers: 2, config: {...} }
200
- ```
201
-
202
- ### Queue Flow Events
203
-
204
- ```typescript
205
- // Listen to user inactivity events
206
- provider.onQueueFlowEvent('userInactive-573123456789', (data) => {
207
- if (data.isActive) {
208
- console.log(`Warning sent to ${data.from}`);
209
- } else {
210
- console.log(`User ${data.from} removed due to inactivity`);
211
- }
212
- });
213
-
214
- // Remove event listeners
215
- provider.offQueueFlowEvent('userInactive-573123456789');
216
- ```
217
-
218
- ## 🤖 BuilderBot Integration
219
-
220
- ### Flow Implementation Examples
221
-
222
- ```typescript
223
- import { addKeyword, EVENTS, utils } from "@builderbot/bot";
224
- import { SendWaveProvider as Provider } from "@gamastudio/sendwave-provider";
225
-
226
- // Welcome Flow
227
- export const flowWelcome = addKeyword<Provider>(EVENTS.WELCOME)
228
- .addAnswer([
229
- "¡Hello! I'm *Max*, your virtual assistant. 😊",
230
- "Welcome to our service.",
231
- ])
232
- .addAction(async (_, { gotoFlow }) => await gotoFlow(flowMainMenu));
233
-
234
- // End Flow (integrates with Queue Flow system)
235
- export const flowEnd = addKeyword<Provider>(utils.setEvent("END_FLOW"))
236
- .addAction(async (ctx, { endFlow, provider }) => {
237
- // Clean up user from queue flow system
238
- provider.forceClearUser(ctx.from);
239
- endFlow("Chat closed due to inactivity. Write again if you need help!");
240
- });
241
-
242
- // Customer Support Flow
243
- export const flowSupport = addKeyword<Provider>("SUPPORT")
244
- .addAction(async (ctx, { blacklist, endFlow, provider }) => {
245
- // Add to blacklist and clean queue
246
- blacklist.add(ctx.from);
247
- provider.forceClearUser(ctx.from);
248
-
249
- return endFlow(
250
- "An agent will contact you shortly. Thanks for your patience! 👨‍💻"
251
- );
252
- });
253
-
254
- // Interactive Menu Flow
255
- export const flowMainMenu = addKeyword<Provider>("MAIN_MENU")
256
- .addAction(async (ctx, { provider }) => {
257
- await provider.sendList({
258
- from: ctx.from,
259
- list: {
260
- button: "View Menu",
261
- title: "",
262
- description: "Select an option from the menu. Let's get started! 👇",
263
- content: ["🛒 Catalog", "🎁 Promotions", "📞 Support"],
264
- },
265
- });
266
- })
267
- .addAction({ capture: true }, async (ctx, { gotoFlow, fallBack }) => {
268
- const option = ctx.body.trim();
269
-
270
- switch (option) {
271
- case "🛒 Catalog":
272
- await gotoFlow(flowCatalog);
273
- break;
274
- case "🎁 Promotions":
275
- await gotoFlow(flowPromotions);
276
- break;
277
- case "📞 Support":
278
- await gotoFlow(flowSupport);
279
- break;
280
- default:
281
- fallBack("I didn't understand that option. Please select from the list.");
282
- break;
283
- }
284
- });
285
- ```
286
-
287
- ### Delayed Response Handling (100% Automatic)
288
-
289
- The Queue Flow system automatically handles users who take time to respond with **zero configuration needed**:
290
-
291
- ```typescript
292
- // ✅ AUTOMATIC PROCESS:
293
- // 1. User sends message -> timeout resets automatically
294
- // 2. After 30 minutes of inactivity -> warning message sent automatically
295
- // 3. After 2 more minutes -> user session ends with END_FLOW event automatically
296
- // 4. User is cleaned from queue automatically
297
-
298
- // 🎯 ONLY THING YOU NEED: Handle the END_FLOW event in your flows
299
- export const flowEnd = addKeyword<Provider>(utils.setEvent("END_FLOW"))
300
- .addAction(async (ctx, { endFlow }) => {
301
- // This runs automatically when user is inactive for too long
302
- endFlow("Session ended due to inactivity. Contact us again anytime!");
303
- // ✨ Queue cleanup happens automatically, no code needed!
304
- });
305
- ```
306
-
307
144
  ## 🎯 Event System
308
145
 
309
146
  ```typescript
310
- // Connection events
311
- provider.on('ready', (isReady: boolean) => {
312
- console.log('Connection status:', isReady ? 'Connected' : 'Disconnected');
313
- });
314
-
315
- provider.on('auth_failure', (error) => {
316
- console.error('Authentication failed:', error);
317
- });
318
-
319
- // Message events
320
- provider.on('message', (ctx) => {
321
- console.log(`Message from ${ctx.from}: ${ctx.body}`);
322
- });
323
-
324
- provider.on('user-message', (data) => {
325
- console.log(`User message: ${data.body}`);
326
- // Timeout automatically resets here if queue flow is enabled
327
- });
147
+ provider.on('ready', (isReady) => console.log('Connected:', isReady));
148
+ provider.on('message', (ctx) => console.log(`From ${ctx.from}: ${ctx.body}`));
328
149
  ```
329
150
 
330
- ## 🛠️ Development Scripts
331
-
332
- | Script | Description |
333
- | --------------- | ------------------------------------------------ |
334
- | `npm run dev` | Run library in development mode with auto-reload |
335
- | `npm run build` | Compile TypeScript and resolve path aliases |
336
- | `npm run test` | Run basic test file |
337
-
338
- ## 📦 Package Structure
339
-
340
- When you install `@gamastudio/sendwave-provider`:
341
-
342
- - Compiled code in `/build` directory
343
- - TypeScript declarations (`.d.ts`) included
344
- - Main entry point: `build/index.js`
345
- - Full TypeScript support with path aliases resolved
346
-
347
- ## 📋 Requirements
348
-
349
- - **Node.js** 18+
350
- - **npm** or **pnpm**
351
- - **TypeScript** 5+
352
- - Valid Sendwave API credentials
353
-
354
- ## 🔥 Important Notes
355
-
356
- This library is in **beta** state and subject to internal changes.
357
-
358
- **Recommendations:**
359
- - Use in testing or controlled environments initially
360
- - Update beta versions as new releases become available
361
- - Monitor the queue flow system performance with your user base
362
-
363
151
  ## 🏗️ Architecture
364
152
 
365
- - **Provider Layer**: Main SendWaveProvider class extending BuilderBot
366
- - **Core Layer**: Message processing and webhook handling
367
- - **Sender Layer**: Message sending functionality with media support
368
- - **Queue Flow**: Advanced user session management with timeout handling
369
- - **Utils**: Media detection, message parsing, and flow utilities
153
+ - **Provider Layer**: Main SendWaveProvider class.
154
+ - **Sender Layer**: Intelligent message transformation.
155
+ - **Queue Flow**: Automatic session management.
370
156
 
371
157
  ## 📜 License
372
158
 
373
- ISC License © 2025 - Ameth Galarcio
374
-
159
+ ISC License © 2026 - Ameth Galarcio
@@ -1,5 +1,5 @@
1
1
  import { SendOptions } from "@builderbot/bot/dist/types";
2
- import { ReadMessage, SendButton, SendList, SendLocation, SendMedia, SendMessage, SendPresence, SendReaction } from "../interface/types";
2
+ import { ReadMessage, SendButton, SendList, SendLocation, SendMedia, SendMessage, SendPoll, SendPresence, SendReaction } from "../interface/types";
3
3
  export interface ProviderInterface {
4
4
  sendMessage?: (number: string, message: string, options?: SendOptions) => Promise<any>;
5
5
  sendText: (data: SendMessage) => Promise<any>;
@@ -13,6 +13,7 @@ export interface ProviderInterface {
13
13
  sendList: (data: SendList) => Promise<any>;
14
14
  sendPresence: (data: SendPresence) => Promise<any>;
15
15
  sendButton: (data: SendButton) => Promise<any>;
16
+ sendPoll: (data: SendPoll) => Promise<any>;
16
17
  sendLocation: (data: SendLocation) => Promise<any>;
17
18
  sendReaction: (data: SendReaction) => Promise<any>;
18
19
  readMessages: (data: ReadMessage) => Promise<any>;
@@ -80,6 +80,9 @@ export interface SendMessage {
80
80
  from: string;
81
81
  delay?: number;
82
82
  text?: string;
83
+ quoted?: any;
84
+ everyOne?: boolean;
85
+ mentioned?: string[];
83
86
  }
84
87
  export interface SendMedia extends SendMessage {
85
88
  mediaType?: "image" | "video" | "document" | "audio";
@@ -90,15 +93,54 @@ export interface SendPresence extends SendMessage {
90
93
  delay?: number;
91
94
  presence?: "composing" | "recording";
92
95
  }
96
+ export type TypeButton = 'reply' | 'copy' | 'url' | 'call' | 'pix';
97
+ export type BaseButton<T> = T & {
98
+ type: TypeButton;
99
+ id?: string;
100
+ displayText: string;
101
+ };
102
+ export type Button = BaseButton<{
103
+ type: 'reply';
104
+ displayText: string;
105
+ }> | BaseButton<{
106
+ type: 'url';
107
+ displayText: string;
108
+ url: string;
109
+ }> | BaseButton<{
110
+ type: 'call';
111
+ displayText: string;
112
+ phoneNumber: string;
113
+ }> | BaseButton<{
114
+ type: 'copy';
115
+ displayText: string;
116
+ copyText: string;
117
+ copyCode?: string;
118
+ }> | BaseButton<{
119
+ type: 'pix';
120
+ displayText: string;
121
+ keyType: KeyType;
122
+ key: string;
123
+ currency?: string;
124
+ name?: string;
125
+ }>;
93
126
  export interface SendButton extends SendMessage {
94
127
  title: string;
95
- body: string;
96
- description: string;
97
- footer: string;
98
- buttons: {
99
- type: "reply" | "url" | "call";
100
- text: string;
101
- }[];
128
+ thumbnailUrl?: string;
129
+ body?: string;
130
+ description?: string;
131
+ footer?: string;
132
+ buttons: (string | {
133
+ body: string;
134
+ } | {
135
+ reply: string;
136
+ } | Button)[];
137
+ }
138
+ export interface SendPoll extends SendMessage {
139
+ poll: {
140
+ name: string;
141
+ values: string[];
142
+ selectableCount?: number;
143
+ };
102
144
  }
103
145
  export interface SendLocation extends SendMessage {
104
146
  name: string;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gamastudio/sendwave-provider",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Librería para interactuar con Sendwave usando configuración dinámica.",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -2,7 +2,7 @@ import { ProviderClass } from "@builderbot/bot";
2
2
  import Queue from "queue-promise";
3
3
  import { SendWaveCore } from "./core";
4
4
  import { BotContext, BotCtxMiddlewareOptions } from "@builderbot/bot/dist/types";
5
- import { GlobalVendorArgs, ReadMessage, SendButton, SendList, SendLocation, SendMedia, SendMessage, SendPresence, SendReaction } from "../core/interface/types";
5
+ import { GlobalVendorArgs, ReadMessage, SendButton, SendList, SendLocation, SendMedia, SendMessage, SendPoll, SendPresence, SendReaction } from "../core/interface/types";
6
6
  import { SenderMessage } from "./sender";
7
7
  import { ParsedMessage } from "../core/interface";
8
8
  export declare class SendWaveProvider extends ProviderClass<SendWaveCore> {
@@ -55,6 +55,7 @@ export declare class SendWaveProvider extends ProviderClass<SendWaveCore> {
55
55
  sendPresence(data: SendPresence): Promise<import("axios").AxiosResponse<any, any, {}> | undefined>;
56
56
  sendVoice(data: SendMedia): Promise<import("axios").AxiosResponse<any, any, {}> | undefined>;
57
57
  sendButton(data: SendButton): Promise<import("axios").AxiosResponse<any, any, {}> | undefined>;
58
+ sendPoll(data: SendPoll): Promise<import("axios").AxiosResponse<any, any, {}> | undefined>;
58
59
  sendReaction(data: SendReaction): Promise<import("axios").AxiosResponse<any, any, {}> | undefined>;
59
60
  sendLocation(data: SendLocation): Promise<import("axios").AxiosResponse<any, any, {}> | undefined>;
60
61
  sendMedia(data: SendMedia): Promise<import("axios").AxiosResponse<any, any, {}> | undefined>;
@@ -195,6 +195,7 @@ class SendWaveProvider extends bot_1.ProviderClass {
195
195
  sendVoice: this.sendVoice,
196
196
  sendPresence: this.sendPresence,
197
197
  sendButton: this.sendButton,
198
+ sendPoll: this.sendPoll,
198
199
  readMessages: this.readMessages,
199
200
  provider: this,
200
201
  blacklist: opts === null || opts === void 0 ? void 0 : opts.blacklist,
@@ -495,6 +496,9 @@ class SendWaveProvider extends bot_1.ProviderClass {
495
496
  sendButton(data) {
496
497
  return this.sender.sendButton(data);
497
498
  }
499
+ sendPoll(data) {
500
+ return this.sender.sendPoll(data);
501
+ }
498
502
  sendReaction(data) {
499
503
  return this.sender.sendReaction(data);
500
504
  }
@@ -1,4 +1,4 @@
1
- import { GlobalVendorArgs, ProviderInterface, SendButton, SendList, SendMedia, SendMessage, SendPresence, SendLocation, SendReaction, ReadMessage } from "../core/interface";
1
+ import { GlobalVendorArgs, ProviderInterface, SendButton, SendList, SendMedia, SendMessage, SendPresence, SendPoll, SendLocation, SendReaction, ReadMessage } from "../core/interface";
2
2
  export declare class SenderMessage implements ProviderInterface {
3
3
  private sendwaveApi?;
4
4
  private globalVendorArgs?;
@@ -15,6 +15,7 @@ export declare class SenderMessage implements ProviderInterface {
15
15
  sendVideo(data: SendMedia): Promise<import("axios").AxiosResponse<any, any, {}> | undefined>;
16
16
  sendVoice(data: SendMedia): Promise<import("axios").AxiosResponse<any, any, {}> | undefined>;
17
17
  sendButton(data: SendButton): Promise<import("axios").AxiosResponse<any, any, {}> | undefined>;
18
+ sendPoll(data: SendPoll): Promise<import("axios").AxiosResponse<any, any, {}> | undefined>;
18
19
  sendLocation(data: SendLocation): Promise<import("axios").AxiosResponse<any, any, {}> | undefined>;
19
20
  sendReaction(data: SendReaction): Promise<import("axios").AxiosResponse<any, any, {}> | undefined>;
20
21
  readMessages(data: ReadMessage): Promise<import("axios").AxiosResponse<any, any, {}> | undefined>;
@@ -89,7 +89,7 @@ class SenderMessage {
89
89
  }
90
90
  }
91
91
  async sendList(data) {
92
- var _a, _b, _c, _d, _e;
92
+ var _a, _b, _c, _d, _e, _f;
93
93
  try {
94
94
  if (!(data === null || data === void 0 ? void 0 : data.from))
95
95
  throw new Error("sendList: falta 'from'");
@@ -126,11 +126,15 @@ class SenderMessage {
126
126
  footerText,
127
127
  buttonText: button,
128
128
  sections,
129
+ delay: data.delay || 2000,
130
+ quoted: data.quoted,
131
+ everyOne: data.everyOne || false,
132
+ mentioned: ((_c = data.mentioned) === null || _c === void 0 ? void 0 : _c.length) ? data.mentioned : [data.from],
129
133
  ...this.globalVendorArgs,
130
134
  }));
131
135
  }
132
136
  catch (err) {
133
- console.error("[sendList Error]", ((_e = (_d = (_c = err.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.response) === null || _e === void 0 ? void 0 : _e.message) || err.message);
137
+ console.error("[sendList Error]", ((_f = (_e = (_d = err.response) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.response) === null || _f === void 0 ? void 0 : _f.message) || err.message);
134
138
  }
135
139
  }
136
140
  async sendMedia(data) {
@@ -280,12 +284,6 @@ class SenderMessage {
280
284
  detectorMedia_1.detectorMedia.updateLimits(this.globalVendorArgs.payloadLimits.media);
281
285
  }
282
286
  const { media } = await detectorMedia_1.detectorMedia.processMedia(data.url);
283
- // try {
284
- // await this.sendPresence({
285
- // from: data.from,
286
- // presence: "recording",
287
- // });
288
- // } catch (error) {}
289
287
  return await ((_c = this.sendwaveApi) === null || _c === void 0 ? void 0 : _c.post(`/message/sendWhatsAppAudio/${(_d = this.globalVendorArgs) === null || _d === void 0 ? void 0 : _d.name}`, {
290
288
  number: data.from,
291
289
  audio: media,
@@ -315,31 +313,85 @@ class SenderMessage {
315
313
  }
316
314
  }
317
315
  async sendButton(data) {
318
- var _a, _b, _c, _d, _e;
316
+ var _a, _b, _c, _d, _e, _f;
319
317
  try {
320
318
  return await ((_a = this.sendwaveApi) === null || _a === void 0 ? void 0 : _a.post(`/message/sendButtons/${(_b = this.globalVendorArgs) === null || _b === void 0 ? void 0 : _b.name}`, {
321
319
  number: data.from,
320
+ thumbnailUrl: data.thumbnailUrl,
322
321
  title: data.title,
323
322
  body: data.body,
324
323
  description: data.description,
325
324
  footer: data.footer,
326
- buttons: data.buttons.map((button, index) => ({
327
- type: button.type,
328
- title: button.text,
329
- displayText: button.text,
330
- id: `${index + 1}`,
331
- })),
325
+ buttons: data.buttons.map((button, index) => {
326
+ let type = "reply";
327
+ let displayText = "";
328
+ let rest = {};
329
+ if (typeof button === "string") {
330
+ displayText = button;
331
+ }
332
+ else if (button.body) {
333
+ displayText = button.body;
334
+ type = button.type || "reply";
335
+ rest = button;
336
+ }
337
+ else if (button.reply) {
338
+ displayText = button.reply;
339
+ type = "reply";
340
+ rest = button;
341
+ }
342
+ else {
343
+ displayText = button.displayText || button.text || "";
344
+ type = button.type || "reply";
345
+ rest = button;
346
+ }
347
+ const base = {
348
+ type,
349
+ displayText,
350
+ id: button.id || `${index + 1}`,
351
+ ...rest
352
+ };
353
+ // Clean up unwanted properties
354
+ delete base.text;
355
+ delete base.body;
356
+ delete base.reply;
357
+ return base;
358
+ }),
359
+ delay: data.delay || 2000,
360
+ quoted: data.quoted,
361
+ everyOne: data.everyOne || false,
362
+ mentioned: ((_c = data.mentioned) === null || _c === void 0 ? void 0 : _c.length) ? data.mentioned : [data.from],
332
363
  ...this.globalVendorArgs,
333
364
  }));
334
365
  }
335
366
  catch (error) {
336
- const msg = ((_e = (_d = (_c = error === null || error === void 0 ? void 0 : error.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.response) === null || _e === void 0 ? void 0 : _e.message) ||
367
+ const msg = ((_f = (_e = (_d = error === null || error === void 0 ? void 0 : error.response) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.response) === null || _f === void 0 ? void 0 : _f.message) ||
337
368
  (error === null || error === void 0 ? void 0 : error.message) ||
338
369
  "Unknown error";
339
370
  console.error(`[sendButton Error] ${msg}`);
340
371
  throw new Error(msg);
341
372
  }
342
373
  }
374
+ async sendPoll(data) {
375
+ var _a, _b, _c, _d, _e, _f;
376
+ try {
377
+ return await ((_a = this.sendwaveApi) === null || _a === void 0 ? void 0 : _a.post(`/message/sendPoll/${(_b = this.globalVendorArgs) === null || _b === void 0 ? void 0 : _b.name}`, {
378
+ number: data.from,
379
+ name: data.poll.name,
380
+ selectableCount: data.poll.selectableCount || 1,
381
+ values: data.poll.values,
382
+ delay: data.delay || 2000,
383
+ quoted: data.quoted,
384
+ everyOne: data.everyOne || false,
385
+ mentioned: ((_c = data.mentioned) === null || _c === void 0 ? void 0 : _c.length) ? data.mentioned : [data.from],
386
+ ...this.globalVendorArgs,
387
+ }));
388
+ }
389
+ catch (e) {
390
+ const msg = ((_f = (_e = (_d = e === null || e === void 0 ? void 0 : e.response) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.response) === null || _f === void 0 ? void 0 : _f.message) || (e === null || e === void 0 ? void 0 : e.message) || "Unknown error";
391
+ console.error(`[sendPoll Error] ${msg}`);
392
+ throw new Error(msg);
393
+ }
394
+ }
343
395
  async sendLocation(data) {
344
396
  var _a, _b, _c, _d, _e;
345
397
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gamastudio/sendwave-provider",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Librería para interactuar con Sendwave usando configuración dinámica.",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",