@green-api/greenapi-integration 0.7.2 → 0.8.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.
@@ -1,4 +1,4 @@
1
- import { Instance, Settings, SendMessage, SendFileByUrl, SendFileByUpload, SendPoll, StateInstance, Reboot, Logout, QR, SendResponse, SendFileByUploadResponse, SetSettingsResponse, GetAuthorizationCode, SetProfilePicture, WaSettings, UploadFile, SendLocation, SendContact, ForwardMessages, ForwardMessagesResponse, QueueMessage, ClearMessagesQueue, ReadChatResponse, ReadChat, CheckWhatsapp, CheckWhatsappResponse, GetAvatarResponse, GetAvatar, Contact, ContactInfo, ArchiveChat, UnarchiveChat, SetDisappearingChat, SetDisappearingChatResponse, CreateGroupResponse, CreateGroup, UpdateGroupName, UpdateGroupNameResponse, GetGroupData, GroupData, AddGroupParticipant, AddGroupParticipantResponse, RemoveGroupParticipant, RemoveGroupParticipantResponse, SetGroupAdmin, SetGroupAdminResponse, RemoveAdminResponse, RemoveAdmin, SetGroupPicture, SetGroupPictureResponse, LeaveGroup, LeaveGroupResponse, GetMessage, JournalResponse, GetChatHistory, IncomingJournalResponse, OutgoingJournalResponse } from "../types/types";
1
+ import { Instance, Settings, SendMessage, SendFileByUrl, SendFileByUpload, SendPoll, StateInstance, Reboot, Logout, QR, SendResponse, SendFileByUploadResponse, SetSettingsResponse, GetAuthorizationCode, SetProfilePicture, WaSettings, UploadFile, SendLocation, SendContact, ForwardMessages, ForwardMessagesResponse, QueueMessage, ClearMessagesQueue, ReadChatResponse, ReadChat, CheckWhatsapp, CheckWhatsappResponse, GetAvatarResponse, GetAvatar, Contact, ContactInfo, ArchiveChat, UnarchiveChat, SetDisappearingChat, SetDisappearingChatResponse, CreateGroupResponse, CreateGroup, UpdateGroupName, UpdateGroupNameResponse, GetGroupData, GroupData, AddGroupParticipant, AddGroupParticipantResponse, RemoveGroupParticipant, RemoveGroupParticipantResponse, SetGroupAdmin, SetGroupAdminResponse, RemoveAdminResponse, RemoveAdmin, SetGroupPicture, SetGroupPictureResponse, LeaveGroup, LeaveGroupResponse, GetMessage, JournalResponse, GetChatHistory, IncomingJournalResponse, OutgoingJournalResponse, SendInteractiveButtons, SendInteractiveButtonsReply, SendTextStatus, SendVoiceStatus, SendMediaStatus, GetStatusStatisticResponse } from "../types/types";
2
2
  /**
3
3
  * Client for direct interaction with GREEN-API's WhatsApp gateway.
4
4
  * Provides methods for sending messages, managing instances, and handling files.
@@ -149,6 +149,76 @@ export declare class GreenApiClient {
149
149
  * ```
150
150
  */
151
151
  sendContact(message: SendContact): Promise<SendResponse>;
152
+ /**
153
+ * Sends interactive buttons to a WhatsApp chat.
154
+ * Supports copy, call, url, and reply button types.
155
+ *
156
+ * @param message - Interactive buttons message data
157
+ * @returns Promise resolving to send response
158
+ *
159
+ * @example
160
+ * ```typescript
161
+ * await client.sendInteractiveButtons({
162
+ * chatId: "1234567890@c.us",
163
+ * header: "Choose an option",
164
+ * body: "Please select one of the following:",
165
+ * footer: "Powered by GREEN-API",
166
+ * buttons: [
167
+ * {
168
+ * type: "copy",
169
+ * buttonId: "1",
170
+ * buttonText: "Copy Code",
171
+ * copyCode: "DISCOUNT50"
172
+ * },
173
+ * {
174
+ * type: "call",
175
+ * buttonId: "2",
176
+ * buttonText: "Call Us",
177
+ * phoneNumber: "1234567890"
178
+ * },
179
+ * {
180
+ * type: "url",
181
+ * buttonId: "3",
182
+ * buttonText: "Visit Website",
183
+ * url: "https://example.com"
184
+ * }
185
+ * ]
186
+ * });
187
+ * ```
188
+ */
189
+ sendInteractiveButtons(message: SendInteractiveButtons): Promise<SendResponse>;
190
+ /**
191
+ * Sends interactive reply buttons to a WhatsApp chat.
192
+ * These buttons return text to the chat when pressed.
193
+ *
194
+ * @param message - Interactive reply buttons message data
195
+ * @returns Promise resolving to send response
196
+ *
197
+ * @example
198
+ * ```typescript
199
+ * await client.sendInteractiveButtonsReply({
200
+ * chatId: "1234567890@c.us",
201
+ * header: "Survey",
202
+ * body: "How satisfied are you with our service?",
203
+ * footer: "Your feedback matters",
204
+ * buttons: [
205
+ * {
206
+ * buttonId: "1",
207
+ * buttonText: "Very Satisfied"
208
+ * },
209
+ * {
210
+ * buttonId: "2",
211
+ * buttonText: "Satisfied"
212
+ * },
213
+ * {
214
+ * buttonId: "3",
215
+ * buttonText: "Needs Improvement"
216
+ * }
217
+ * ]
218
+ * });
219
+ * ```
220
+ */
221
+ sendInteractiveButtonsReply(message: SendInteractiveButtonsReply): Promise<SendResponse>;
152
222
  /**
153
223
  * Reboots the GREEN-API instance.
154
224
  *
@@ -438,4 +508,84 @@ export declare class GreenApiClient {
438
508
  * @returns Promise resolving to array of outgoing messages
439
509
  */
440
510
  lastOutgoingMessages(minutes?: number): Promise<OutgoingJournalResponse[]>;
511
+ /**
512
+ * The method is aimed for sending a text status
513
+ *
514
+ * @param status - Status data containing message, backgroundColor (optional), font (optional), participants (optional)
515
+ * @returns Promise resolving to send response with message ID
516
+ *
517
+ * @example
518
+ * ```typescript
519
+ * await client.sendTextStatus({
520
+ * message: "I use Green-API to send this status!",
521
+ * backgroundColor: "#228B22", // optional
522
+ * font: "SERIF", // optional
523
+ * participants: ["70000001234@c.us", "440000001234@c.us"] // optional
524
+ * });
525
+ * ```
526
+ */
527
+ sendTextStatus(status: SendTextStatus): Promise<SendResponse>;
528
+ /**
529
+ * The method is aimed for sending a voice status
530
+ *
531
+ * @param status - Status data containing urlFile, fileName, backgroundColor (optional), participants (optional)
532
+ * @returns Promise resolving to send response with message ID
533
+ *
534
+ * @example
535
+ * ```typescript
536
+ * await client.sendVoiceStatus({
537
+ * urlFile: "https://my.site.com/img/horse.mp3",
538
+ * fileName: "horse.mp3",
539
+ * backgroundColor: "#228B22", // optional
540
+ * participants: ["70000001234@c.us", "440000001234@c.us"] // optional
541
+ * });
542
+ * ```
543
+ */
544
+ sendVoiceStatus(status: SendVoiceStatus): Promise<SendResponse>;
545
+ /**
546
+ * The method is aimed for sending a pictures or video status
547
+ *
548
+ * @param status - Message data containing urlFile, fileName, backgroundColor (optional), participants (optional)
549
+ * @returns Promise resolving to send response with message ID
550
+ *
551
+ * @example
552
+ * ```typescript
553
+ * await client.sendVoiceStatus({
554
+ * urlFile: "https://my.site.com/img/horse.png",
555
+ * fileName: "horse.png",
556
+ * caption: "Little horse",
557
+ * participants: ["70000001234@c.us", "440000001234@c.us"] // optional
558
+ * });
559
+ * ```
560
+ */
561
+ sendMediaStatus(status: SendMediaStatus): Promise<SendResponse>;
562
+ /**
563
+ * The method returns the incoming status messages of the instance.
564
+ * In the default mode the incoming status messages for 24 hours are returned.
565
+ * Note: Requires "Receive webhooks" setting to be enabled.
566
+ * Messages can take up to 2 minutes to appear in history.
567
+ *
568
+ * @param minutes - Optional time period in minutes
569
+ * @returns Promise resolving to array of incoming statuses
570
+ */
571
+ getIncomingStatuses(minutes?: number): Promise<IncomingJournalResponse[]>;
572
+ /**
573
+ * The method returns the outgoing statuses of the account.
574
+ * In the default mode the outgoing status messages for 24 hours are returned.
575
+ * Note: Requires "Receive webhooks" setting to be enabled.
576
+ * Messages can take up to 2 minutes to appear in history.
577
+ *
578
+ * @param minutes - Optional time period in minutes
579
+ * @returns Promise resolving to array of outgoing statuses
580
+ */
581
+ getOutgoingStatuses(minutes?: number): Promise<OutgoingJournalResponse[]>;
582
+ /**
583
+ * The method returns an array of recipients marked sent/delivered/read for a given status.
584
+ * Note: Requires "Receive webhooks" setting to be enabled.
585
+ * Messages can take up to 2 minutes to appear in history.
586
+ *
587
+ * @param idMessage - Status message ID
588
+ * @returns Promise resolving to array participant, timestamp, status
589
+ */
590
+ getStatusStatistic(idMessage?: string): Promise<GetStatusStatisticResponse[]>;
441
591
  }
@@ -241,6 +241,94 @@ class GreenApiClient {
241
241
  quotedMessageId: message.quotedMessageId,
242
242
  });
243
243
  }
244
+ /**
245
+ * Sends interactive buttons to a WhatsApp chat.
246
+ * Supports copy, call, url, and reply button types.
247
+ *
248
+ * @param message - Interactive buttons message data
249
+ * @returns Promise resolving to send response
250
+ *
251
+ * @example
252
+ * ```typescript
253
+ * await client.sendInteractiveButtons({
254
+ * chatId: "1234567890@c.us",
255
+ * header: "Choose an option",
256
+ * body: "Please select one of the following:",
257
+ * footer: "Powered by GREEN-API",
258
+ * buttons: [
259
+ * {
260
+ * type: "copy",
261
+ * buttonId: "1",
262
+ * buttonText: "Copy Code",
263
+ * copyCode: "DISCOUNT50"
264
+ * },
265
+ * {
266
+ * type: "call",
267
+ * buttonId: "2",
268
+ * buttonText: "Call Us",
269
+ * phoneNumber: "1234567890"
270
+ * },
271
+ * {
272
+ * type: "url",
273
+ * buttonId: "3",
274
+ * buttonText: "Visit Website",
275
+ * url: "https://example.com"
276
+ * }
277
+ * ]
278
+ * });
279
+ * ```
280
+ */
281
+ async sendInteractiveButtons(message) {
282
+ return this.makeRequest("post", "sendInteractiveButtons", {
283
+ chatId: message.chatId,
284
+ header: message.header,
285
+ body: message.body,
286
+ footer: message.footer,
287
+ buttons: message.buttons,
288
+ quotedMessageId: message.quotedMessageId,
289
+ });
290
+ }
291
+ /**
292
+ * Sends interactive reply buttons to a WhatsApp chat.
293
+ * These buttons return text to the chat when pressed.
294
+ *
295
+ * @param message - Interactive reply buttons message data
296
+ * @returns Promise resolving to send response
297
+ *
298
+ * @example
299
+ * ```typescript
300
+ * await client.sendInteractiveButtonsReply({
301
+ * chatId: "1234567890@c.us",
302
+ * header: "Survey",
303
+ * body: "How satisfied are you with our service?",
304
+ * footer: "Your feedback matters",
305
+ * buttons: [
306
+ * {
307
+ * buttonId: "1",
308
+ * buttonText: "Very Satisfied"
309
+ * },
310
+ * {
311
+ * buttonId: "2",
312
+ * buttonText: "Satisfied"
313
+ * },
314
+ * {
315
+ * buttonId: "3",
316
+ * buttonText: "Needs Improvement"
317
+ * }
318
+ * ]
319
+ * });
320
+ * ```
321
+ */
322
+ async sendInteractiveButtonsReply(message) {
323
+ return this.makeRequest("post", "sendInteractiveButtonsReply", {
324
+ chatId: message.chatId,
325
+ header: message.header,
326
+ body: message.body,
327
+ footer: message.footer,
328
+ buttons: message.buttons,
329
+ quotedMessageId: message.quotedMessageId,
330
+ });
331
+ }
244
332
  /**
245
333
  * Reboots the GREEN-API instance.
246
334
  *
@@ -626,5 +714,112 @@ class GreenApiClient {
626
714
  async lastOutgoingMessages(minutes) {
627
715
  return this.makeRequest("get", "lastOutgoingMessages", undefined, minutes ? { minutes } : undefined);
628
716
  }
717
+ /**
718
+ * The method is aimed for sending a text status
719
+ *
720
+ * @param status - Status data containing message, backgroundColor (optional), font (optional), participants (optional)
721
+ * @returns Promise resolving to send response with message ID
722
+ *
723
+ * @example
724
+ * ```typescript
725
+ * await client.sendTextStatus({
726
+ * message: "I use Green-API to send this status!",
727
+ * backgroundColor: "#228B22", // optional
728
+ * font: "SERIF", // optional
729
+ * participants: ["70000001234@c.us", "440000001234@c.us"] // optional
730
+ * });
731
+ * ```
732
+ */
733
+ async sendTextStatus(status) {
734
+ return this.makeRequest("post", "sendTextStatus", {
735
+ message: status.message,
736
+ backgroundColor: status.backgroundColor,
737
+ font: status.font,
738
+ participants: status.participants,
739
+ });
740
+ }
741
+ /**
742
+ * The method is aimed for sending a voice status
743
+ *
744
+ * @param status - Status data containing urlFile, fileName, backgroundColor (optional), participants (optional)
745
+ * @returns Promise resolving to send response with message ID
746
+ *
747
+ * @example
748
+ * ```typescript
749
+ * await client.sendVoiceStatus({
750
+ * urlFile: "https://my.site.com/img/horse.mp3",
751
+ * fileName: "horse.mp3",
752
+ * backgroundColor: "#228B22", // optional
753
+ * participants: ["70000001234@c.us", "440000001234@c.us"] // optional
754
+ * });
755
+ * ```
756
+ */
757
+ async sendVoiceStatus(status) {
758
+ return this.makeRequest("post", "sendVoiceStatus", {
759
+ urlFile: status.urlFile,
760
+ fileName: status.fileName,
761
+ backgroundColor: status.backgroundColor,
762
+ participants: status.participants,
763
+ });
764
+ }
765
+ /**
766
+ * The method is aimed for sending a pictures or video status
767
+ *
768
+ * @param status - Message data containing urlFile, fileName, backgroundColor (optional), participants (optional)
769
+ * @returns Promise resolving to send response with message ID
770
+ *
771
+ * @example
772
+ * ```typescript
773
+ * await client.sendVoiceStatus({
774
+ * urlFile: "https://my.site.com/img/horse.png",
775
+ * fileName: "horse.png",
776
+ * caption: "Little horse",
777
+ * participants: ["70000001234@c.us", "440000001234@c.us"] // optional
778
+ * });
779
+ * ```
780
+ */
781
+ async sendMediaStatus(status) {
782
+ return this.makeRequest("post", "sendMediaStatus", {
783
+ urlFile: status.urlFile,
784
+ fileName: status.fileName,
785
+ caption: status.caption,
786
+ participants: status.participants,
787
+ });
788
+ }
789
+ /**
790
+ * The method returns the incoming status messages of the instance.
791
+ * In the default mode the incoming status messages for 24 hours are returned.
792
+ * Note: Requires "Receive webhooks" setting to be enabled.
793
+ * Messages can take up to 2 minutes to appear in history.
794
+ *
795
+ * @param minutes - Optional time period in minutes
796
+ * @returns Promise resolving to array of incoming statuses
797
+ */
798
+ async getIncomingStatuses(minutes) {
799
+ return this.makeRequest("get", "getIncomingStatuses", undefined, minutes ? { minutes } : undefined);
800
+ }
801
+ /**
802
+ * The method returns the outgoing statuses of the account.
803
+ * In the default mode the outgoing status messages for 24 hours are returned.
804
+ * Note: Requires "Receive webhooks" setting to be enabled.
805
+ * Messages can take up to 2 minutes to appear in history.
806
+ *
807
+ * @param minutes - Optional time period in minutes
808
+ * @returns Promise resolving to array of outgoing statuses
809
+ */
810
+ async getOutgoingStatuses(minutes) {
811
+ return this.makeRequest("get", "getOutgoingStatuses", undefined, minutes ? { minutes } : undefined);
812
+ }
813
+ /**
814
+ * The method returns an array of recipients marked sent/delivered/read for a given status.
815
+ * Note: Requires "Receive webhooks" setting to be enabled.
816
+ * Messages can take up to 2 minutes to appear in history.
817
+ *
818
+ * @param idMessage - Status message ID
819
+ * @returns Promise resolving to array participant, timestamp, status
820
+ */
821
+ async getStatusStatistic(idMessage) {
822
+ return this.makeRequest("get", "getStatusStatistic", undefined, idMessage ? { idMessage } : undefined);
823
+ }
629
824
  }
630
825
  exports.GreenApiClient = GreenApiClient;
@@ -66,6 +66,28 @@ export interface SendPoll extends BaseMessage {
66
66
  options: PollOption[];
67
67
  multipleAnswers?: boolean;
68
68
  }
69
+ export interface SendInteractiveButtons extends BaseMessage {
70
+ header?: string;
71
+ body: string;
72
+ footer?: string;
73
+ buttons: Array<{
74
+ type: "copy" | "call" | "url";
75
+ buttonId: string;
76
+ buttonText: string;
77
+ copyCode?: string;
78
+ phoneNumber?: string;
79
+ url?: string;
80
+ }>;
81
+ }
82
+ export interface SendInteractiveButtonsReply extends BaseMessage {
83
+ header?: string;
84
+ body: string;
85
+ footer?: string;
86
+ buttons: Array<{
87
+ buttonId: string;
88
+ buttonText: string;
89
+ }>;
90
+ }
69
91
  export interface ForwardMessages {
70
92
  chatId: string;
71
93
  chatIdFrom: string;
@@ -741,3 +763,26 @@ export interface BaseUser {
741
763
  id: number | bigint | string;
742
764
  [key: string]: any;
743
765
  }
766
+ export interface SendTextStatus {
767
+ message: string;
768
+ backgroundColor: string | null;
769
+ font: string | null;
770
+ participants: string[] | null;
771
+ }
772
+ export interface SendVoiceStatus {
773
+ urlFile: string;
774
+ fileName: string;
775
+ backgroundColor: string | null;
776
+ participants: string[] | null;
777
+ }
778
+ export interface SendMediaStatus {
779
+ urlFile: string;
780
+ fileName: string;
781
+ caption: string | null;
782
+ participants: string[] | null;
783
+ }
784
+ export interface GetStatusStatisticResponse {
785
+ timestamp: number;
786
+ participant: string;
787
+ status: string;
788
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@green-api/greenapi-integration",
3
- "version": "0.7.2",
3
+ "version": "0.8.1",
4
4
  "description": "GREEN-API Integration library",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",