@green-api/greenapi-integration 0.8.0 → 0.9.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.
|
@@ -110,6 +110,10 @@ class BaseAdapter {
|
|
|
110
110
|
return client.sendLocation(transformedMessage);
|
|
111
111
|
case "forward":
|
|
112
112
|
return client.forwardMessages(transformedMessage);
|
|
113
|
+
case "interactive-buttons":
|
|
114
|
+
return client.sendInteractiveButtons(transformedMessage);
|
|
115
|
+
case "interactive-buttons-reply":
|
|
116
|
+
return client.sendInteractiveButtonsReply(transformedMessage);
|
|
113
117
|
default:
|
|
114
118
|
throw new Error("Invalid file message format");
|
|
115
119
|
}
|
|
@@ -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, SendInteractiveButtons, SendInteractiveButtonsReply, SendTextStatus, SendVoiceStatus, SendMediaStatus, GetStatusStatisticResponse } from "../types/types";
|
|
1
|
+
import { Instance, Settings, SendMessage, SendFileByUrl, SendFileByUpload, SendPoll, StateInstance, Reboot, Logout, QR, SendResponse, SendFileByUploadResponse, SetSettingsResponse, GetAuthorizationCode, SetProfilePicture, WaSettings, AccountSettings, UploadFile, SendLocation, SendContact, ForwardMessages, ForwardMessagesResponse, QueueMessage, ClearMessagesQueue, ReadChatResponse, ReadChat, CheckWhatsapp, CheckWhatsappResponse, CheckAccount, CheckAccountResponse, 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.
|
|
@@ -261,6 +261,7 @@ export declare class GreenApiClient {
|
|
|
261
261
|
*
|
|
262
262
|
* @returns Promise resolving to WhatsApp settings
|
|
263
263
|
*/
|
|
264
|
+
getAccountSettings(): Promise<AccountSettings>;
|
|
264
265
|
getWaSettings(): Promise<WaSettings>;
|
|
265
266
|
/**
|
|
266
267
|
* Sets the profile picture for the WhatsApp account.
|
|
@@ -356,6 +357,14 @@ export declare class GreenApiClient {
|
|
|
356
357
|
* ```
|
|
357
358
|
*/
|
|
358
359
|
checkWhatsapp(params: CheckWhatsapp): Promise<CheckWhatsappResponse>;
|
|
360
|
+
/**
|
|
361
|
+
* Checks whether a messenger account exists for a phone number or username (Telegram, MAX).
|
|
362
|
+
*
|
|
363
|
+
* @param params - Phone number in international format, or a Telegram username starting with "@"
|
|
364
|
+
* @returns Promise resolving to the existence flag and, when the account exists, its chat id
|
|
365
|
+
* @throws {Error} If neither phoneNumber nor username is given
|
|
366
|
+
*/
|
|
367
|
+
checkAccount(params: CheckAccount): Promise<CheckAccountResponse>;
|
|
359
368
|
/**
|
|
360
369
|
* Gets a user or group chat avatar.
|
|
361
370
|
*
|
|
@@ -7,6 +7,7 @@ exports.GreenApiClient = void 0;
|
|
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
|
8
8
|
const errors_1 = require("./errors");
|
|
9
9
|
const logger_1 = require("./logger");
|
|
10
|
+
const defaults_1 = require("../defaults");
|
|
10
11
|
/**
|
|
11
12
|
* Client for direct interaction with GREEN-API's WhatsApp gateway.
|
|
12
13
|
* Provides methods for sending messages, managing instances, and handling files.
|
|
@@ -35,8 +36,8 @@ class GreenApiClient {
|
|
|
35
36
|
*/
|
|
36
37
|
constructor(instance) {
|
|
37
38
|
this.instance = instance;
|
|
38
|
-
this.baseUrl = "https://api.green-api.com";
|
|
39
39
|
this.gaLogger = logger_1.GreenApiLogger.getInstance(GreenApiClient.name);
|
|
40
|
+
this.baseUrl = (instance.apiUrl || defaults_1.DEFAULT_API_URL).replace(/\/+$/, "");
|
|
40
41
|
this.client = axios_1.default.create({
|
|
41
42
|
baseURL: this.buildUrl(),
|
|
42
43
|
});
|
|
@@ -64,7 +65,7 @@ class GreenApiClient {
|
|
|
64
65
|
return response.data;
|
|
65
66
|
}
|
|
66
67
|
catch (error) {
|
|
67
|
-
throw new errors_1.IntegrationError(`Failed to ${endpoint.replace(/([A-Z])/g, " $1").toLowerCase()}: ${error.message}. ${JSON.stringify(error.response?.data)}`, "INTEGRATION_ERROR");
|
|
68
|
+
throw new errors_1.IntegrationError(`Failed to ${endpoint.replace(/([A-Z])/g, " $1").toLowerCase()}: ${error.message}. ${JSON.stringify(error.response?.data)}`, "INTEGRATION_ERROR", error.response?.status ?? 500, error.response?.data);
|
|
68
69
|
}
|
|
69
70
|
}
|
|
70
71
|
async makeFileUploadRequest(endpoint, formData, headers) {
|
|
@@ -142,7 +143,7 @@ class GreenApiClient {
|
|
|
142
143
|
*/
|
|
143
144
|
async sendFileByUpload(message) {
|
|
144
145
|
const formData = new FormData();
|
|
145
|
-
formData.append("file", message.file.data);
|
|
146
|
+
formData.append("file", message.file.data, message.file.fileName);
|
|
146
147
|
formData.append("chatId", message.chatId);
|
|
147
148
|
formData.append("fileName", message.file.fileName);
|
|
148
149
|
if (message.caption)
|
|
@@ -383,6 +384,9 @@ class GreenApiClient {
|
|
|
383
384
|
*
|
|
384
385
|
* @returns Promise resolving to WhatsApp settings
|
|
385
386
|
*/
|
|
387
|
+
async getAccountSettings() {
|
|
388
|
+
return this.makeRequest("get", "getAccountSettings");
|
|
389
|
+
}
|
|
386
390
|
async getWaSettings() {
|
|
387
391
|
return this.makeRequest("get", "getWaSettings");
|
|
388
392
|
}
|
|
@@ -521,6 +525,22 @@ class GreenApiClient {
|
|
|
521
525
|
}
|
|
522
526
|
return this.makeRequest("post", "checkWhatsapp", params);
|
|
523
527
|
}
|
|
528
|
+
/**
|
|
529
|
+
* Checks whether a messenger account exists for a phone number or username (Telegram, MAX).
|
|
530
|
+
*
|
|
531
|
+
* @param params - Phone number in international format, or a Telegram username starting with "@"
|
|
532
|
+
* @returns Promise resolving to the existence flag and, when the account exists, its chat id
|
|
533
|
+
* @throws {Error} If neither phoneNumber nor username is given
|
|
534
|
+
*/
|
|
535
|
+
async checkAccount(params) {
|
|
536
|
+
if (params.phoneNumber === undefined && !params.username) {
|
|
537
|
+
throw new Error("Either phoneNumber or username is required");
|
|
538
|
+
}
|
|
539
|
+
if (params.phoneNumber !== undefined && !Number.isInteger(params.phoneNumber)) {
|
|
540
|
+
throw new Error("Phone number must contain only digits");
|
|
541
|
+
}
|
|
542
|
+
return this.makeRequest("post", "checkAccount", params);
|
|
543
|
+
}
|
|
524
544
|
/**
|
|
525
545
|
* Gets a user or group chat avatar.
|
|
526
546
|
*
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const DEFAULT_API_URL = "https://api.green-api.com";
|
package/dist/defaults.js
ADDED
package/dist/types/types.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export interface BaseInstance {
|
|
|
7
7
|
apiTokenInstance: string;
|
|
8
8
|
stateInstance?: InstanceState | null;
|
|
9
9
|
settings?: Settings | Record<string, any> | null;
|
|
10
|
+
apiUrl?: string | null;
|
|
10
11
|
}
|
|
11
12
|
/**
|
|
12
13
|
* Extended instance interface that allows for additional platform-specific properties.
|
|
@@ -71,7 +72,7 @@ export interface SendInteractiveButtons extends BaseMessage {
|
|
|
71
72
|
body: string;
|
|
72
73
|
footer?: string;
|
|
73
74
|
buttons: Array<{
|
|
74
|
-
type: "copy" | "call" | "url"
|
|
75
|
+
type: "copy" | "call" | "url";
|
|
75
76
|
buttonId: string;
|
|
76
77
|
buttonText: string;
|
|
77
78
|
copyCode?: string;
|
|
@@ -107,6 +108,10 @@ export type Message = (SendMessage & {
|
|
|
107
108
|
type: "contact";
|
|
108
109
|
}) | (ForwardMessages & {
|
|
109
110
|
type: "forward";
|
|
111
|
+
}) | (SendInteractiveButtons & {
|
|
112
|
+
type: "interactive-buttons";
|
|
113
|
+
}) | (SendInteractiveButtonsReply & {
|
|
114
|
+
type: "interactive-buttons-reply";
|
|
110
115
|
});
|
|
111
116
|
export type QueueMessageType = "sendMessage" | "sendPoll" | "sendFileByUrl" | "sendLocation" | "sendContact" | "ForwardMessages";
|
|
112
117
|
export type QueueMessageBody = SendMessage | SendPoll | SendFileByUrl | SendLocation | SendContact | ForwardMessages;
|
|
@@ -510,6 +515,7 @@ export interface MessageWebhook {
|
|
|
510
515
|
chatName: string;
|
|
511
516
|
senderName: string;
|
|
512
517
|
senderContactName?: string;
|
|
518
|
+
senderPhoneNumber?: number;
|
|
513
519
|
};
|
|
514
520
|
messageData: WebhookMessageData & {
|
|
515
521
|
quotedMessage?: QuotedMessage;
|
|
@@ -538,6 +544,7 @@ export type GreenApiWebhook = MessageWebhook | OutgoingMessageStatusWebhook | St
|
|
|
538
544
|
*/
|
|
539
545
|
export interface Settings {
|
|
540
546
|
wid?: string;
|
|
547
|
+
typeInstance?: string;
|
|
541
548
|
webhookUrl?: string;
|
|
542
549
|
webhookUrlToken?: string;
|
|
543
550
|
delaySendMessagesMilliseconds?: number;
|
|
@@ -574,6 +581,18 @@ export interface CheckWhatsapp {
|
|
|
574
581
|
export interface CheckWhatsappResponse {
|
|
575
582
|
existsWhatsapp: boolean;
|
|
576
583
|
}
|
|
584
|
+
export interface CheckAccount {
|
|
585
|
+
phoneNumber?: number;
|
|
586
|
+
username?: string;
|
|
587
|
+
force?: boolean;
|
|
588
|
+
}
|
|
589
|
+
export interface CheckAccountResponse {
|
|
590
|
+
exist: boolean;
|
|
591
|
+
chatId: string;
|
|
592
|
+
username?: string;
|
|
593
|
+
phoneNumber?: number;
|
|
594
|
+
fromCache?: boolean;
|
|
595
|
+
}
|
|
577
596
|
export interface GetAvatar {
|
|
578
597
|
chatId: string;
|
|
579
598
|
}
|
|
@@ -583,10 +602,13 @@ export interface GetAvatarResponse {
|
|
|
583
602
|
}
|
|
584
603
|
export type ContactType = "user" | "group";
|
|
585
604
|
export interface Contact {
|
|
586
|
-
id
|
|
605
|
+
id?: string;
|
|
606
|
+
chatId?: string;
|
|
587
607
|
name: string;
|
|
588
608
|
contactName: string;
|
|
589
609
|
type: ContactType;
|
|
610
|
+
phoneNumber?: number;
|
|
611
|
+
username?: string;
|
|
590
612
|
}
|
|
591
613
|
export interface ProductImageUrls {
|
|
592
614
|
requested: string;
|
|
@@ -641,7 +663,7 @@ export interface SetDisappearingChatResponse {
|
|
|
641
663
|
/**
|
|
642
664
|
* Represents an instance state in the GREEN-API system.
|
|
643
665
|
*/
|
|
644
|
-
export type InstanceState = "notAuthorized" | "authorized" | "blocked" | "starting" | "yellowCard";
|
|
666
|
+
export type InstanceState = "notAuthorized" | "authorized" | "blocked" | "starting" | "yellowCard" | "suspended" | "pendingPassword";
|
|
645
667
|
export interface StateInstance {
|
|
646
668
|
stateInstance: InstanceState;
|
|
647
669
|
}
|
|
@@ -672,6 +694,16 @@ export interface WaSettings {
|
|
|
672
694
|
stateInstance: InstanceState;
|
|
673
695
|
deviceId: string;
|
|
674
696
|
}
|
|
697
|
+
export interface AccountSettings {
|
|
698
|
+
avatar: string;
|
|
699
|
+
phone: string;
|
|
700
|
+
stateInstance: InstanceState;
|
|
701
|
+
chatId: string;
|
|
702
|
+
historySyncProgress: number;
|
|
703
|
+
username?: string;
|
|
704
|
+
logoutProcess?: boolean;
|
|
705
|
+
suspendedUntil?: number;
|
|
706
|
+
}
|
|
675
707
|
export interface SetProfilePicture {
|
|
676
708
|
reason: string | null;
|
|
677
709
|
urlAvatar: string;
|