@raphaelvserafim/client-api-whatsapp 1.0.8 → 1.2.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.
Files changed (60) hide show
  1. package/README.md +512 -297
  2. package/dist/WhatsApp.d.ts +142 -31
  3. package/dist/WhatsApp.js +111 -167
  4. package/dist/WhatsApp.js.map +1 -1
  5. package/dist/client/HttpClient.d.ts +6 -0
  6. package/dist/client/HttpClient.js +29 -0
  7. package/dist/client/HttpClient.js.map +1 -0
  8. package/dist/client/IHttpClient.d.ts +9 -0
  9. package/dist/client/IHttpClient.js +3 -0
  10. package/dist/client/IHttpClient.js.map +1 -0
  11. package/dist/errors.d.ts +5 -0
  12. package/dist/errors.js +13 -0
  13. package/dist/errors.js.map +1 -0
  14. package/dist/index.d.ts +14 -1
  15. package/dist/index.js +33 -3
  16. package/dist/index.js.map +1 -1
  17. package/dist/services/ActionService.d.ts +9 -0
  18. package/dist/services/ActionService.js +32 -0
  19. package/dist/services/ActionService.js.map +1 -0
  20. package/dist/services/BusinessService.d.ts +10 -0
  21. package/dist/services/BusinessService.js +43 -0
  22. package/dist/services/BusinessService.js.map +1 -0
  23. package/dist/services/CallService.d.ts +8 -0
  24. package/dist/services/CallService.js +24 -0
  25. package/dist/services/CallService.js.map +1 -0
  26. package/dist/services/ChatService.d.ts +16 -0
  27. package/dist/services/ChatService.js +38 -0
  28. package/dist/services/ChatService.js.map +1 -0
  29. package/dist/services/CommunityService.d.ts +28 -0
  30. package/dist/services/CommunityService.js +76 -0
  31. package/dist/services/CommunityService.js.map +1 -0
  32. package/dist/services/ContactService.d.ts +15 -0
  33. package/dist/services/ContactService.js +30 -0
  34. package/dist/services/ContactService.js.map +1 -0
  35. package/dist/services/GroupService.d.ts +32 -0
  36. package/dist/services/GroupService.js +104 -0
  37. package/dist/services/GroupService.js.map +1 -0
  38. package/dist/services/InstanceService.d.ts +28 -0
  39. package/dist/services/InstanceService.js +124 -0
  40. package/dist/services/InstanceService.js.map +1 -0
  41. package/dist/services/LabelService.d.ts +17 -0
  42. package/dist/services/LabelService.js +43 -0
  43. package/dist/services/LabelService.js.map +1 -0
  44. package/dist/services/MessageService.d.ts +51 -0
  45. package/dist/services/MessageService.js +106 -0
  46. package/dist/services/MessageService.js.map +1 -0
  47. package/dist/types/index.d.ts +155 -11
  48. package/dist/types/index.js +10 -0
  49. package/dist/types/index.js.map +1 -1
  50. package/package.json +6 -11
  51. package/.babelrc +0 -3
  52. package/dist/exemple.d.ts +0 -1
  53. package/dist/exemple.js +0 -264
  54. package/dist/exemple.js.map +0 -1
  55. package/src/WhatsApp.ts +0 -245
  56. package/src/exemple.ts +0 -312
  57. package/src/index.ts +0 -2
  58. package/src/types/index.ts +0 -190
  59. package/tsconfig.compile.json +0 -15
  60. package/tsconfig.json +0 -35
@@ -17,6 +17,10 @@ var Routes;
17
17
  Routes["GROUPS"] = "groups";
18
18
  Routes["ACTIONS"] = "actions";
19
19
  Routes["CALL"] = "call";
20
+ Routes["CHAT"] = "chat";
21
+ Routes["LABELS"] = "labels";
22
+ Routes["COMMUNITY"] = "community";
23
+ Routes["BUSINESS"] = "business";
20
24
  })(Routes || (exports.Routes = Routes = {}));
21
25
  var TypeMessage;
22
26
  (function (TypeMessage) {
@@ -36,6 +40,12 @@ var TypeMessage;
36
40
  TypeMessage["BUTTON_PIX"] = "pix";
37
41
  TypeMessage["POLL"] = "survey";
38
42
  TypeMessage["MENU"] = "list";
43
+ TypeMessage["STICKER"] = "sticker";
44
+ TypeMessage["VIDEO_NOTE"] = "video-note";
45
+ TypeMessage["POLL_V2"] = "poll";
46
+ TypeMessage["EVENT"] = "event";
47
+ TypeMessage["PIN"] = "pin";
48
+ TypeMessage["CALL_LINK"] = "call-link";
39
49
  })(TypeMessage || (exports.TypeMessage = TypeMessage = {}));
40
50
  var StatusPresence;
41
51
  (function (StatusPresence) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/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,WAiBX;AAjBD,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;IACf,4CAA6B,CAAA;IAC7B,8CAA+B,CAAA;IAC/B,iCAAkB,CAAA;IAClB,8BAAe,CAAA;IACf,4BAAa,CAAA;AACf,CAAC,EAjBW,WAAW,2BAAX,WAAW,QAiBtB;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 BUTTON_REPLY = 'button_reply',\n BUTTON_ACTION = 'button_action',\n BUTTON_PIX = 'pix',\n POLL = 'survey',\n MENU = 'list',\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\nexport interface InfoInstance {\n status: number\n instance: Instance\n}\n\nexport interface Instance {\n receive_status_message: boolean\n save_media: boolean\n receive_presence: boolean\n permission: number\n mark_messages: boolean\n blocked: boolean\n user?: User\n phoneConnected: boolean\n webhook: Webhook;\n businessProfile?: BusinessProfile;\n}\n\nexport interface User {\n id?: string;\n lid?: string;\n name?: string;\n imageProfile?: string;\n\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\nexport interface Connect {\n status: number;\n phoneConnected: boolean;\n qrcode: string;\n image: string;\n user?: User;\n}\n\n\n\nexport interface BusinessProfile {\n wid: string\n description: string\n website: any[]\n category: string\n business_hours: {}\n}\n\n\n\nexport interface Buttons {\n type: \"quick_reply\" | \"cta_copy\" | \"cta_url\" | \"cta_call\",\n copy_code?: string,\n phone_number?: string,\n url?: string,\n id?: string,\n text: string;\n}\n\n\nexport interface Items {\n id: string,\n name: string,\n price: number,\n quantity: number\n}"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/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,MAWX;AAXD,WAAY,MAAM;IAChB,gCAAsB,CAAA;IACtB,8BAAoB,CAAA;IACpB,+BAAqB,CAAA;IACrB,2BAAiB,CAAA;IACjB,6BAAmB,CAAA;IACnB,uBAAa,CAAA;IACb,uBAAa,CAAA;IACb,2BAAiB,CAAA;IACjB,iCAAuB,CAAA;IACvB,+BAAqB,CAAA;AACvB,CAAC,EAXW,MAAM,sBAAN,MAAM,QAWjB;AAGD,IAAY,WAuBX;AAvBD,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;IACf,4CAA6B,CAAA;IAC7B,8CAA+B,CAAA;IAC/B,iCAAkB,CAAA;IAClB,8BAAe,CAAA;IACf,4BAAa,CAAA;IACb,kCAAmB,CAAA;IACnB,wCAAyB,CAAA;IACzB,+BAAgB,CAAA;IAChB,8BAAe,CAAA;IACf,0BAAW,CAAA;IACX,sCAAuB,CAAA;AACzB,CAAC,EAvBW,WAAW,2BAAX,WAAW,QAuBtB;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 CHAT = 'chat',\n LABELS = 'labels',\n COMMUNITY = 'community',\n BUSINESS = 'business',\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 BUTTON_REPLY = 'button_reply',\n BUTTON_ACTION = 'button_action',\n BUTTON_PIX = 'pix',\n POLL = 'survey',\n MENU = 'list',\n STICKER = 'sticker',\n VIDEO_NOTE = 'video-note',\n POLL_V2 = 'poll',\n EVENT = 'event',\n PIN = 'pin',\n CALL_LINK = 'call-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\nexport interface ApiResponse {\n status: number;\n message: string;\n}\n\n\nexport interface WebhookBody {\n allowWebhook: boolean;\n allowNumber?: string;\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\nexport interface InfoInstance {\n status: number;\n instance: Instance;\n}\n\nexport interface Instance {\n receive_status_message: boolean;\n save_media: boolean;\n receive_presence: boolean;\n permission: number;\n mark_messages: boolean;\n blocked: boolean;\n user?: User;\n phoneConnected: boolean;\n webhook: Webhook;\n businessProfile?: BusinessProfile;\n}\n\nexport interface User {\n id?: string;\n lid?: string;\n name?: string;\n imageProfile?: string;\n}\n\nexport interface Webhook {\n allowWebhook: boolean;\n allowNumber?: string;\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: MessageData;\n}\n\nexport interface MessageData {\n key: MessageKey;\n message: MessageContent;\n messageTimestamp: string;\n status: string;\n}\n\nexport interface MessageKey {\n remoteJid: string;\n fromMe: boolean;\n id: string;\n}\n\nexport interface MessageContent {\n extendedTextMessage?: ExtendedTextMessage;\n}\n\nexport interface ExtendedTextMessage {\n text: string;\n}\n\nexport interface Connect {\n status: number;\n phoneConnected: boolean;\n qrcode: string;\n image: string;\n user?: User;\n}\n\n\nexport interface PairingCodeResponse {\n status: number;\n code: string;\n}\n\n\nexport interface BusinessProfile {\n wid: string;\n description: string;\n website: string[];\n category: string;\n business_hours: Record<string, unknown>;\n}\n\n\n\nexport interface Buttons {\n type: \"quick_reply\" | \"cta_copy\" | \"cta_url\" | \"cta_call\";\n copy_code?: string;\n phone_number?: string;\n url?: string;\n id?: string;\n text: string;\n}\n\n\nexport interface Items {\n id: string;\n name: string;\n price: number;\n quantity: number;\n}\n\n\nexport interface HeaderMedia {\n title?: string;\n hasMediaAttachment?: boolean;\n imageMessage?: { url: string };\n videoMessage?: { url: string };\n documentMessage?: { url: string; mimetype?: string; fileName?: string };\n}\n\n\nexport interface DownloadableMessage {\n mediaKey: string;\n directPath: string;\n url: string;\n}\n\n\nexport interface Product {\n name: string;\n description?: string;\n originCountryCode?: string;\n currency?: string;\n price?: number;\n images?: { url: string }[];\n}\n\n\nexport interface CommunityCreate {\n name: string;\n subject: string;\n}\n\nexport interface CommunityUpdate {\n subject: string;\n description: string;\n}\n\n\nexport interface GroupParticipantsAction {\n participants: string[];\n action: 'reject' | 'approve';\n}\n\n\nexport interface MobileRegisterData {\n phoneNumberCountryCode: string;\n phoneNumberNationalNumber: string;\n phoneNumberMobileCountryCode: string;\n phoneNumberMobileNetworkCode: string;\n}\n\n\nexport interface EventData {\n to: string;\n name: string;\n description?: string;\n startTime?: string;\n locationName?: string;\n locationAddress?: string;\n}\n\n\nexport interface RegisteredResponse {\n status: number;\n registered: boolean;\n}\n\n\nexport interface ContactInfo {\n id: string;\n name?: string;\n notify?: string;\n imgUrl?: string;\n}\n\n\nexport interface GroupInfo {\n id: string;\n subject: string;\n owner: string;\n creation: number;\n desc?: string;\n participants: GroupParticipant[];\n}\n\nexport interface GroupParticipant {\n id: string;\n admin?: string;\n}\n\n\nexport interface InviteCodeResponse {\n status: number;\n inviteCode: string;\n}\n\n\nexport interface ChatInfo {\n id: string;\n name?: string;\n timestamp?: number;\n unreadCount?: number;\n}\n\n\nexport interface LabelInfo {\n id: string;\n name: string;\n color?: number;\n}\n\n\nexport interface CommunityInfo {\n id: string;\n name: string;\n subject?: string;\n description?: string;\n participants?: GroupParticipant[];\n}\n\n\nexport interface CatalogResponse {\n status: number;\n data: Product[];\n cursor?: string;\n}\n\n\nexport interface WebhookStatistics {\n status: number;\n data: Record<string, unknown>;\n}\n\n\nexport interface ListMessagesResponse {\n status: number;\n data: MessageData[];\n page?: number;\n limit?: number;\n total?: number;\n}\n\n\nexport interface DownloadMediaResponse {\n status: number;\n data: string;\n}\n\n\nexport interface CallResponse {\n status: number;\n data: Record<string, unknown>;\n}\n"]}
package/package.json CHANGED
@@ -1,9 +1,12 @@
1
1
  {
2
2
  "name": "@raphaelvserafim/client-api-whatsapp",
3
- "version": "1.0.8",
3
+ "version": "1.2.0",
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",
7
+ "files": [
8
+ "dist"
9
+ ],
7
10
  "private": false,
8
11
  "keywords": [
9
12
  "api",
@@ -27,19 +30,11 @@
27
30
  "url": "https://github.com/raphaelvserafim/client-api-whatsapp.git"
28
31
  },
29
32
  "dependencies": {
30
- "axios": "^1.6.8",
31
- "fs": "^0.0.1-security",
32
- "typescript": "^5.4.3"
33
+ "axios": "^1.6.8"
33
34
  },
34
35
  "devDependencies": {
35
- "@babel/preset-env": "^7.24.3",
36
- "@jest/globals": "^29.7.0",
37
- "@types/jest": "^29.5.12",
38
36
  "@types/node": "^20.11.30",
39
- "babel-jest": "^29.7.0",
40
- "jest": "^29.7.0",
41
- "ts-jest": "^29.1.2",
42
37
  "tslib": "^2.6.2",
43
38
  "typescript": "^5.4.3"
44
39
  }
45
- }
40
+ }
package/.babelrc DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "presets": ["@babel/preset-env"]
3
- }
package/dist/exemple.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};
package/dist/exemple.js DELETED
@@ -1,264 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const WhatsApp_1 = tslib_1.__importDefault(require("./WhatsApp"));
5
- const types_1 = require("./types");
6
- const whatsapp = new WhatsApp_1.default({ server: "", key: "" });
7
- const to = "559999999999"; // If you want to send it to the group = 123456789@us
8
- whatsapp.info().then((response) => {
9
- console.log(response);
10
- }).catch(console.error);
11
- whatsapp.connect().then((response) => {
12
- console.log(response);
13
- }).catch(console.error);
14
- whatsapp.logout().then((response) => {
15
- console.log(response);
16
- }).catch(console.error);
17
- whatsapp.contacts().then((response) => {
18
- console.log(response);
19
- }).catch(console.error);
20
- whatsapp.sendMessage({
21
- type: types_1.TypeMessage.PRESENCE,
22
- body: {
23
- to: to,
24
- status: types_1.StatusPresence.COMPOSING
25
- }
26
- }).then((response) => {
27
- console.log(response);
28
- }).catch(console.error);
29
- whatsapp.sendMessage({
30
- type: types_1.TypeMessage.TEXT,
31
- body: {
32
- to: to,
33
- text: "Hey"
34
- }
35
- }).then((response) => {
36
- console.log(response);
37
- }).catch(console.error);
38
- whatsapp.sendMessage({
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,
183
- body: {
184
- msgId: "SKJH455AJKJ",
185
- to: to,
186
- text: "Hey"
187
- }
188
- }, true).then((response) => {
189
- console.log(response);
190
- }).catch(console.error);
191
- whatsapp.sendMessage({
192
- type: types_1.TypeMessage.AUDIO,
193
- body: {
194
- to: to,
195
- url: ""
196
- }
197
- }).then((response) => {
198
- console.log(response);
199
- }).catch(console.error);
200
- whatsapp.sendMessage({
201
- type: types_1.TypeMessage.IMAGE,
202
- body: {
203
- to: to,
204
- url: ""
205
- }
206
- }).then((response) => {
207
- console.log(response);
208
- }).catch(console.error);
209
- whatsapp.sendMessage({
210
- type: types_1.TypeMessage.VIDEO,
211
- body: {
212
- to: to,
213
- url: ""
214
- }
215
- }).then((response) => {
216
- console.log(response);
217
- }).catch(console.error);
218
- whatsapp.sendMessage({
219
- type: types_1.TypeMessage.DOCUMENT,
220
- body: {
221
- to: to,
222
- url: "",
223
- mimetype: "",
224
- fileName: ""
225
- }
226
- }).then((response) => {
227
- console.log(response);
228
- }).catch(console.error);
229
- whatsapp.sendMessage({
230
- type: types_1.TypeMessage.CONTACT,
231
- body: {
232
- to: to,
233
- contact: {
234
- fullName: "Raphael",
235
- phoneNumber: to,
236
- organization: "api-wa.me"
237
- }
238
- }
239
- }).then((response) => {
240
- console.log(response);
241
- }).catch(console.error);
242
- whatsapp.sendMessage({
243
- type: types_1.TypeMessage.REACTION,
244
- body: {
245
- to: to,
246
- msgId: "ASDDF872AHDURBSG",
247
- text: "🤖"
248
- }
249
- }).then((response) => {
250
- console.log(response);
251
- }).catch(console.error);
252
- whatsapp.groups().then((response) => {
253
- console.log(response);
254
- }).catch(console.error);
255
- whatsapp.infoGroup("123456789@us").then((response) => {
256
- console.log(response);
257
- }).catch(console.error);
258
- whatsapp.createGroup("Devs", [to]).then((response) => {
259
- console.log(response);
260
- }).catch(console.error);
261
- whatsapp.updateGroup("123456789@us", "Devs", "Only developers !").then((response) => {
262
- console.log(response);
263
- }).catch(console.error);
264
- //# sourceMappingURL=exemple.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"exemple.js","sourceRoot":"","sources":["../src/exemple.ts"],"names":[],"mappings":";;;AAAA,kEAAkC;AAClC,mCAAsD;AAEtD,MAAM,QAAQ,GAAG,IAAI,kBAAQ,CAAC,EAAE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AAC,QAAQ,EAAE,EAAE;IAClC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;AACvB,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;AAGvB,QAAQ,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE;IACnD,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;AACvB,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;AAIvB,QAAQ,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE;IACnD,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;AACvB,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;AAGvB,QAAQ,CAAC,WAAW,CAAC,cAAc,EAAE,MAAM,EAAE,mBAAmB,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE;IAClF,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;AACvB,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA","sourcesContent":["import WhatsApp from \"./WhatsApp\";\nimport { StatusPresence, TypeMessage } from \"./types\";\n\nconst whatsapp = new WhatsApp({ server: \"\", key: \"\" });\n\nconst to = \"559999999999\" // If you want to send it to the group = 123456789@us\n\nwhatsapp.info().then((response) => {\n console.log(response)\n}).catch(console.error)\n\n\nwhatsapp.connect().then((response) => {\n console.log(response)\n}).catch(console.error);\n\n\nwhatsapp.logout().then((response) => {\n console.log(response)\n}).catch(console.error);\n\n\nwhatsapp.contacts().then((response) => {\n console.log(response)\n}).catch(console.error)\n\n\nwhatsapp.sendMessage({\n type: TypeMessage.PRESENCE,\n body: {\n to: to,\n status: StatusPresence.COMPOSING\n }\n}).then((response) => {\n console.log(response)\n}).catch(console.error)\n\n\nwhatsapp.sendMessage({\n type: TypeMessage.TEXT,\n body: {\n to: to,\n text: \"Hey\"\n }\n}).then((response) => {\n console.log(response)\n\n}).catch(console.error)\n\nwhatsapp.sendMessage({\n type: TypeMessage.BUTTON_PIX,\n body: {\n to: \"14375223417\",\n title: \"Pizza\",\n text: \"Pizza \",\n referenceId: \"apiwame\",\n code: \"0020\",\n key: \"23711695000115\",\n merchantName: \"CACHE SISTEMAS WEB\",\n keyType: \"CNPJ\",\n items: [\n {\n id: \"123\",\n name: \"Pizza G\",\n price: 10,\n quantity: 10\n },\n ],\n subtotal: \"90\",\n totalAmount: \"100\"\n }\n}).then((response) => {\n console.log(response)\n}).catch(console.error)\n\nwhatsapp.sendMessage({\n type: TypeMessage.BUTTON_PIX,\n body: {\n to: \"14375223417\",\n title: \"Pizza\",\n text: \"Pizza \",\n referenceId: \"apiwame\",\n code: \"0020\",\n key: \"23711695000115\",\n merchantName: \"CACHE SISTEMAS WEB\",\n keyType: \"CNPJ\",\n items: [\n {\n id: \"123\",\n name: \"Pizza G\",\n price: 10,\n quantity: 10\n },\n ],\n subtotal: \"90\",\n totalAmount: \"100\"\n }\n}).then((response) => {\n console.log(response)\n}).catch(console.error)\n\n\nwhatsapp.sendMessage({\n type: TypeMessage.BUTTON_REPLY,\n body: {\n to: \"14375223417\",\n header: {\n title: \"Example Header\",\n },\n text: \"This is a test\",\n footer: \"choose an option\",\n buttons: [\n {\n type: \"quick_reply\",\n id: \"uniqId1\",\n text: \"Yes\"\n },\n {\n type: \"quick_reply\",\n id: \"uniqId2\",\n text: \"No\"\n }\n ]\n }\n}).then((response) => {\n console.log(response)\n}).catch(console.error)\n\n\nwhatsapp.sendMessage({\n type: TypeMessage.BUTTON_ACTION,\n body: {\n to: \"14375223417\",\n header: {\n title: \"Example Header\",\n },\n text: \"This is a test\",\n footer: \"choose an option\",\n buttons: [\n {\n type: \"cta_copy\",\n copy_code: \"1234567890\",\n text: \"Copy barcode\"\n },\n {\n type: \"cta_url\",\n url: \"https://api-wa.me\",\n text: \"Access the website\"\n },\n {\n type: \"cta_call\",\n phone_number: \"+5566996852025\",\n text: \"Call us\"\n }\n ]\n }\n}).then((response) => {\n console.log(response)\n}).catch(console.error)\n\n\nwhatsapp.sendMessage({\n type: TypeMessage.MENU,\n body: {\n to: \"14375223417\",\n buttonText: \"Menu\",\n text: \"string\",\n title: \"Menu\",\n description: \"Description\",\n footer: \"footer\",\n sections: [\n {\n title: \"Pizza\",\n rows: [\n {\n title: \"Pizza 01\",\n description: \"Example pizza 01\",\n rowId: \"1\"\n }\n ]\n }\n ]\n }\n}).then((response) => {\n console.log(response)\n}).catch(console.error)\n\n\nwhatsapp.sendMessage({\n type: TypeMessage.POLL,\n body: {\n to: \"14375223417\",\n name: \"Do you like PHP?\",\n options: [\n \"Yes\",\n \"No\"\n ],\n }\n}).then((response) => {\n console.log(response)\n}).catch(console.error)\n\n\nwhatsapp.sendMessage({\n type: TypeMessage.TEXT,\n body: {\n msgId: \"SKJH455AJKJ\",\n to: to,\n text: \"Hey\"\n }\n}, true).then((response) => {\n console.log(response)\n}).catch(console.error)\n\n\n\nwhatsapp.sendMessage({\n type: TypeMessage.AUDIO,\n body: {\n to: to,\n url: \"\"\n }\n}).then((response) => {\n console.log(response)\n}).catch(console.error)\n\n\nwhatsapp.sendMessage({\n type: TypeMessage.IMAGE,\n body: {\n to: to,\n url: \"\"\n }\n}).then((response) => {\n console.log(response)\n}).catch(console.error)\n\n\nwhatsapp.sendMessage({\n type: TypeMessage.VIDEO,\n body: {\n to: to,\n url: \"\"\n }\n}).then((response) => {\n console.log(response)\n}).catch(console.error)\n\n\n\nwhatsapp.sendMessage({\n type: TypeMessage.DOCUMENT,\n body: {\n to: to,\n url: \"\",\n mimetype: \"\",\n fileName: \"\"\n }\n}).then((response) => {\n console.log(response)\n}).catch(console.error)\n\n\nwhatsapp.sendMessage({\n type: TypeMessage.CONTACT,\n body: {\n to: to,\n contact: {\n fullName: \"Raphael\",\n phoneNumber: to,\n organization: \"api-wa.me\"\n }\n }\n}).then((response) => {\n console.log(response)\n}).catch(console.error)\n\n\nwhatsapp.sendMessage({\n type: TypeMessage.REACTION,\n body: {\n to: to,\n msgId: \"ASDDF872AHDURBSG\",\n text: \"🤖\"\n }\n}).then((response) => {\n console.log(response)\n}).catch(console.error)\n\n\nwhatsapp.groups().then((response) => {\n console.log(response)\n}).catch(console.error)\n\n\nwhatsapp.infoGroup(\"123456789@us\").then((response) => {\n console.log(response)\n}).catch(console.error)\n\n\n\nwhatsapp.createGroup(\"Devs\", [to]).then((response) => {\n console.log(response)\n}).catch(console.error)\n\n\nwhatsapp.updateGroup(\"123456789@us\", \"Devs\", \"Only developers !\").then((response) => {\n console.log(response)\n}).catch(console.error)\n\n\n\n"]}
package/src/WhatsApp.ts DELETED
@@ -1,245 +0,0 @@
1
- import axios, { AxiosRequestConfig, AxiosResponse } from 'axios';
2
- import { Init, HttpMethod, WebhookBody, Routes, TypeMessage, StatusPresence, Contact, Section, InfoInstance, SendMessageRoot, Connect, Location, Buttons, Items } from './types';
3
-
4
- export class WhatsApp {
5
- private readonly server: string;
6
- private readonly key: string;
7
- private route: string;
8
- private method: HttpMethod | null = null;
9
- private body: any = null;
10
-
11
- constructor(data: Init) {
12
- this.server = data.server;
13
- this.key = data.key;
14
- }
15
-
16
- private async request(): Promise<any> {
17
- if (!this.route || !this.method) {
18
- throw new Error('Path and method must be defined before making a request.');
19
- }
20
- const options: AxiosRequestConfig = {
21
- url: `${this.server}/${this.key}/${this.route}`,
22
- method: this.method,
23
- headers: {
24
- 'Content-Type': 'application/json'
25
- }
26
- };
27
- if ((this.method === 'POST' || this.method === 'PUT') && this.body) {
28
- options.data = JSON.stringify(this.body);
29
- }
30
- try {
31
- const response = await axios(options);
32
- return response.data;
33
- } catch (error: any) {
34
- throw new Error(`HTTP Request Error: ${error.message} (status: ${error.response?.status})`);
35
- }
36
- }
37
-
38
-
39
- async connect(): Promise<Connect> {
40
- this.route = Routes.INSTANCES;
41
- this.method = HttpMethod.POST;
42
- return await this.request();
43
- }
44
-
45
- async info(): Promise<InfoInstance> {
46
- this.route = Routes.INSTANCES;
47
- this.method = HttpMethod.GET;
48
- return await this.request();
49
- }
50
-
51
- async logout(): Promise<any> {
52
- this.route = Routes.INSTANCES;
53
- this.method = HttpMethod.DELETE;
54
- return await this.request();
55
- }
56
-
57
-
58
- async setting(markMessageRead: boolean, saveMedia: boolean, receiveStatusMessage: boolean, receivePresence: boolean): Promise<{ status: number, message: string }> {
59
- this.route = Routes.INSTANCES + `/?markMessageRead=${markMessageRead}&saveMedia=${saveMedia}&receiveStatusMessage=${receiveStatusMessage}&receivePresence=${receivePresence}`;
60
- this.method = HttpMethod.PATCH;
61
- return await this.request();
62
- }
63
-
64
-
65
- async updateWebhook(body: WebhookBody): Promise<any> {
66
- this.route = Routes.INSTANCES;
67
- this.method = HttpMethod.PUT;
68
- this.body = body;
69
- return await this.request();
70
- }
71
-
72
-
73
- async sendMessage(
74
- data: {
75
- type: TypeMessage,
76
- body: {
77
- to: string,
78
- msgId?: string,
79
- header?: {
80
- title?: string,
81
- },
82
- status?: StatusPresence,
83
- text?: string,
84
- url?: string,
85
- caption?: string,
86
- mimetype?: string,
87
- fileName?: string,
88
- contact?: Contact,
89
- location?: Location,
90
- name?: string,
91
- options?: string[],
92
- sections?: Section[],
93
- buttons?: Buttons[],
94
- footer?: string,
95
- description?: string,
96
- title?: string,
97
- buttonText?: string,
98
- thumbnailUrl?: string,
99
- sourceUrl?: string,
100
- referenceId?: string,
101
- code?: string,
102
- key?: string,
103
- merchantName?: string,
104
- keyType?: "CNPJ" | "CPF" | "EMAIL" | "PHONE",
105
- subtotal?: string,
106
- totalAmount?: string,
107
- items?: Items[],
108
- }
109
- }, reply: boolean = false): Promise<SendMessageRoot> {
110
-
111
- if (data.type === TypeMessage.BUTTON_PIX) {
112
- const { key, keyType, merchantName, subtotal, totalAmount, items } = data.body;
113
- if (!key || !keyType || !merchantName || !subtotal || !totalAmount || !items || items.length === 0) {
114
- throw new Error("Campos obrigatórios para pagamento via PIX estão ausentes.");
115
- }
116
- }
117
-
118
- if (reply) {
119
- this.route = Routes.MESSAGES + "/" + data.body.msgId + "/" + data.type;
120
- } else {
121
- this.route = Routes.MESSAGES + "/" + data.type;
122
- }
123
-
124
- this.method = HttpMethod.POST;
125
- this.body = data.body;
126
- return await this.request();
127
- }
128
-
129
-
130
- async forwardingMessage(to: string, msgId: string) {
131
- this.route = Routes.MESSAGES + "/" + msgId + "/forwarding";
132
- this.method = HttpMethod.POST;
133
- this.body = {
134
- to,
135
- }
136
- return await this.request();
137
- }
138
-
139
- async rejectCall(id: string, from: string) {
140
- this.route = Routes.CALL + `/${id}/${from}`;
141
- this.method = HttpMethod.DELETE;
142
- return await this.request();
143
- }
144
-
145
- async pairingCode(phoneNumber: string) {
146
- this.route = Routes.INSTANCES + "/pairing-code";
147
- this.body = {
148
- phoneNumber,
149
- }
150
- this.method = HttpMethod.POST;
151
- return await this.request();
152
- }
153
-
154
- async checkRegisteredWhatsapp(number: string) {
155
- this.route = Routes.ACTIONS + "/registered?number=" + number;
156
- this.method = HttpMethod.GET;
157
- return await this.request();
158
- }
159
-
160
-
161
- async contacts() {
162
- this.route = Routes.CONTACTS;
163
- this.method = HttpMethod.GET;
164
- return await this.request();
165
- }
166
-
167
- async contactProfile(id: string) {
168
- this.route = Routes.CONTACTS + "/" + id;
169
- this.method = HttpMethod.GET;
170
- return await this.request();
171
- }
172
-
173
-
174
- async groups() {
175
- this.route = Routes.GROUPS;
176
- this.method = HttpMethod.GET;
177
- return await this.request();
178
- }
179
-
180
-
181
- async infoGroup(id: string) {
182
- this.route = Routes.GROUPS + "/" + id;
183
- this.method = HttpMethod.GET;
184
- return await this.request();
185
- }
186
-
187
- async getInviteGroup(id: string) {
188
- this.route = Routes.GROUPS + "/" + id + "/invite";
189
- this.method = HttpMethod.GET;
190
- return await this.request();
191
- }
192
-
193
-
194
-
195
- async updateGroup(id: string, name: string, description: string) {
196
- this.route = Routes.GROUPS + "/" + id;
197
- this.method = HttpMethod.PUT;
198
- this.body = {
199
- name,
200
- description
201
- }
202
- return await this.request();
203
- }
204
-
205
- async updateGroupPicture(id: string, url: string) {
206
- this.route = Routes.GROUPS + "/" + id + "/picture";
207
- this.method = HttpMethod.PUT;
208
- this.body = {
209
- url
210
- }
211
- return await this.request();
212
- }
213
-
214
- async leaveGroup(id: string) {
215
- this.route = Routes.GROUPS + "/" + id;
216
- this.method = HttpMethod.DELETE;
217
- return await this.request();
218
- }
219
-
220
- async createGroup(name: string, participants: string[]) {
221
- this.route = Routes.GROUPS;
222
- this.method = HttpMethod.POST;
223
- this.body = {
224
- name,
225
- participants
226
- }
227
- return await this.request();
228
- }
229
-
230
-
231
- async addParticipantsGroup(id: string, participants: string[]) {
232
- this.route = Routes.GROUPS + "/" + id + "/participants";
233
- this.method = HttpMethod.POST;
234
- this.body = {
235
- participants
236
- }
237
- return await this.request();
238
- }
239
-
240
- }
241
-
242
-
243
- export default WhatsApp;
244
-
245
-