@raphaelvserafim/client-api-whatsapp 1.0.6 → 1.0.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.
@@ -1,4 +1,4 @@
1
- import { Init, WebhookBody, TypeMessage, StatusPresence, Contact, Section } from './model';
1
+ import { Init, WebhookBody, TypeMessage, StatusPresence, Contact, Section, InfoInstance, SendMessageRoot } from './model';
2
2
  export declare class WhatsApp {
3
3
  private readonly server;
4
4
  private readonly key;
@@ -8,9 +8,9 @@ export declare class WhatsApp {
8
8
  constructor(data: Init);
9
9
  private request;
10
10
  connect(): Promise<any>;
11
- info(): Promise<any>;
11
+ info(): Promise<InfoInstance>;
12
12
  logout(): Promise<any>;
13
- setting(markMessageRead: boolean, saveMedia: boolean): Promise<any>;
13
+ setting(markMessageRead: boolean, saveMedia: boolean, receiveStatusMessage: boolean): Promise<any>;
14
14
  updateWebhook(body: WebhookBody): Promise<any>;
15
15
  sendMessage(data: {
16
16
  type: TypeMessage;
@@ -35,14 +35,20 @@ export declare class WhatsApp {
35
35
  thumbnailUrl?: string;
36
36
  sourceUrl?: string;
37
37
  };
38
- }, reply?: boolean): Promise<any>;
38
+ }, reply?: boolean): Promise<SendMessageRoot>;
39
+ forwardingMessage(to: string, msgId: string): Promise<any>;
40
+ rejectCall(id: string, from: string): Promise<any>;
41
+ pairingCode(phoneNumber: string): Promise<any>;
39
42
  checkRegisteredWhatsapp(number: string): Promise<any>;
40
43
  contacts(): Promise<any>;
41
44
  contactProfile(id: string): Promise<any>;
42
45
  groups(): Promise<any>;
43
46
  infoGroup(id: string): Promise<any>;
47
+ getInviteGroup(id: string): Promise<any>;
44
48
  updateGroup(id: string, name: string, description: string): Promise<any>;
49
+ updateGroupPicture(id: string, url: string): Promise<any>;
45
50
  leaveGroup(id: string): Promise<any>;
46
51
  createGroup(name: string, participants: string[]): Promise<any>;
52
+ addParticipantsGroup(id: string, participants: string[]): Promise<any>;
47
53
  }
48
54
  export default WhatsApp;
package/dist/WhatsApp.js CHANGED
@@ -51,8 +51,8 @@ class WhatsApp {
51
51
  this.method = model_1.HttpMethod.DELETE;
52
52
  return await this.request();
53
53
  }
54
- async setting(markMessageRead, saveMedia) {
55
- this.route = model_1.Routes.INSTANCES + `/?markMessageRead=${markMessageRead}&saveMedia=${saveMedia}`;
54
+ async setting(markMessageRead, saveMedia, receiveStatusMessage) {
55
+ this.route = model_1.Routes.INSTANCES + `/?markMessageRead=${markMessageRead}&saveMedia=${saveMedia}&receiveStatusMessage=${receiveStatusMessage}`;
56
56
  this.method = model_1.HttpMethod.PATCH;
57
57
  return await this.request();
58
58
  }
@@ -73,6 +73,27 @@ class WhatsApp {
73
73
  this.body = data.body;
74
74
  return await this.request();
75
75
  }
76
+ async forwardingMessage(to, msgId) {
77
+ this.route = model_1.Routes.MESSAGES + "/" + msgId + "/forwarding";
78
+ this.method = model_1.HttpMethod.POST;
79
+ this.body = {
80
+ to,
81
+ };
82
+ return await this.request();
83
+ }
84
+ async rejectCall(id, from) {
85
+ this.route = model_1.Routes.CALL + `/${id}/${from}`;
86
+ this.method = model_1.HttpMethod.DELETE;
87
+ return await this.request();
88
+ }
89
+ async pairingCode(phoneNumber) {
90
+ this.route = model_1.Routes.INSTANCES + "/pairing-code";
91
+ this.body = {
92
+ phoneNumber,
93
+ };
94
+ this.method = model_1.HttpMethod.POST;
95
+ return await this.request();
96
+ }
76
97
  async checkRegisteredWhatsapp(number) {
77
98
  this.route = model_1.Routes.ACTIONS + "/registered?number=" + number;
78
99
  this.method = model_1.HttpMethod.GET;
@@ -98,6 +119,11 @@ class WhatsApp {
98
119
  this.method = model_1.HttpMethod.GET;
99
120
  return await this.request();
100
121
  }
122
+ async getInviteGroup(id) {
123
+ this.route = model_1.Routes.GROUPS + "/" + id + "/invite";
124
+ this.method = model_1.HttpMethod.GET;
125
+ return await this.request();
126
+ }
101
127
  async updateGroup(id, name, description) {
102
128
  this.route = model_1.Routes.GROUPS + "/" + id;
103
129
  this.method = model_1.HttpMethod.PUT;
@@ -107,6 +133,14 @@ class WhatsApp {
107
133
  };
108
134
  return await this.request();
109
135
  }
136
+ async updateGroupPicture(id, url) {
137
+ this.route = model_1.Routes.GROUPS + "/" + id + "/picture";
138
+ this.method = model_1.HttpMethod.PUT;
139
+ this.body = {
140
+ url
141
+ };
142
+ return await this.request();
143
+ }
110
144
  async leaveGroup(id) {
111
145
  this.route = model_1.Routes.GROUPS + "/" + id;
112
146
  this.method = model_1.HttpMethod.DELETE;
@@ -121,6 +155,14 @@ class WhatsApp {
121
155
  };
122
156
  return await this.request();
123
157
  }
158
+ async addParticipantsGroup(id, participants) {
159
+ this.route = model_1.Routes.GROUPS + "/" + id + "/participants";
160
+ this.method = model_1.HttpMethod.POST;
161
+ this.body = {
162
+ participants
163
+ };
164
+ return await this.request();
165
+ }
124
166
  }
125
167
  exports.WhatsApp = WhatsApp;
126
168
  exports.default = WhatsApp;
@@ -1 +1 @@
1
- {"version":3,"file":"WhatsApp.js","sourceRoot":"","sources":["../src/WhatsApp.ts"],"names":[],"mappings":";;;;AAAA,0DAAiE;AACjE,mCAA+G;AAE/G,MAAa,QAAQ;IACF,MAAM,CAAS;IACf,GAAG,CAAS;IACrB,KAAK,CAAS;IACd,MAAM,GAAsB,IAAI,CAAC;IACjC,IAAI,GAAQ,IAAI,CAAC;IAEzB,YAAY,IAAU;QACpB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;IACtB,CAAC;IAEO,KAAK,CAAC,OAAO;QACnB,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YAChC,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;QAC9E,CAAC;QACD,MAAM,OAAO,GAAuB;YAClC,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,GAAG,IAAI,IAA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UAAU,CAAC,EAAU;QACzB,IAAI,CAAC,KAAK,GAAG,cAAM,CAAC,MAAM,GAAG,GAAG,GAAG,EAAE,CAAC;QACtC,IAAI,CAAC,MAAM,GAAG,kBAAU,CAAC,MAAM,CAAC;QAChC,OAAO,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;IAC9B,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,IAAY,EAAE,YAAsB;QACpD,IAAI,CAAC,KAAK,GAAG,cAAM,CAAC,MAAM,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,kBAAU,CAAC,IAAI,CAAC;QAC9B,IAAI,CAAC,IAAI,GAAG;YACV,IAAI;YACJ,YAAY;SACb,CAAA;QACD,OAAO,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;IAC9B,CAAC;CAEF;AApKD,4BAoKC;AAGD,kBAAe,QAAQ,CAAC","sourcesContent":["import axios, { AxiosRequestConfig, AxiosResponse } from 'axios';\nimport { Init, HttpMethod, WebhookBody, Routes, TypeMessage, StatusPresence, Contact, Section } from './model';\n\nexport class WhatsApp {\n private readonly server: string;\n private readonly key: string;\n private route: string;\n private method: HttpMethod | null = null;\n private body: any = null;\n\n constructor(data: Init) {\n this.server = data.server;\n this.key = data.key;\n }\n\n private async request(): Promise<any> {\n if (!this.route || !this.method) {\n throw new Error('Path and method must be defined before making a request.');\n }\n const options: AxiosRequestConfig = {\n url: `${this.server}/${this.key}/${this.route}`,\n method: this.method,\n headers: {\n 'Content-Type': 'application/json'\n }\n };\n if ((this.method === 'POST' || this.method === 'PUT') && this.body) {\n options.data = JSON.stringify(this.body);\n }\n try {\n const response = await axios(options);\n return response.data;\n } catch (error: any) {\n throw new Error(`HTTP Request Error: ${error.message} (status: ${error.response?.status})`);\n }\n }\n\n\n async connect(): Promise<any> {\n this.route = Routes.INSTANCES;\n this.method = HttpMethod.POST;\n return await this.request();\n }\n\n async info(): Promise<any> {\n this.route = Routes.INSTANCES;\n this.method = HttpMethod.GET;\n return await this.request();\n }\n\n async logout(): Promise<any> {\n this.route = Routes.INSTANCES;\n this.method = HttpMethod.DELETE;\n return await this.request();\n }\n\n async setting(markMessageRead: boolean, saveMedia: boolean): Promise<any> {\n this.route = Routes.INSTANCES + `/?markMessageRead=${markMessageRead}&saveMedia=${saveMedia}`;\n this.method = HttpMethod.PATCH;\n return await this.request();\n }\n\n\n\n async updateWebhook(body: WebhookBody): Promise<any> {\n this.route = Routes.INSTANCES;\n this.method = HttpMethod.PUT;\n this.body = body;\n return await this.request();\n }\n\n\n async sendMessage(\n data: {\n type: TypeMessage,\n body: {\n to: string,\n msgId?: string,\n status?: StatusPresence,\n text?: string,\n url?: string,\n caption?: string,\n mimetype?: string,\n fileName?: string,\n contact?: Contact,\n location?: Location,\n name?: string,\n options?: string[],\n sections?: Section,\n footer?: string,\n description?: string,\n title?: string,\n buttonText?: string,\n thumbnailUrl?: string,\n sourceUrl?: string,\n }\n }, reply: boolean = false): Promise<any> {\n if (reply) {\n this.route = Routes.MESSAGES + \"/\" + data.body.msgId + \"/\" + data.type;\n } else {\n this.route = Routes.MESSAGES + \"/\" + data.type;\n }\n\n this.method = HttpMethod.POST;\n this.body = data.body;\n return await this.request();\n }\n\n async checkRegisteredWhatsapp(number: string) {\n this.route = Routes.ACTIONS + \"/registered?number=\" + number;\n this.method = HttpMethod.GET;\n return await this.request();\n }\n\n\n async contacts() {\n this.route = Routes.CONTACTS;\n this.method = HttpMethod.GET;\n return await this.request();\n }\n\n async contactProfile(id: string) {\n this.route = Routes.CONTACTS + \"/\" + id;\n this.method = HttpMethod.GET;\n return await this.request();\n }\n\n\n async groups() {\n this.route = Routes.GROUPS;\n this.method = HttpMethod.GET;\n return await this.request();\n }\n\n\n async infoGroup(id: string) {\n this.route = Routes.GROUPS + \"/\" + id;\n this.method = HttpMethod.GET;\n return await this.request();\n }\n\n async updateGroup(id: string, name: string, description: string) {\n this.route = Routes.GROUPS + \"/\" + id;\n this.method = HttpMethod.PUT;\n this.body = {\n name,\n description\n }\n return await this.request();\n }\n\n async leaveGroup(id: string) {\n this.route = Routes.GROUPS + \"/\" + id;\n this.method = HttpMethod.DELETE;\n return await this.request();\n }\n\n async createGroup(name: string, participants: string[]) {\n this.route = Routes.GROUPS;\n this.method = HttpMethod.POST;\n this.body = {\n name,\n participants\n }\n return await this.request();\n }\n\n}\n\n\nexport default WhatsApp;\n\n\n"]}
1
+ {"version":3,"file":"WhatsApp.js","sourceRoot":"","sources":["../src/WhatsApp.ts"],"names":[],"mappings":";;;;AAAA,0DAAiE;AACjE,mCAA8I;AAE9I,MAAa,QAAQ;IACF,MAAM,CAAS;IACf,GAAG,CAAS;IACrB,KAAK,CAAS;IACd,MAAM,GAAsB,IAAI,CAAC;IACjC,IAAI,GAAQ,IAAI,CAAC;IAEzB,YAAY,IAAU;QACpB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;IACtB,CAAC;IAEO,KAAK,CAAC,OAAO;QACnB,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YAChC,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;QAC9E,CAAC;QACD,MAAM,OAAO,GAAuB;YAClC,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,KAAK,EAAE;YAC/C,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;aACnC;SACF,CAAC;QACF,IAAI,CAAC,IAAI,CAAC,MAAM,KAAK,MAAM,IAAI,IAAI,CAAC,MAAM,KAAK,KAAK,CAAC,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YACnE,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC3C,CAAC;QACD,IAAI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C,OAAO,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;IAC9B,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,IAAY,EAAE,YAAsB;QACpD,IAAI,CAAC,KAAK,GAAG,cAAM,CAAC,MAAM,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,kBAAU,CAAC,IAAI,CAAC;QAC9B,IAAI,CAAC,IAAI,GAAG;YACV,IAAI;YACJ,YAAY;SACb,CAAA;QACD,OAAO,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;IAC9B,CAAC;IAGD,KAAK,CAAC,oBAAoB,CAAC,EAAU,EAAE,YAAsB;QAC3D,IAAI,CAAC,KAAK,GAAG,cAAM,CAAC,MAAM,GAAG,GAAG,GAAG,EAAE,GAAG,eAAe,CAAC;QACxD,IAAI,CAAC,MAAM,GAAG,kBAAU,CAAC,IAAI,CAAC;QAC9B,IAAI,CAAC,IAAI,GAAG;YACV,YAAY;SACb,CAAA;QACD,OAAO,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;IAC9B,CAAC;CAEF;AAxND,4BAwNC;AAGD,kBAAe,QAAQ,CAAC","sourcesContent":["import axios, { AxiosRequestConfig, AxiosResponse } from 'axios';\nimport { Init, HttpMethod, WebhookBody, Routes, TypeMessage, StatusPresence, Contact, Section, InfoInstance, SendMessageRoot } from './model';\n\nexport class WhatsApp {\n private readonly server: string;\n private readonly key: string;\n private route: string;\n private method: HttpMethod | null = null;\n private body: any = null;\n\n constructor(data: Init) {\n this.server = data.server;\n this.key = data.key;\n }\n\n private async request(): Promise<any> {\n if (!this.route || !this.method) {\n throw new Error('Path and method must be defined before making a request.');\n }\n const options: AxiosRequestConfig = {\n url: `${this.server}/${this.key}/${this.route}`,\n method: this.method,\n headers: {\n 'Content-Type': 'application/json'\n }\n };\n if ((this.method === 'POST' || this.method === 'PUT') && this.body) {\n options.data = JSON.stringify(this.body);\n }\n try {\n const response = await axios(options);\n return response.data;\n } catch (error: any) {\n throw new Error(`HTTP Request Error: ${error.message} (status: ${error.response?.status})`);\n }\n }\n\n\n async connect(): Promise<any> {\n this.route = Routes.INSTANCES;\n this.method = HttpMethod.POST;\n return await this.request();\n }\n\n async info(): Promise<InfoInstance> {\n this.route = Routes.INSTANCES;\n this.method = HttpMethod.GET;\n return await this.request();\n }\n\n async logout(): Promise<any> {\n this.route = Routes.INSTANCES;\n this.method = HttpMethod.DELETE;\n return await this.request();\n }\n\n\n async setting(markMessageRead: boolean, saveMedia: boolean, receiveStatusMessage: boolean): Promise<any> {\n this.route = Routes.INSTANCES + `/?markMessageRead=${markMessageRead}&saveMedia=${saveMedia}&receiveStatusMessage=${receiveStatusMessage}`;\n this.method = HttpMethod.PATCH;\n return await this.request();\n }\n\n\n async updateWebhook(body: WebhookBody): Promise<any> {\n this.route = Routes.INSTANCES;\n this.method = HttpMethod.PUT;\n this.body = body;\n return await this.request();\n }\n\n\n async sendMessage(\n data: {\n type: TypeMessage,\n body: {\n to: string,\n msgId?: string,\n status?: StatusPresence,\n text?: string,\n url?: string,\n caption?: string,\n mimetype?: string,\n fileName?: string,\n contact?: Contact,\n location?: Location,\n name?: string,\n options?: string[],\n sections?: Section,\n footer?: string,\n description?: string,\n title?: string,\n buttonText?: string,\n thumbnailUrl?: string,\n sourceUrl?: string,\n }\n }, reply: boolean = false): Promise<SendMessageRoot> {\n if (reply) {\n this.route = Routes.MESSAGES + \"/\" + data.body.msgId + \"/\" + data.type;\n } else {\n this.route = Routes.MESSAGES + \"/\" + data.type;\n }\n\n this.method = HttpMethod.POST;\n this.body = data.body;\n return await this.request();\n }\n\n\n async forwardingMessage(to: string, msgId: string) {\n this.route = Routes.MESSAGES + \"/\" + msgId + \"/forwarding\";\n this.method = HttpMethod.POST;\n this.body = {\n to,\n }\n return await this.request();\n }\n\n async rejectCall(id: string, from: string) {\n this.route = Routes.CALL + `/${id}/${from}`;\n this.method = HttpMethod.DELETE;\n return await this.request();\n }\n\n async pairingCode(phoneNumber: string) {\n this.route = Routes.INSTANCES + \"/pairing-code\";\n this.body = {\n phoneNumber,\n }\n this.method = HttpMethod.POST;\n return await this.request();\n }\n\n async checkRegisteredWhatsapp(number: string) {\n this.route = Routes.ACTIONS + \"/registered?number=\" + number;\n this.method = HttpMethod.GET;\n return await this.request();\n }\n\n\n async contacts() {\n this.route = Routes.CONTACTS;\n this.method = HttpMethod.GET;\n return await this.request();\n }\n\n async contactProfile(id: string) {\n this.route = Routes.CONTACTS + \"/\" + id;\n this.method = HttpMethod.GET;\n return await this.request();\n }\n\n\n async groups() {\n this.route = Routes.GROUPS;\n this.method = HttpMethod.GET;\n return await this.request();\n }\n\n\n async infoGroup(id: string) {\n this.route = Routes.GROUPS + \"/\" + id;\n this.method = HttpMethod.GET;\n return await this.request();\n }\n\n async getInviteGroup(id: string) {\n this.route = Routes.GROUPS + \"/\" + id + \"/invite\";\n this.method = HttpMethod.GET;\n return await this.request();\n }\n\n\n\n async updateGroup(id: string, name: string, description: string) {\n this.route = Routes.GROUPS + \"/\" + id;\n this.method = HttpMethod.PUT;\n this.body = {\n name,\n description\n }\n return await this.request();\n }\n\n async updateGroupPicture(id: string, url: string) {\n this.route = Routes.GROUPS + \"/\" + id + \"/picture\";\n this.method = HttpMethod.PUT;\n this.body = {\n url\n }\n return await this.request();\n }\n\n async leaveGroup(id: string) {\n this.route = Routes.GROUPS + \"/\" + id;\n this.method = HttpMethod.DELETE;\n return await this.request();\n }\n\n async createGroup(name: string, participants: string[]) {\n this.route = Routes.GROUPS;\n this.method = HttpMethod.POST;\n this.body = {\n name,\n participants\n }\n return await this.request();\n }\n\n\n async addParticipantsGroup(id: string, participants: string[]) {\n this.route = Routes.GROUPS + \"/\" + id + \"/participants\";\n this.method = HttpMethod.POST;\n this.body = {\n participants\n }\n return await this.request();\n }\n\n}\n\n\nexport default WhatsApp;\n\n\n"]}
@@ -14,7 +14,8 @@ export declare enum Routes {
14
14
  MESSAGES = "message",
15
15
  CONTACTS = "contacts",
16
16
  GROUPS = "groups",
17
- ACTIONS = "actions"
17
+ ACTIONS = "actions",
18
+ CALL = "call"
18
19
  }
19
20
  export declare enum TypeMessage {
20
21
  PRESENCE = "presence",
@@ -26,7 +27,8 @@ export declare enum TypeMessage {
26
27
  CONTACT = "contact",
27
28
  LOCATION = "location",
28
29
  REACTION = "reaction",
29
- LINK = "link"
30
+ LINK = "link",
31
+ TITLE = "title"
30
32
  }
31
33
  export declare enum StatusPresence {
32
34
  UNAVAILABLE = "unavailable",
@@ -63,3 +65,50 @@ export interface Section {
63
65
  title: string;
64
66
  rows: Row[];
65
67
  }
68
+ export interface InfoInstance {
69
+ status: number;
70
+ instance: Instance;
71
+ }
72
+ export interface Instance {
73
+ receive_status_message: boolean;
74
+ save_media: boolean;
75
+ mark_messages: boolean;
76
+ blocked: boolean;
77
+ user: User;
78
+ phoneConnected: boolean;
79
+ webhook: Webhook;
80
+ }
81
+ export interface User {
82
+ id: string;
83
+ lid: string;
84
+ }
85
+ export interface Webhook {
86
+ allowWebhook: boolean;
87
+ webhookMessage: string;
88
+ webhookGroup: string;
89
+ webhookConnection: string;
90
+ webhookQrCode: string;
91
+ webhookMessageFromMe: string;
92
+ webhookHistory: string;
93
+ }
94
+ export interface SendMessageRoot {
95
+ status: number;
96
+ data: Data;
97
+ }
98
+ export interface Data {
99
+ key: Key;
100
+ message: Message;
101
+ messageTimestamp: string;
102
+ status: string;
103
+ }
104
+ export interface Key {
105
+ remoteJid: string;
106
+ fromMe: boolean;
107
+ id: string;
108
+ }
109
+ export interface Message {
110
+ extendedTextMessage: ExtendedTextMessage;
111
+ }
112
+ export interface ExtendedTextMessage {
113
+ text: string;
114
+ }
@@ -16,6 +16,7 @@ var Routes;
16
16
  Routes["CONTACTS"] = "contacts";
17
17
  Routes["GROUPS"] = "groups";
18
18
  Routes["ACTIONS"] = "actions";
19
+ Routes["CALL"] = "call";
19
20
  })(Routes || (exports.Routes = Routes = {}));
20
21
  var TypeMessage;
21
22
  (function (TypeMessage) {
@@ -29,6 +30,7 @@ var TypeMessage;
29
30
  TypeMessage["LOCATION"] = "location";
30
31
  TypeMessage["REACTION"] = "reaction";
31
32
  TypeMessage["LINK"] = "link";
33
+ TypeMessage["TITLE"] = "title";
32
34
  })(TypeMessage || (exports.TypeMessage = TypeMessage = {}));
33
35
  var StatusPresence;
34
36
  (function (StatusPresence) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/model/index.ts"],"names":[],"mappings":";;;AAKA,IAAY,UAMX;AAND,WAAY,UAAU;IACpB,yBAAW,CAAA;IACX,2BAAa,CAAA;IACb,yBAAW,CAAA;IACX,+BAAiB,CAAA;IACjB,6BAAe,CAAA;AACjB,CAAC,EANW,UAAU,0BAAV,UAAU,QAMrB;AAGD,IAAY,MAMX;AAND,WAAY,MAAM;IAChB,gCAAsB,CAAA;IACtB,8BAAoB,CAAA;IACpB,+BAAqB,CAAA;IACrB,2BAAiB,CAAA;IACjB,6BAAmB,CAAA;AACrB,CAAC,EANW,MAAM,sBAAN,MAAM,QAMjB;AAGD,IAAY,WAWX;AAXD,WAAY,WAAW;IACrB,oCAAqB,CAAA;IACrB,4BAAa,CAAA;IACb,8BAAe,CAAA;IACf,8BAAe,CAAA;IACf,8BAAe,CAAA;IACf,oCAAqB,CAAA;IACrB,kCAAmB,CAAA;IACnB,oCAAqB,CAAA;IACrB,oCAAqB,CAAA;IACrB,4BAAa,CAAA;AACf,CAAC,EAXW,WAAW,2BAAX,WAAW,QAWtB;AAGD,IAAY,cAMX;AAND,WAAY,cAAc;IACxB,6CAA2B,CAAA;IAC3B,yCAAuB,CAAA;IACvB,yCAAuB,CAAA;IACvB,yCAAuB,CAAA;IACvB,mCAAiB,CAAA;AACnB,CAAC,EANW,cAAc,8BAAd,cAAc,QAMzB","sourcesContent":["export interface Init {\n server: string;\n key: string;\n}\n\nexport enum HttpMethod {\n GET = 'GET',\n POST = 'POST',\n PUT = 'PUT',\n DELETE = 'DELETE',\n PATCH = 'PATCH',\n}\n\n\nexport enum Routes {\n INSTANCES = 'instance',\n MESSAGES = 'message',\n CONTACTS = 'contacts',\n GROUPS = 'groups',\n ACTIONS = 'actions',\n}\n\n\nexport enum TypeMessage {\n PRESENCE = 'presence',\n TEXT = 'text',\n AUDIO = 'audio',\n IMAGE = 'image',\n VIDEO = 'video',\n DOCUMENT = 'document',\n CONTACT = 'contact',\n LOCATION = 'location',\n REACTION = 'reaction',\n LINK = 'link',\n}\n\n\nexport enum StatusPresence {\n UNAVAILABLE = 'unavailable',\n AVAILABLE = 'available',\n COMPOSING = 'composing',\n RECORDING = 'recording',\n PAUSED = 'paused',\n}\n\n\n\nexport interface WebhookBody {\n allowWebhook: boolean;\n webhookMessage: string;\n webhookGroup: string;\n webhookConnection: string;\n webhookQrCode: string;\n webhookMessageFromMe: string;\n webhookHistory: string;\n}\n\nexport interface Contact {\n fullName: string;\n phoneNumber: string;\n organization?: string;\n}\n\n\nexport interface Location {\n latitude: number;\n longitude: number;\n address: string;\n}\n\nexport interface Row {\n title: string;\n description: string;\n rowId: string;\n}\n\nexport interface Section {\n title: string;\n rows: Row[];\n}"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/model/index.ts"],"names":[],"mappings":";;;AAKA,IAAY,UAMX;AAND,WAAY,UAAU;IACpB,yBAAW,CAAA;IACX,2BAAa,CAAA;IACb,yBAAW,CAAA;IACX,+BAAiB,CAAA;IACjB,6BAAe,CAAA;AACjB,CAAC,EANW,UAAU,0BAAV,UAAU,QAMrB;AAGD,IAAY,MAOX;AAPD,WAAY,MAAM;IAChB,gCAAsB,CAAA;IACtB,8BAAoB,CAAA;IACpB,+BAAqB,CAAA;IACrB,2BAAiB,CAAA;IACjB,6BAAmB,CAAA;IACnB,uBAAa,CAAA;AACf,CAAC,EAPW,MAAM,sBAAN,MAAM,QAOjB;AAGD,IAAY,WAYX;AAZD,WAAY,WAAW;IACrB,oCAAqB,CAAA;IACrB,4BAAa,CAAA;IACb,8BAAe,CAAA;IACf,8BAAe,CAAA;IACf,8BAAe,CAAA;IACf,oCAAqB,CAAA;IACrB,kCAAmB,CAAA;IACnB,oCAAqB,CAAA;IACrB,oCAAqB,CAAA;IACrB,4BAAa,CAAA;IACb,8BAAe,CAAA;AACjB,CAAC,EAZW,WAAW,2BAAX,WAAW,QAYtB;AAGD,IAAY,cAMX;AAND,WAAY,cAAc;IACxB,6CAA2B,CAAA;IAC3B,yCAAuB,CAAA;IACvB,yCAAuB,CAAA;IACvB,yCAAuB,CAAA;IACvB,mCAAiB,CAAA;AACnB,CAAC,EANW,cAAc,8BAAd,cAAc,QAMzB","sourcesContent":["export interface Init {\n server: string;\n key: string;\n}\n\nexport enum HttpMethod {\n GET = 'GET',\n POST = 'POST',\n PUT = 'PUT',\n DELETE = 'DELETE',\n PATCH = 'PATCH',\n}\n\n\nexport enum Routes {\n INSTANCES = 'instance',\n MESSAGES = 'message',\n CONTACTS = 'contacts',\n GROUPS = 'groups',\n ACTIONS = 'actions',\n CALL = 'call',\n}\n\n\nexport enum TypeMessage {\n PRESENCE = 'presence',\n TEXT = 'text',\n AUDIO = 'audio',\n IMAGE = 'image',\n VIDEO = 'video',\n DOCUMENT = 'document',\n CONTACT = 'contact',\n LOCATION = 'location',\n REACTION = 'reaction',\n LINK = 'link',\n TITLE = 'title',\n}\n\n\nexport enum StatusPresence {\n UNAVAILABLE = 'unavailable',\n AVAILABLE = 'available',\n COMPOSING = 'composing',\n RECORDING = 'recording',\n PAUSED = 'paused',\n}\n\n\n\nexport interface WebhookBody {\n allowWebhook: boolean;\n webhookMessage: string;\n webhookGroup: string;\n webhookConnection: string;\n webhookQrCode: string;\n webhookMessageFromMe: string;\n webhookHistory: string;\n}\n\nexport interface Contact {\n fullName: string;\n phoneNumber: string;\n organization?: string;\n}\n\n\nexport interface Location {\n latitude: number;\n longitude: number;\n address: string;\n}\n\nexport interface Row {\n title: string;\n description: string;\n rowId: string;\n}\n\nexport interface Section {\n title: string;\n rows: Row[];\n}\n\n\n\n\n\nexport interface InfoInstance {\n status: number\n instance: Instance\n}\n\nexport interface Instance {\n receive_status_message: boolean\n save_media: boolean\n mark_messages: boolean\n blocked: boolean\n user: User\n phoneConnected: boolean\n webhook: Webhook\n}\n\nexport interface User {\n id: string\n lid: string\n}\n\nexport interface Webhook {\n allowWebhook: boolean\n webhookMessage: string\n webhookGroup: string\n webhookConnection: string\n webhookQrCode: string\n webhookMessageFromMe: string\n webhookHistory: string\n}\n\n\n\nexport interface SendMessageRoot {\n status: number\n data: Data\n}\n\nexport interface Data {\n key: Key\n message: Message\n messageTimestamp: string\n status: string\n}\n\nexport interface Key {\n remoteJid: string\n fromMe: boolean\n id: string\n}\n\nexport interface Message {\n extendedTextMessage: ExtendedTextMessage\n}\n\nexport interface ExtendedTextMessage {\n text: string\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raphaelvserafim/client-api-whatsapp",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "With our API, you can send text, audio, video, and image messages quickly and easily. Adapt to your business communication needs comprehensively.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/WhatsApp.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import axios, { AxiosRequestConfig, AxiosResponse } from 'axios';
2
- import { Init, HttpMethod, WebhookBody, Routes, TypeMessage, StatusPresence, Contact, Section } from './model';
2
+ import { Init, HttpMethod, WebhookBody, Routes, TypeMessage, StatusPresence, Contact, Section, InfoInstance, SendMessageRoot } from './model';
3
3
 
4
4
  export class WhatsApp {
5
5
  private readonly server: string;
@@ -42,7 +42,7 @@ export class WhatsApp {
42
42
  return await this.request();
43
43
  }
44
44
 
45
- async info(): Promise<any> {
45
+ async info(): Promise<InfoInstance> {
46
46
  this.route = Routes.INSTANCES;
47
47
  this.method = HttpMethod.GET;
48
48
  return await this.request();
@@ -54,14 +54,14 @@ export class WhatsApp {
54
54
  return await this.request();
55
55
  }
56
56
 
57
- async setting(markMessageRead: boolean, saveMedia: boolean): Promise<any> {
58
- this.route = Routes.INSTANCES + `/?markMessageRead=${markMessageRead}&saveMedia=${saveMedia}`;
57
+
58
+ async setting(markMessageRead: boolean, saveMedia: boolean, receiveStatusMessage: boolean): Promise<any> {
59
+ this.route = Routes.INSTANCES + `/?markMessageRead=${markMessageRead}&saveMedia=${saveMedia}&receiveStatusMessage=${receiveStatusMessage}`;
59
60
  this.method = HttpMethod.PATCH;
60
61
  return await this.request();
61
62
  }
62
63
 
63
64
 
64
-
65
65
  async updateWebhook(body: WebhookBody): Promise<any> {
66
66
  this.route = Routes.INSTANCES;
67
67
  this.method = HttpMethod.PUT;
@@ -94,7 +94,7 @@ export class WhatsApp {
94
94
  thumbnailUrl?: string,
95
95
  sourceUrl?: string,
96
96
  }
97
- }, reply: boolean = false): Promise<any> {
97
+ }, reply: boolean = false): Promise<SendMessageRoot> {
98
98
  if (reply) {
99
99
  this.route = Routes.MESSAGES + "/" + data.body.msgId + "/" + data.type;
100
100
  } else {
@@ -106,6 +106,31 @@ export class WhatsApp {
106
106
  return await this.request();
107
107
  }
108
108
 
109
+
110
+ async forwardingMessage(to: string, msgId: string) {
111
+ this.route = Routes.MESSAGES + "/" + msgId + "/forwarding";
112
+ this.method = HttpMethod.POST;
113
+ this.body = {
114
+ to,
115
+ }
116
+ return await this.request();
117
+ }
118
+
119
+ async rejectCall(id: string, from: string) {
120
+ this.route = Routes.CALL + `/${id}/${from}`;
121
+ this.method = HttpMethod.DELETE;
122
+ return await this.request();
123
+ }
124
+
125
+ async pairingCode(phoneNumber: string) {
126
+ this.route = Routes.INSTANCES + "/pairing-code";
127
+ this.body = {
128
+ phoneNumber,
129
+ }
130
+ this.method = HttpMethod.POST;
131
+ return await this.request();
132
+ }
133
+
109
134
  async checkRegisteredWhatsapp(number: string) {
110
135
  this.route = Routes.ACTIONS + "/registered?number=" + number;
111
136
  this.method = HttpMethod.GET;
@@ -139,6 +164,14 @@ export class WhatsApp {
139
164
  return await this.request();
140
165
  }
141
166
 
167
+ async getInviteGroup(id: string) {
168
+ this.route = Routes.GROUPS + "/" + id + "/invite";
169
+ this.method = HttpMethod.GET;
170
+ return await this.request();
171
+ }
172
+
173
+
174
+
142
175
  async updateGroup(id: string, name: string, description: string) {
143
176
  this.route = Routes.GROUPS + "/" + id;
144
177
  this.method = HttpMethod.PUT;
@@ -149,6 +182,15 @@ export class WhatsApp {
149
182
  return await this.request();
150
183
  }
151
184
 
185
+ async updateGroupPicture(id: string, url: string) {
186
+ this.route = Routes.GROUPS + "/" + id + "/picture";
187
+ this.method = HttpMethod.PUT;
188
+ this.body = {
189
+ url
190
+ }
191
+ return await this.request();
192
+ }
193
+
152
194
  async leaveGroup(id: string) {
153
195
  this.route = Routes.GROUPS + "/" + id;
154
196
  this.method = HttpMethod.DELETE;
@@ -165,6 +207,16 @@ export class WhatsApp {
165
207
  return await this.request();
166
208
  }
167
209
 
210
+
211
+ async addParticipantsGroup(id: string, participants: string[]) {
212
+ this.route = Routes.GROUPS + "/" + id + "/participants";
213
+ this.method = HttpMethod.POST;
214
+ this.body = {
215
+ participants
216
+ }
217
+ return await this.request();
218
+ }
219
+
168
220
  }
169
221
 
170
222
 
@@ -18,6 +18,7 @@ export enum Routes {
18
18
  CONTACTS = 'contacts',
19
19
  GROUPS = 'groups',
20
20
  ACTIONS = 'actions',
21
+ CALL = 'call',
21
22
  }
22
23
 
23
24
 
@@ -32,6 +33,7 @@ export enum TypeMessage {
32
33
  LOCATION = 'location',
33
34
  REACTION = 'reaction',
34
35
  LINK = 'link',
36
+ TITLE = 'title',
35
37
  }
36
38
 
37
39
 
@@ -77,4 +79,66 @@ export interface Row {
77
79
  export interface Section {
78
80
  title: string;
79
81
  rows: Row[];
80
- }
82
+ }
83
+
84
+
85
+
86
+
87
+
88
+ export interface InfoInstance {
89
+ status: number
90
+ instance: Instance
91
+ }
92
+
93
+ export interface Instance {
94
+ receive_status_message: boolean
95
+ save_media: boolean
96
+ mark_messages: boolean
97
+ blocked: boolean
98
+ user: User
99
+ phoneConnected: boolean
100
+ webhook: Webhook
101
+ }
102
+
103
+ export interface User {
104
+ id: string
105
+ lid: string
106
+ }
107
+
108
+ export interface Webhook {
109
+ allowWebhook: boolean
110
+ webhookMessage: string
111
+ webhookGroup: string
112
+ webhookConnection: string
113
+ webhookQrCode: string
114
+ webhookMessageFromMe: string
115
+ webhookHistory: string
116
+ }
117
+
118
+
119
+
120
+ export interface SendMessageRoot {
121
+ status: number
122
+ data: Data
123
+ }
124
+
125
+ export interface Data {
126
+ key: Key
127
+ message: Message
128
+ messageTimestamp: string
129
+ status: string
130
+ }
131
+
132
+ export interface Key {
133
+ remoteJid: string
134
+ fromMe: boolean
135
+ id: string
136
+ }
137
+
138
+ export interface Message {
139
+ extendedTextMessage: ExtendedTextMessage
140
+ }
141
+
142
+ export interface ExtendedTextMessage {
143
+ text: string
144
+ }