@raphaelvserafim/client-api-whatsapp 1.0.8 → 1.0.9

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.
@@ -10,7 +10,12 @@ export declare class WhatsApp {
10
10
  connect(): Promise<Connect>;
11
11
  info(): Promise<InfoInstance>;
12
12
  logout(): Promise<any>;
13
- setting(markMessageRead: boolean, saveMedia: boolean, receiveStatusMessage: boolean, receivePresence: boolean): Promise<{
13
+ setting({ markMessageRead, saveMedia, receiveStatusMessage, receivePresence }: {
14
+ markMessageRead: boolean;
15
+ receiveStatusMessage: boolean;
16
+ receivePresence: boolean;
17
+ saveMedia: boolean;
18
+ }): Promise<{
14
19
  status: number;
15
20
  message: string;
16
21
  }>;
package/dist/WhatsApp.js CHANGED
@@ -51,7 +51,7 @@ class WhatsApp {
51
51
  this.method = types_1.HttpMethod.DELETE;
52
52
  return await this.request();
53
53
  }
54
- async setting(markMessageRead, saveMedia, receiveStatusMessage, receivePresence) {
54
+ async setting({ markMessageRead, saveMedia, receiveStatusMessage, receivePresence }) {
55
55
  this.route = types_1.Routes.INSTANCES + `/?markMessageRead=${markMessageRead}&saveMedia=${saveMedia}&receiveStatusMessage=${receiveStatusMessage}&receivePresence=${receivePresence}`;
56
56
  this.method = types_1.HttpMethod.PATCH;
57
57
  return await this.request();
@@ -1 +1 @@
1
- {"version":3,"file":"WhatsApp.js","sourceRoot":"","sources":["../src/WhatsApp.ts"],"names":[],"mappings":";;;;AAAA,0DAAiE;AACjE,mCAAiL;AAEjL,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,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B,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"]}
1
+ {"version":3,"file":"WhatsApp.js","sourceRoot":"","sources":["../src/WhatsApp.ts"],"names":[],"mappings":";;;;AAAA,0DAAiE;AACjE,mCAAiL;AAEjL,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,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,IAAA,eAAK,EAAC,OAAO,CAAC,CAAC;YACtC,OAAO,QAAQ,CAAC,IA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EAAE,GAAG,UAAU,CAAC;QACnD,IAAI,CAAC,MAAM,GAAG,kBAAU,CAAC,GAAG,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG;YACV,GAAG;SACJ,CAAA;QACD,OAAO,MAAM,IAAI,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, saveMedia, receiveStatusMessage, receivePresence }: { markMessageRead: boolean, receiveStatusMessage: boolean, receivePresence: boolean; saveMedia: 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raphaelvserafim/client-api-whatsapp",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
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
@@ -55,7 +55,7 @@ export class WhatsApp {
55
55
  }
56
56
 
57
57
 
58
- async setting(markMessageRead: boolean, saveMedia: boolean, receiveStatusMessage: boolean, receivePresence: boolean): Promise<{ status: number, message: string }> {
58
+ async setting({ markMessageRead, saveMedia, receiveStatusMessage, receivePresence }: { markMessageRead: boolean, receiveStatusMessage: boolean, receivePresence: boolean; saveMedia: boolean, }): Promise<{ status: number, message: string }> {
59
59
  this.route = Routes.INSTANCES + `/?markMessageRead=${markMessageRead}&saveMedia=${saveMedia}&receiveStatusMessage=${receiveStatusMessage}&receivePresence=${receivePresence}`;
60
60
  this.method = HttpMethod.PATCH;
61
61
  return await this.request();