@raphaelvserafim/client-api-whatsapp 1.0.6 → 1.0.8

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
@@ -98,6 +98,148 @@ whatsapp.sendMessage({
98
98
  }).catch(console.error)
99
99
  ```
100
100
 
101
+
102
+ ### Cobrança Pix
103
+ ```js
104
+ whatsapp.sendMessage({
105
+ type: TypeMessage.BUTTON_PIX,
106
+ body: {
107
+ to: "14375223417",
108
+ title: "Pizza",
109
+ text: "Pizza ",
110
+ referenceId: "apiwame",
111
+ code: "0020",
112
+ key: "23711695000115",
113
+ merchantName: "CACHE SISTEMAS WEB",
114
+ keyType: "CNPJ",
115
+ items: [
116
+ {
117
+ id: "123",
118
+ name: "Pizza G",
119
+ price: 10,
120
+ quantity: 10
121
+ },
122
+ ],
123
+ subtotal: "90",
124
+ totalAmount: "100"
125
+ }
126
+ }).then((response) => {
127
+ console.log(response)
128
+ }).catch(console.error)
129
+ ```
130
+
131
+
132
+ ### Buttons Reply
133
+ ```js
134
+ whatsapp.sendMessage({
135
+ type: TypeMessage.BUTTON_REPLY,
136
+ body: {
137
+ to: "14375223417",
138
+ header: {
139
+ title: "Example Header",
140
+ },
141
+ text: "This is a test",
142
+ footer: "choose an option",
143
+ buttons: [
144
+ {
145
+ type: "quick_reply",
146
+ id: "uniqId1",
147
+ text: "Yes"
148
+ },
149
+ {
150
+ type: "quick_reply",
151
+ id: "uniqId2",
152
+ text: "No"
153
+ }
154
+ ]
155
+ }
156
+ }).then((response) => {
157
+ console.log(response)
158
+ }).catch(console.error)
159
+ ```
160
+
161
+
162
+ ### Buttons ACTION
163
+ ```js
164
+ whatsapp.sendMessage({
165
+ type: TypeMessage.BUTTON_ACTION,
166
+ body: {
167
+ to: "14375223417",
168
+ header: {
169
+ title: "Example Header",
170
+ },
171
+ text: "This is a test",
172
+ footer: "choose an option",
173
+ buttons: [
174
+ {
175
+ type: "cta_copy",
176
+ copy_code: "1234567890",
177
+ text: "Copy barcode"
178
+ },
179
+ {
180
+ type: "cta_url",
181
+ url: "https://api-wa.me",
182
+ text: "Access the website"
183
+ },
184
+ {
185
+ type: "cta_call",
186
+ phone_number: "+5566996852025",
187
+ text: "Call us"
188
+ }
189
+ ]
190
+ }
191
+ }).then((response) => {
192
+ console.log(response)
193
+ }).catch(console.error)
194
+ ```
195
+
196
+
197
+ ### List Menu
198
+ ```js
199
+ whatsapp.sendMessage({
200
+ type: TypeMessage.MENU,
201
+ body: {
202
+ to: "14375223417",
203
+ buttonText: "Menu",
204
+ text: "string",
205
+ title: "Menu",
206
+ description: "Description",
207
+ footer: "footer",
208
+ sections: [
209
+ {
210
+ title: "Pizza",
211
+ rows: [
212
+ {
213
+ title: "Pizza 01",
214
+ description: "Example pizza 01",
215
+ rowId: "1"
216
+ }
217
+ ]
218
+ }
219
+ ]
220
+ }
221
+ }).then((response) => {
222
+ console.log(response)
223
+ }).catch(console.error)
224
+ ```
225
+
226
+ ### POLL
227
+ ```js
228
+ whatsapp.sendMessage({
229
+ type: TypeMessage.POLL,
230
+ body: {
231
+ to: "14375223417",
232
+ name: "Do you like PHP?",
233
+ options: [
234
+ "Yes",
235
+ "No"
236
+ ],
237
+ }
238
+ }).then((response) => {
239
+ console.log(response)
240
+ }).catch(console.error)
241
+ ```
242
+
101
243
  ### Link
102
244
  ```js
103
245
  whatsapp.sendMessage({
@@ -1,4 +1,4 @@
1
- import { Init, WebhookBody, TypeMessage, StatusPresence, Contact, Section } from './model';
1
+ import { Init, WebhookBody, TypeMessage, StatusPresence, Contact, Section, InfoInstance, SendMessageRoot, Connect, Location, Buttons, Items } from './types';
2
2
  export declare class WhatsApp {
3
3
  private readonly server;
4
4
  private readonly key;
@@ -7,16 +7,22 @@ export declare class WhatsApp {
7
7
  private body;
8
8
  constructor(data: Init);
9
9
  private request;
10
- connect(): Promise<any>;
11
- info(): Promise<any>;
10
+ connect(): Promise<Connect>;
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, receivePresence: boolean): Promise<{
14
+ status: number;
15
+ message: string;
16
+ }>;
14
17
  updateWebhook(body: WebhookBody): Promise<any>;
15
18
  sendMessage(data: {
16
19
  type: TypeMessage;
17
20
  body: {
18
21
  to: string;
19
22
  msgId?: string;
23
+ header?: {
24
+ title?: string;
25
+ };
20
26
  status?: StatusPresence;
21
27
  text?: string;
22
28
  url?: string;
@@ -27,22 +33,37 @@ export declare class WhatsApp {
27
33
  location?: Location;
28
34
  name?: string;
29
35
  options?: string[];
30
- sections?: Section;
36
+ sections?: Section[];
37
+ buttons?: Buttons[];
31
38
  footer?: string;
32
39
  description?: string;
33
40
  title?: string;
34
41
  buttonText?: string;
35
42
  thumbnailUrl?: string;
36
43
  sourceUrl?: string;
44
+ referenceId?: string;
45
+ code?: string;
46
+ key?: string;
47
+ merchantName?: string;
48
+ keyType?: "CNPJ" | "CPF" | "EMAIL" | "PHONE";
49
+ subtotal?: string;
50
+ totalAmount?: string;
51
+ items?: Items[];
37
52
  };
38
- }, reply?: boolean): Promise<any>;
53
+ }, reply?: boolean): Promise<SendMessageRoot>;
54
+ forwardingMessage(to: string, msgId: string): Promise<any>;
55
+ rejectCall(id: string, from: string): Promise<any>;
56
+ pairingCode(phoneNumber: string): Promise<any>;
39
57
  checkRegisteredWhatsapp(number: string): Promise<any>;
40
58
  contacts(): Promise<any>;
41
59
  contactProfile(id: string): Promise<any>;
42
60
  groups(): Promise<any>;
43
61
  infoGroup(id: string): Promise<any>;
62
+ getInviteGroup(id: string): Promise<any>;
44
63
  updateGroup(id: string, name: string, description: string): Promise<any>;
64
+ updateGroupPicture(id: string, url: string): Promise<any>;
45
65
  leaveGroup(id: string): Promise<any>;
46
66
  createGroup(name: string, participants: string[]): Promise<any>;
67
+ addParticipantsGroup(id: string, participants: string[]): Promise<any>;
47
68
  }
48
69
  export default WhatsApp;
package/dist/WhatsApp.js CHANGED
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.WhatsApp = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const axios_1 = tslib_1.__importDefault(require("axios"));
6
- const model_1 = require("./model");
6
+ const types_1 = require("./types");
7
7
  class WhatsApp {
8
8
  server;
9
9
  key;
@@ -37,90 +37,138 @@ class WhatsApp {
37
37
  }
38
38
  }
39
39
  async connect() {
40
- this.route = model_1.Routes.INSTANCES;
41
- this.method = model_1.HttpMethod.POST;
40
+ this.route = types_1.Routes.INSTANCES;
41
+ this.method = types_1.HttpMethod.POST;
42
42
  return await this.request();
43
43
  }
44
44
  async info() {
45
- this.route = model_1.Routes.INSTANCES;
46
- this.method = model_1.HttpMethod.GET;
45
+ this.route = types_1.Routes.INSTANCES;
46
+ this.method = types_1.HttpMethod.GET;
47
47
  return await this.request();
48
48
  }
49
49
  async logout() {
50
- this.route = model_1.Routes.INSTANCES;
51
- this.method = model_1.HttpMethod.DELETE;
50
+ this.route = types_1.Routes.INSTANCES;
51
+ this.method = types_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}`;
56
- this.method = model_1.HttpMethod.PATCH;
54
+ async setting(markMessageRead, saveMedia, receiveStatusMessage, receivePresence) {
55
+ this.route = types_1.Routes.INSTANCES + `/?markMessageRead=${markMessageRead}&saveMedia=${saveMedia}&receiveStatusMessage=${receiveStatusMessage}&receivePresence=${receivePresence}`;
56
+ this.method = types_1.HttpMethod.PATCH;
57
57
  return await this.request();
58
58
  }
59
59
  async updateWebhook(body) {
60
- this.route = model_1.Routes.INSTANCES;
61
- this.method = model_1.HttpMethod.PUT;
60
+ this.route = types_1.Routes.INSTANCES;
61
+ this.method = types_1.HttpMethod.PUT;
62
62
  this.body = body;
63
63
  return await this.request();
64
64
  }
65
65
  async sendMessage(data, reply = false) {
66
+ if (data.type === types_1.TypeMessage.BUTTON_PIX) {
67
+ const { key, keyType, merchantName, subtotal, totalAmount, items } = data.body;
68
+ if (!key || !keyType || !merchantName || !subtotal || !totalAmount || !items || items.length === 0) {
69
+ throw new Error("Campos obrigatórios para pagamento via PIX estão ausentes.");
70
+ }
71
+ }
66
72
  if (reply) {
67
- this.route = model_1.Routes.MESSAGES + "/" + data.body.msgId + "/" + data.type;
73
+ this.route = types_1.Routes.MESSAGES + "/" + data.body.msgId + "/" + data.type;
68
74
  }
69
75
  else {
70
- this.route = model_1.Routes.MESSAGES + "/" + data.type;
76
+ this.route = types_1.Routes.MESSAGES + "/" + data.type;
71
77
  }
72
- this.method = model_1.HttpMethod.POST;
78
+ this.method = types_1.HttpMethod.POST;
73
79
  this.body = data.body;
74
80
  return await this.request();
75
81
  }
82
+ async forwardingMessage(to, msgId) {
83
+ this.route = types_1.Routes.MESSAGES + "/" + msgId + "/forwarding";
84
+ this.method = types_1.HttpMethod.POST;
85
+ this.body = {
86
+ to,
87
+ };
88
+ return await this.request();
89
+ }
90
+ async rejectCall(id, from) {
91
+ this.route = types_1.Routes.CALL + `/${id}/${from}`;
92
+ this.method = types_1.HttpMethod.DELETE;
93
+ return await this.request();
94
+ }
95
+ async pairingCode(phoneNumber) {
96
+ this.route = types_1.Routes.INSTANCES + "/pairing-code";
97
+ this.body = {
98
+ phoneNumber,
99
+ };
100
+ this.method = types_1.HttpMethod.POST;
101
+ return await this.request();
102
+ }
76
103
  async checkRegisteredWhatsapp(number) {
77
- this.route = model_1.Routes.ACTIONS + "/registered?number=" + number;
78
- this.method = model_1.HttpMethod.GET;
104
+ this.route = types_1.Routes.ACTIONS + "/registered?number=" + number;
105
+ this.method = types_1.HttpMethod.GET;
79
106
  return await this.request();
80
107
  }
81
108
  async contacts() {
82
- this.route = model_1.Routes.CONTACTS;
83
- this.method = model_1.HttpMethod.GET;
109
+ this.route = types_1.Routes.CONTACTS;
110
+ this.method = types_1.HttpMethod.GET;
84
111
  return await this.request();
85
112
  }
86
113
  async contactProfile(id) {
87
- this.route = model_1.Routes.CONTACTS + "/" + id;
88
- this.method = model_1.HttpMethod.GET;
114
+ this.route = types_1.Routes.CONTACTS + "/" + id;
115
+ this.method = types_1.HttpMethod.GET;
89
116
  return await this.request();
90
117
  }
91
118
  async groups() {
92
- this.route = model_1.Routes.GROUPS;
93
- this.method = model_1.HttpMethod.GET;
119
+ this.route = types_1.Routes.GROUPS;
120
+ this.method = types_1.HttpMethod.GET;
94
121
  return await this.request();
95
122
  }
96
123
  async infoGroup(id) {
97
- this.route = model_1.Routes.GROUPS + "/" + id;
98
- this.method = model_1.HttpMethod.GET;
124
+ this.route = types_1.Routes.GROUPS + "/" + id;
125
+ this.method = types_1.HttpMethod.GET;
126
+ return await this.request();
127
+ }
128
+ async getInviteGroup(id) {
129
+ this.route = types_1.Routes.GROUPS + "/" + id + "/invite";
130
+ this.method = types_1.HttpMethod.GET;
99
131
  return await this.request();
100
132
  }
101
133
  async updateGroup(id, name, description) {
102
- this.route = model_1.Routes.GROUPS + "/" + id;
103
- this.method = model_1.HttpMethod.PUT;
134
+ this.route = types_1.Routes.GROUPS + "/" + id;
135
+ this.method = types_1.HttpMethod.PUT;
104
136
  this.body = {
105
137
  name,
106
138
  description
107
139
  };
108
140
  return await this.request();
109
141
  }
142
+ async updateGroupPicture(id, url) {
143
+ this.route = types_1.Routes.GROUPS + "/" + id + "/picture";
144
+ this.method = types_1.HttpMethod.PUT;
145
+ this.body = {
146
+ url
147
+ };
148
+ return await this.request();
149
+ }
110
150
  async leaveGroup(id) {
111
- this.route = model_1.Routes.GROUPS + "/" + id;
112
- this.method = model_1.HttpMethod.DELETE;
151
+ this.route = types_1.Routes.GROUPS + "/" + id;
152
+ this.method = types_1.HttpMethod.DELETE;
113
153
  return await this.request();
114
154
  }
115
155
  async createGroup(name, participants) {
116
- this.route = model_1.Routes.GROUPS;
117
- this.method = model_1.HttpMethod.POST;
156
+ this.route = types_1.Routes.GROUPS;
157
+ this.method = types_1.HttpMethod.POST;
118
158
  this.body = {
119
159
  name,
120
160
  participants
121
161
  };
122
162
  return await this.request();
123
163
  }
164
+ async addParticipantsGroup(id, participants) {
165
+ this.route = types_1.Routes.GROUPS + "/" + id + "/participants";
166
+ this.method = types_1.HttpMethod.POST;
167
+ this.body = {
168
+ participants
169
+ };
170
+ return await this.request();
171
+ }
124
172
  }
125
173
  exports.WhatsApp = WhatsApp;
126
174
  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,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,CAA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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
+ {"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AAI,CAAC,OAAO,EAAE,CAAC;IAC9B,CAAC;IAED,KAAK,CAAC,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;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;AA5OD,4BA4OC;AAGD,kBAAe,QAAQ,CAAC","sourcesContent":["import axios, { AxiosRequestConfig, AxiosResponse } from 'axios';\nimport { Init, HttpMethod, WebhookBody, Routes, TypeMessage, StatusPresence, Contact, Section, InfoInstance, SendMessageRoot, Connect, Location, Buttons, Items } from './types';\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<Connect> {\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, receivePresence: boolean): Promise<{ status: number, message: string }> {\n this.route = Routes.INSTANCES + `/?markMessageRead=${markMessageRead}&saveMedia=${saveMedia}&receiveStatusMessage=${receiveStatusMessage}&receivePresence=${receivePresence}`;\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 header?: {\n title?: string,\n },\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 buttons?: Buttons[],\n footer?: string,\n description?: string,\n title?: string,\n buttonText?: string,\n thumbnailUrl?: string,\n sourceUrl?: string,\n referenceId?: string,\n code?: string,\n key?: string,\n merchantName?: string,\n keyType?: \"CNPJ\" | \"CPF\" | \"EMAIL\" | \"PHONE\",\n subtotal?: string,\n totalAmount?: string,\n items?: Items[],\n }\n }, reply: boolean = false): Promise<SendMessageRoot> {\n\n if (data.type === TypeMessage.BUTTON_PIX) {\n const { key, keyType, merchantName, subtotal, totalAmount, items } = data.body;\n if (!key || !keyType || !merchantName || !subtotal || !totalAmount || !items || items.length === 0) {\n throw new Error(\"Campos obrigatórios para pagamento via PIX estão ausentes.\");\n }\n }\n\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"]}
package/dist/exemple.js CHANGED
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  const WhatsApp_1 = tslib_1.__importDefault(require("./WhatsApp"));
5
- const model_1 = require("./model");
5
+ const types_1 = require("./types");
6
6
  const whatsapp = new WhatsApp_1.default({ server: "", key: "" });
7
7
  const to = "559999999999"; // If you want to send it to the group = 123456789@us
8
8
  whatsapp.info().then((response) => {
@@ -18,16 +18,16 @@ whatsapp.contacts().then((response) => {
18
18
  console.log(response);
19
19
  }).catch(console.error);
20
20
  whatsapp.sendMessage({
21
- type: model_1.TypeMessage.PRESENCE,
21
+ type: types_1.TypeMessage.PRESENCE,
22
22
  body: {
23
23
  to: to,
24
- status: model_1.StatusPresence.COMPOSING
24
+ status: types_1.StatusPresence.COMPOSING
25
25
  }
26
26
  }).then((response) => {
27
27
  console.log(response);
28
28
  }).catch(console.error);
29
29
  whatsapp.sendMessage({
30
- type: model_1.TypeMessage.TEXT,
30
+ type: types_1.TypeMessage.TEXT,
31
31
  body: {
32
32
  to: to,
33
33
  text: "Hey"
@@ -36,7 +36,150 @@ whatsapp.sendMessage({
36
36
  console.log(response);
37
37
  }).catch(console.error);
38
38
  whatsapp.sendMessage({
39
- type: model_1.TypeMessage.TEXT,
39
+ type: types_1.TypeMessage.BUTTON_PIX,
40
+ body: {
41
+ to: "14375223417",
42
+ title: "Pizza",
43
+ text: "Pizza ",
44
+ referenceId: "apiwame",
45
+ code: "0020",
46
+ key: "23711695000115",
47
+ merchantName: "CACHE SISTEMAS WEB",
48
+ keyType: "CNPJ",
49
+ items: [
50
+ {
51
+ id: "123",
52
+ name: "Pizza G",
53
+ price: 10,
54
+ quantity: 10
55
+ },
56
+ ],
57
+ subtotal: "90",
58
+ totalAmount: "100"
59
+ }
60
+ }).then((response) => {
61
+ console.log(response);
62
+ }).catch(console.error);
63
+ whatsapp.sendMessage({
64
+ type: types_1.TypeMessage.BUTTON_PIX,
65
+ body: {
66
+ to: "14375223417",
67
+ title: "Pizza",
68
+ text: "Pizza ",
69
+ referenceId: "apiwame",
70
+ code: "0020",
71
+ key: "23711695000115",
72
+ merchantName: "CACHE SISTEMAS WEB",
73
+ keyType: "CNPJ",
74
+ items: [
75
+ {
76
+ id: "123",
77
+ name: "Pizza G",
78
+ price: 10,
79
+ quantity: 10
80
+ },
81
+ ],
82
+ subtotal: "90",
83
+ totalAmount: "100"
84
+ }
85
+ }).then((response) => {
86
+ console.log(response);
87
+ }).catch(console.error);
88
+ whatsapp.sendMessage({
89
+ type: types_1.TypeMessage.BUTTON_REPLY,
90
+ body: {
91
+ to: "14375223417",
92
+ header: {
93
+ title: "Example Header",
94
+ },
95
+ text: "This is a test",
96
+ footer: "choose an option",
97
+ buttons: [
98
+ {
99
+ type: "quick_reply",
100
+ id: "uniqId1",
101
+ text: "Yes"
102
+ },
103
+ {
104
+ type: "quick_reply",
105
+ id: "uniqId2",
106
+ text: "No"
107
+ }
108
+ ]
109
+ }
110
+ }).then((response) => {
111
+ console.log(response);
112
+ }).catch(console.error);
113
+ whatsapp.sendMessage({
114
+ type: types_1.TypeMessage.BUTTON_ACTION,
115
+ body: {
116
+ to: "14375223417",
117
+ header: {
118
+ title: "Example Header",
119
+ },
120
+ text: "This is a test",
121
+ footer: "choose an option",
122
+ buttons: [
123
+ {
124
+ type: "cta_copy",
125
+ copy_code: "1234567890",
126
+ text: "Copy barcode"
127
+ },
128
+ {
129
+ type: "cta_url",
130
+ url: "https://api-wa.me",
131
+ text: "Access the website"
132
+ },
133
+ {
134
+ type: "cta_call",
135
+ phone_number: "+5566996852025",
136
+ text: "Call us"
137
+ }
138
+ ]
139
+ }
140
+ }).then((response) => {
141
+ console.log(response);
142
+ }).catch(console.error);
143
+ whatsapp.sendMessage({
144
+ type: types_1.TypeMessage.MENU,
145
+ body: {
146
+ to: "14375223417",
147
+ buttonText: "Menu",
148
+ text: "string",
149
+ title: "Menu",
150
+ description: "Description",
151
+ footer: "footer",
152
+ sections: [
153
+ {
154
+ title: "Pizza",
155
+ rows: [
156
+ {
157
+ title: "Pizza 01",
158
+ description: "Example pizza 01",
159
+ rowId: "1"
160
+ }
161
+ ]
162
+ }
163
+ ]
164
+ }
165
+ }).then((response) => {
166
+ console.log(response);
167
+ }).catch(console.error);
168
+ whatsapp.sendMessage({
169
+ type: types_1.TypeMessage.POLL,
170
+ body: {
171
+ to: "14375223417",
172
+ name: "Do you like PHP?",
173
+ options: [
174
+ "Yes",
175
+ "No"
176
+ ],
177
+ }
178
+ }).then((response) => {
179
+ console.log(response);
180
+ }).catch(console.error);
181
+ whatsapp.sendMessage({
182
+ type: types_1.TypeMessage.TEXT,
40
183
  body: {
41
184
  msgId: "SKJH455AJKJ",
42
185
  to: to,
@@ -46,7 +189,7 @@ whatsapp.sendMessage({
46
189
  console.log(response);
47
190
  }).catch(console.error);
48
191
  whatsapp.sendMessage({
49
- type: model_1.TypeMessage.AUDIO,
192
+ type: types_1.TypeMessage.AUDIO,
50
193
  body: {
51
194
  to: to,
52
195
  url: ""
@@ -55,7 +198,7 @@ whatsapp.sendMessage({
55
198
  console.log(response);
56
199
  }).catch(console.error);
57
200
  whatsapp.sendMessage({
58
- type: model_1.TypeMessage.IMAGE,
201
+ type: types_1.TypeMessage.IMAGE,
59
202
  body: {
60
203
  to: to,
61
204
  url: ""
@@ -64,7 +207,7 @@ whatsapp.sendMessage({
64
207
  console.log(response);
65
208
  }).catch(console.error);
66
209
  whatsapp.sendMessage({
67
- type: model_1.TypeMessage.VIDEO,
210
+ type: types_1.TypeMessage.VIDEO,
68
211
  body: {
69
212
  to: to,
70
213
  url: ""
@@ -73,7 +216,7 @@ whatsapp.sendMessage({
73
216
  console.log(response);
74
217
  }).catch(console.error);
75
218
  whatsapp.sendMessage({
76
- type: model_1.TypeMessage.DOCUMENT,
219
+ type: types_1.TypeMessage.DOCUMENT,
77
220
  body: {
78
221
  to: to,
79
222
  url: "",
@@ -84,7 +227,7 @@ whatsapp.sendMessage({
84
227
  console.log(response);
85
228
  }).catch(console.error);
86
229
  whatsapp.sendMessage({
87
- type: model_1.TypeMessage.CONTACT,
230
+ type: types_1.TypeMessage.CONTACT,
88
231
  body: {
89
232
  to: to,
90
233
  contact: {
@@ -97,7 +240,7 @@ whatsapp.sendMessage({
97
240
  console.log(response);
98
241
  }).catch(console.error);
99
242
  whatsapp.sendMessage({
100
- type: model_1.TypeMessage.REACTION,
243
+ type: types_1.TypeMessage.REACTION,
101
244
  body: {
102
245
  to: to,
103
246
  msgId: "ASDDF872AHDURBSG",