meta-cloud-api 0.0.8 → 0.0.10
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/dist/api/base.d.mts +1 -1
- package/dist/api/base.d.ts +1 -1
- package/dist/api/businessProfile.d.mts +1 -1
- package/dist/api/businessProfile.d.ts +1 -1
- package/dist/api/businessProfile.js +1 -1
- package/dist/api/encryption.d.mts +1 -1
- package/dist/api/encryption.d.ts +1 -1
- package/dist/api/encryption.js +1 -1
- package/dist/api/encryption.mjs +1 -1
- package/dist/api/flow.d.mts +1 -1
- package/dist/api/flow.d.ts +1 -1
- package/dist/api/flow.js +1 -1
- package/dist/api/flow.mjs +1 -1
- package/dist/api/index.d.mts +1 -1
- package/dist/api/index.d.ts +1 -1
- package/dist/api/index.js +1 -1
- package/dist/api/index.js.map +1 -1
- package/dist/api/index.mjs +1 -1
- package/dist/api/index.mjs.map +1 -1
- package/dist/api/media.d.mts +1 -1
- package/dist/api/media.d.ts +1 -1
- package/dist/api/media.js +1 -1
- package/dist/api/messages.d.mts +179 -3
- package/dist/api/messages.d.ts +179 -3
- package/dist/api/messages.js +1 -1
- package/dist/api/messages.js.map +1 -1
- package/dist/api/messages.mjs +1 -1
- package/dist/api/messages.mjs.map +1 -1
- package/dist/api/phoneNumber.d.mts +1 -1
- package/dist/api/phoneNumber.d.ts +1 -1
- package/dist/api/phoneNumber.js +1 -1
- package/dist/api/phoneNumber.mjs +1 -1
- package/dist/api/qrCode.d.mts +1 -1
- package/dist/api/qrCode.d.ts +1 -1
- package/dist/api/qrCode.js +1 -1
- package/dist/api/qrCode.mjs +1 -1
- package/dist/api/registration.d.mts +1 -1
- package/dist/api/registration.d.ts +1 -1
- package/dist/api/registration.js +1 -1
- package/dist/api/registration.mjs +1 -1
- package/dist/api/template.d.mts +1 -1
- package/dist/api/template.d.ts +1 -1
- package/dist/api/template.js +1 -1
- package/dist/api/template.mjs +1 -1
- package/dist/api/twoStepVerification.d.mts +1 -1
- package/dist/api/twoStepVerification.d.ts +1 -1
- package/dist/api/twoStepVerification.js +1 -1
- package/dist/api/waba.d.mts +1 -1
- package/dist/api/waba.d.ts +1 -1
- package/dist/api/waba.js +1 -1
- package/dist/api/waba.mjs +1 -1
- package/dist/{enums-Dn5Y1Nom.d.mts → enums-DLut7LZL.d.mts} +5 -1
- package/dist/{enums-Dn5Y1Nom.d.ts → enums-DLut7LZL.d.ts} +5 -1
- package/dist/httpsClient.d.mts +1 -1
- package/dist/httpsClient.d.ts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/request.d.mts +1 -1
- package/dist/request.d.ts +1 -1
- package/dist/request.js +1 -1
- package/dist/request.js.map +1 -1
- package/dist/request.mjs +1 -1
- package/dist/request.mjs.map +1 -1
- package/dist/types/base.d.mts +1 -1
- package/dist/types/base.d.ts +1 -1
- package/dist/types/businessProfile.d.mts +1 -1
- package/dist/types/businessProfile.d.ts +1 -1
- package/dist/types/config.d.mts +1 -1
- package/dist/types/config.d.ts +1 -1
- package/dist/types/encryption.d.mts +1 -1
- package/dist/types/encryption.d.ts +1 -1
- package/dist/types/enums.d.mts +1 -1
- package/dist/types/enums.d.ts +1 -1
- package/dist/types/enums.js +1 -1
- package/dist/types/enums.js.map +1 -1
- package/dist/types/enums.mjs +1 -1
- package/dist/types/enums.mjs.map +1 -1
- package/dist/types/flow.d.mts +1 -1
- package/dist/types/flow.d.ts +1 -1
- package/dist/types/httpsClient.d.mts +1 -1
- package/dist/types/httpsClient.d.ts +1 -1
- package/dist/types/index.d.mts +2 -2
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.js +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/index.mjs +1 -1
- package/dist/types/index.mjs.map +1 -1
- package/dist/types/media.d.mts +1 -1
- package/dist/types/media.d.ts +1 -1
- package/dist/types/messages.d.mts +244 -3
- package/dist/types/messages.d.ts +244 -3
- package/dist/types/messages.js +1 -1
- package/dist/types/messages.js.map +1 -1
- package/dist/types/phoneNumber.d.mts +1 -1
- package/dist/types/phoneNumber.d.ts +1 -1
- package/dist/types/qrCode.d.mts +1 -1
- package/dist/types/qrCode.d.ts +1 -1
- package/dist/types/registration.d.mts +1 -1
- package/dist/types/registration.d.ts +1 -1
- package/dist/types/request.d.mts +1 -1
- package/dist/types/request.d.ts +1 -1
- package/dist/types/template.d.mts +1 -1
- package/dist/types/template.d.ts +1 -1
- package/dist/types/twoStepVerification.d.mts +1 -1
- package/dist/types/twoStepVerification.d.ts +1 -1
- package/dist/types/waba.d.mts +1 -1
- package/dist/types/waba.d.ts +1 -1
- package/dist/types/whatsapp.d.mts +1 -1
- package/dist/types/whatsapp.d.ts +1 -1
- package/dist/utils/importConfig.d.mts +1 -1
- package/dist/utils/importConfig.d.ts +1 -1
- package/dist/utils/importConfig.js +1 -1
- package/dist/utils/importConfig.js.map +1 -1
- package/dist/utils/importConfig.mjs +1 -1
- package/dist/utils/importConfig.mjs.map +1 -1
- package/dist/utils/index.d.mts +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +1 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +1 -1
- package/dist/utils/index.mjs.map +1 -1
- package/dist/whatsapp.d.mts +1 -1
- package/dist/whatsapp.d.ts +1 -1
- package/dist/whatsapp.js +1 -1
- package/dist/whatsapp.js.map +1 -1
- package/dist/whatsapp.mjs +1 -1
- package/dist/whatsapp.mjs.map +1 -1
- package/package.json +1 -1
package/dist/api/messages.d.ts
CHANGED
|
@@ -1,27 +1,203 @@
|
|
|
1
1
|
import { WabaConfigType } from '../types/config.js';
|
|
2
|
-
import { M as MessageTypesEnum, b as ComponentTypesEnum } from '../enums-
|
|
2
|
+
import { M as MessageTypesEnum, b as ComponentTypesEnum, I as InteractiveTypesEnum } from '../enums-DLut7LZL.js';
|
|
3
3
|
import { MessagesClass, AudioMediaObject, ContactObject, DocumentMediaObject, ImageMediaObject, InteractiveObject, LocationObject, MessageTemplateObject, StickerMediaObject, TextObject, VideoMediaObject, MessageRequestBody, MessagesResponse, StatusObject } from '../types/messages.js';
|
|
4
4
|
import { RequesterClass, RequesterResponseInterface } from '../types/request.js';
|
|
5
5
|
import BaseAPI from './base.js';
|
|
6
6
|
import '../types/base.js';
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Maps each message type to its appropriate payload type
|
|
10
|
+
*/
|
|
11
|
+
type MessagePayloadType<T extends MessageTypesEnum> = T extends MessageTypesEnum.Audio ? AudioMediaObject : T extends MessageTypesEnum.Contacts ? [ContactObject] : T extends MessageTypesEnum.Document ? DocumentMediaObject : T extends MessageTypesEnum.Image ? ImageMediaObject : T extends MessageTypesEnum.Interactive ? InteractiveObject : T extends MessageTypesEnum.Location ? LocationObject : T extends MessageTypesEnum.Template ? MessageTemplateObject<ComponentTypesEnum> : T extends MessageTypesEnum.Sticker ? StickerMediaObject : T extends MessageTypesEnum.Text ? TextObject : T extends MessageTypesEnum.Video ? VideoMediaObject : T extends MessageTypesEnum.Reaction ? {
|
|
12
|
+
message_id: string;
|
|
13
|
+
emoji: string;
|
|
14
|
+
} : never;
|
|
8
15
|
declare class MessagesApi extends BaseAPI implements MessagesClass {
|
|
9
16
|
private readonly commonMethod;
|
|
10
17
|
private readonly commonEndpoint;
|
|
11
18
|
constructor(config: WabaConfigType, client: RequesterClass);
|
|
12
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Builds the request body for WhatsApp API messages
|
|
21
|
+
* @param type The type of message to send
|
|
22
|
+
* @param payload The message payload object
|
|
23
|
+
* @param toNumber The recipient's phone number
|
|
24
|
+
* @param replyMessageId Optional message ID to reply to
|
|
25
|
+
* @returns The formatted request body
|
|
26
|
+
*/
|
|
27
|
+
bodyBuilder<T extends MessageTypesEnum>(type: T, payload: MessagePayloadType<T>, toNumber: string, replyMessageId?: string): MessageRequestBody<T>;
|
|
28
|
+
/**
|
|
29
|
+
* Sends a request to the WhatsApp API
|
|
30
|
+
* @param body The request body to send
|
|
31
|
+
* @returns Promise with the API response
|
|
32
|
+
*/
|
|
13
33
|
private send;
|
|
34
|
+
/**
|
|
35
|
+
* Sends an audio message via WhatsApp
|
|
36
|
+
* @param body The audio media object
|
|
37
|
+
* @param recipient Recipient's phone number
|
|
38
|
+
* @param replyMessageId Optional message ID to reply to
|
|
39
|
+
* @returns Promise with the message response
|
|
40
|
+
*/
|
|
14
41
|
audio(body: AudioMediaObject, recipient: number, replyMessageId?: string): Promise<RequesterResponseInterface<MessagesResponse>>;
|
|
42
|
+
/**
|
|
43
|
+
* Sends a contact card via WhatsApp
|
|
44
|
+
* @param body The contact object
|
|
45
|
+
* @param recipient Recipient's phone number
|
|
46
|
+
* @param replyMessageId Optional message ID to reply to
|
|
47
|
+
* @returns Promise with the message response
|
|
48
|
+
*/
|
|
15
49
|
contacts(body: [ContactObject], recipient: number, replyMessageId?: string): Promise<RequesterResponseInterface<MessagesResponse>>;
|
|
50
|
+
/**
|
|
51
|
+
* Sends a document via WhatsApp
|
|
52
|
+
* @param body The document media object
|
|
53
|
+
* @param recipient Recipient's phone number
|
|
54
|
+
* @param replyMessageId Optional message ID to reply to
|
|
55
|
+
* @returns Promise with the message response
|
|
56
|
+
*/
|
|
16
57
|
document(body: DocumentMediaObject, recipient: number, replyMessageId?: string): Promise<RequesterResponseInterface<MessagesResponse>>;
|
|
58
|
+
/**
|
|
59
|
+
* Sends an image via WhatsApp
|
|
60
|
+
* @param body The image media object
|
|
61
|
+
* @param recipient Recipient's phone number
|
|
62
|
+
* @param replyMessageId Optional message ID to reply to
|
|
63
|
+
* @returns Promise with the message response
|
|
64
|
+
*/
|
|
17
65
|
image(body: ImageMediaObject, recipient: number, replyMessageId?: string): Promise<RequesterResponseInterface<MessagesResponse>>;
|
|
66
|
+
/**
|
|
67
|
+
* Sends an interactive message via WhatsApp
|
|
68
|
+
* @param body The interactive object (buttons, lists, etc.)
|
|
69
|
+
* @param recipient Recipient's phone number
|
|
70
|
+
* @param replyMessageId Optional message ID to reply to
|
|
71
|
+
* @returns Promise with the message response
|
|
72
|
+
*/
|
|
18
73
|
interactive(body: InteractiveObject, recipient: number, replyMessageId?: string): Promise<RequesterResponseInterface<MessagesResponse>>;
|
|
74
|
+
/**
|
|
75
|
+
* Sends a location via WhatsApp
|
|
76
|
+
* @param body The location object with coordinates
|
|
77
|
+
* @param recipient Recipient's phone number
|
|
78
|
+
* @param replyMessageId Optional message ID to reply to
|
|
79
|
+
* @returns Promise with the message response
|
|
80
|
+
*/
|
|
19
81
|
location(body: LocationObject, recipient: number, replyMessageId?: string): Promise<RequesterResponseInterface<MessagesResponse>>;
|
|
82
|
+
/**
|
|
83
|
+
* Sends a sticker via WhatsApp
|
|
84
|
+
* @param body The sticker media object
|
|
85
|
+
* @param recipient Recipient's phone number
|
|
86
|
+
* @param replyMessageId Optional message ID to reply to
|
|
87
|
+
* @returns Promise with the message response
|
|
88
|
+
*/
|
|
20
89
|
sticker(body: StickerMediaObject, recipient: number, replyMessageId?: string): Promise<RequesterResponseInterface<MessagesResponse>>;
|
|
90
|
+
/**
|
|
91
|
+
* Sends a template message via WhatsApp
|
|
92
|
+
* @param body The message template object
|
|
93
|
+
* @param recipient Recipient's phone number
|
|
94
|
+
* @param replyMessageId Optional message ID to reply to
|
|
95
|
+
* @returns Promise with the message response
|
|
96
|
+
*/
|
|
21
97
|
template(body: MessageTemplateObject<ComponentTypesEnum>, recipient: number, replyMessageId?: string): Promise<RequesterResponseInterface<MessagesResponse>>;
|
|
98
|
+
/**
|
|
99
|
+
* Sends a text message via WhatsApp
|
|
100
|
+
* @param body The text object containing the message
|
|
101
|
+
* @param recipient Recipient's phone number
|
|
102
|
+
* @param replyMessageId Optional message ID to reply to
|
|
103
|
+
* @returns Promise with the message response
|
|
104
|
+
*/
|
|
22
105
|
text(body: TextObject, recipient: number, replyMessageId?: string): Promise<RequesterResponseInterface<MessagesResponse>>;
|
|
106
|
+
/**
|
|
107
|
+
* Sends a video via WhatsApp
|
|
108
|
+
* @param body The video media object
|
|
109
|
+
* @param recipient Recipient's phone number
|
|
110
|
+
* @param replyMessageId Optional message ID to reply to
|
|
111
|
+
* @returns Promise with the message response
|
|
112
|
+
*/
|
|
23
113
|
video(body: VideoMediaObject, recipient: number, replyMessageId?: string): Promise<RequesterResponseInterface<MessagesResponse>>;
|
|
114
|
+
/**
|
|
115
|
+
* Updates message status (used for read receipts and typing indicators)
|
|
116
|
+
* @param body The status object
|
|
117
|
+
* @returns Promise with the response
|
|
118
|
+
*/
|
|
24
119
|
status(body: StatusObject): Promise<RequesterResponseInterface<MessagesResponse>>;
|
|
120
|
+
/**
|
|
121
|
+
* Marks a message as read in WhatsApp
|
|
122
|
+
* @param messageId ID of the message to mark as read
|
|
123
|
+
* @returns Promise with the response
|
|
124
|
+
*/
|
|
125
|
+
markAsRead(messageId: string): Promise<RequesterResponseInterface<MessagesResponse>>;
|
|
126
|
+
/**
|
|
127
|
+
* Marks a message as read and shows a typing indicator in WhatsApp
|
|
128
|
+
* @param messageId ID of the message to mark as read
|
|
129
|
+
* @returns Promise with the response
|
|
130
|
+
*/
|
|
131
|
+
showTypingIndicator(messageId: string): Promise<RequesterResponseInterface<MessagesResponse>>;
|
|
132
|
+
/**
|
|
133
|
+
* Sends an interactive list message
|
|
134
|
+
* @param body The list message content
|
|
135
|
+
* @param recipient Recipient phone number
|
|
136
|
+
* @param replyMessageId Optional message ID to reply to
|
|
137
|
+
* @returns Promise with the response
|
|
138
|
+
*/
|
|
139
|
+
interactiveList(body: InteractiveObject & {
|
|
140
|
+
type: InteractiveTypesEnum.List;
|
|
141
|
+
}, recipient: number, replyMessageId?: string): Promise<RequesterResponseInterface<MessagesResponse>>;
|
|
142
|
+
/**
|
|
143
|
+
* Sends an interactive CTA URL message
|
|
144
|
+
* @param body The CTA URL message content
|
|
145
|
+
* @param recipient Recipient phone number
|
|
146
|
+
* @param replyMessageId Optional message ID to reply to
|
|
147
|
+
* @returns Promise with the response
|
|
148
|
+
*/
|
|
149
|
+
interactiveCtaUrl(body: InteractiveObject & {
|
|
150
|
+
type: InteractiveTypesEnum.CtaUrl;
|
|
151
|
+
}, recipient: number, replyMessageId?: string): Promise<RequesterResponseInterface<MessagesResponse>>;
|
|
152
|
+
/**
|
|
153
|
+
* Sends a location request message
|
|
154
|
+
* @param body The location request message content
|
|
155
|
+
* @param recipient Recipient phone number
|
|
156
|
+
* @param replyMessageId Optional message ID to reply to
|
|
157
|
+
* @returns Promise with the response
|
|
158
|
+
*/
|
|
159
|
+
interactiveLocationRequest(body: InteractiveObject & {
|
|
160
|
+
type: InteractiveTypesEnum.LocationRequest;
|
|
161
|
+
}, recipient: number, replyMessageId?: string): Promise<RequesterResponseInterface<MessagesResponse>>;
|
|
162
|
+
/**
|
|
163
|
+
* Sends an address message to request shipping address from the user
|
|
164
|
+
* Note: This feature is only available for businesses based in India and their India customers
|
|
165
|
+
* @param body The address message content
|
|
166
|
+
* @param recipient Recipient phone number
|
|
167
|
+
* @param replyMessageId Optional message ID to reply to
|
|
168
|
+
* @returns Promise with the response
|
|
169
|
+
*/
|
|
170
|
+
interactiveAddressMessage(body: InteractiveObject & {
|
|
171
|
+
type: InteractiveTypesEnum.AddressMessage;
|
|
172
|
+
}, recipient: number, replyMessageId?: string): Promise<RequesterResponseInterface<MessagesResponse>>;
|
|
173
|
+
/**
|
|
174
|
+
* Sends an interactive reply buttons message
|
|
175
|
+
* @param body The reply buttons message content
|
|
176
|
+
* @param recipient Recipient phone number
|
|
177
|
+
* @param replyMessageId Optional message ID to reply to
|
|
178
|
+
* @returns Promise with the response
|
|
179
|
+
*/
|
|
180
|
+
interactiveReplyButtons(body: InteractiveObject & {
|
|
181
|
+
type: InteractiveTypesEnum.Button;
|
|
182
|
+
}, recipient: number, replyMessageId?: string): Promise<RequesterResponseInterface<MessagesResponse>>;
|
|
183
|
+
/**
|
|
184
|
+
* Sends an interactive Flow message
|
|
185
|
+
* @param body The Flow message content
|
|
186
|
+
* @param recipient Recipient phone number
|
|
187
|
+
* @param replyMessageId Optional message ID to reply to
|
|
188
|
+
* @returns Promise with the response
|
|
189
|
+
*/
|
|
190
|
+
interactiveFlow(body: InteractiveObject & {
|
|
191
|
+
type: InteractiveTypesEnum.Flow;
|
|
192
|
+
}, recipient: number, replyMessageId?: string): Promise<RequesterResponseInterface<MessagesResponse>>;
|
|
193
|
+
/**
|
|
194
|
+
* Sends a reaction to a message (emoji response)
|
|
195
|
+
* @param messageId ID of the message to react to
|
|
196
|
+
* @param emoji The emoji to send as reaction (e.g. "😀", "❤️", "👍")
|
|
197
|
+
* @param recipient Recipient phone number
|
|
198
|
+
* @returns Promise with the response
|
|
199
|
+
*/
|
|
200
|
+
reaction(messageId: string, emoji: string, recipient: number): Promise<RequesterResponseInterface<MessagesResponse>>;
|
|
25
201
|
}
|
|
26
202
|
|
|
27
|
-
export { MessagesApi as default };
|
|
203
|
+
export { type MessagePayloadType, MessagesApi as default };
|
package/dist/api/messages.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var D=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var B=(S,t)=>{for(var i in t)D(S,i,{get:t[i],enumerable:!0})},U=(S,t,i,R)=>{if(t&&typeof t=="object"||typeof t=="function")for(let A of T(t))!M.call(S,A)&&A!==i&&D(S,A,{get:()=>t[A],enumerable:!(R=I(t,A))||R.enumerable});return S};var G=S=>U(D({},"__esModule",{value:!0}),S);var s={};B(s,{default:()=>N});module.exports=G(s);var p=class{name;debug;constructor(t,i=!1){this.name=t,this.debug=i}log(...t){if(this.debug){let i=`[ ${Date.now()} ]`;this.name&&(i+=` - ${this.name}`),console.log.apply(console,[i,": ",...t])}}error(...t){let i=`[ ${Date.now()} ] - ERROR`;this.name&&(i+=` - ${this.name}`),console.error.apply(console,[i,": ",...t])}warn(...t){let i=`[ ${Date.now()} ] - WARN`;this.name&&(i+=` - ${this.name}`),console.warn.apply(console,[i,": ",...t])}info(...t){let i=`[ ${Date.now()} ] - INFO`;this.name&&(i+=` - ${this.name}`),console.info.apply(console,[i,": ",...t])}};var a="BaseAPI",l=!1,e=new p(a,process.env.DEBUG==="true"||l),P=class{config;client;constructor(t,i){this.config=t,this.client=i,e.log("Initialized with HTTPSClient")}};var N=class extends P{commonMethod="POST";commonEndpoint="messages";constructor(t,i){super(t,i)}bodyBuilder(t,i,R,A){let O={messaging_product:"whatsapp",recipient_type:"individual",to:R,type:t,[t]:i};return A&&(O.context={message_id:A}),O}send(t){return this.client.sendRequest(this.commonMethod,`${this.config.WA_PHONE_NUMBER_ID}/${this.commonEndpoint}`,this.config.REQUEST_TIMEOUT,t)}async audio(t,i,R){return this.send(JSON.stringify(this.bodyBuilder("audio",t,i.toString(),R)))}async contacts(t,i,R){return this.send(JSON.stringify(this.bodyBuilder("contacts",t,i.toString(),R)))}async document(t,i,R){return this.send(JSON.stringify(this.bodyBuilder("document",t,i.toString(),R)))}async image(t,i,R){return this.send(JSON.stringify(this.bodyBuilder("image",t,i.toString(),R)))}async interactive(t,i,R){return this.send(JSON.stringify(this.bodyBuilder("interactive",t,i.toString(),R)))}async location(t,i,R){return this.send(JSON.stringify(this.bodyBuilder("location",t,i.toString(),R)))}async sticker(t,i,R){return this.send(JSON.stringify(this.bodyBuilder("sticker",t,i.toString(),R)))}async template(t,i,R){return this.send(JSON.stringify(this.bodyBuilder("template",t,i.toString(),R)))}async text(t,i,R){return this.send(JSON.stringify(this.bodyBuilder("text",t,i.toString(),R)))}async video(t,i,R){return this.send(JSON.stringify(this.bodyBuilder("video",t,i.toString(),R)))}async status(t){let i={messaging_product:"whatsapp",...t};return this.send(JSON.stringify(i))}async markAsRead(t){return this.status({status:"read",message_id:t})}async showTypingIndicator(t){return this.status({status:"read",message_id:t,typing_indicator:{type:"text"}})}async interactiveList(t,i,R){return this.send(JSON.stringify(this.bodyBuilder("interactive",t,i.toString(),R)))}async interactiveCtaUrl(t,i,R){return this.send(JSON.stringify(this.bodyBuilder("interactive",t,i.toString(),R)))}async interactiveLocationRequest(t,i,R){return this.send(JSON.stringify(this.bodyBuilder("interactive",t,i.toString(),R)))}async interactiveAddressMessage(t,i,R){return this.send(JSON.stringify(this.bodyBuilder("interactive",t,i.toString(),R)))}async interactiveReplyButtons(t,i,R){return this.send(JSON.stringify(this.bodyBuilder("interactive",t,i.toString(),R)))}async interactiveFlow(t,i,R){return this.send(JSON.stringify(this.bodyBuilder("interactive",t,i.toString(),R)))}async reaction(t,i,R){let A={messaging_product:"whatsapp",recipient_type:"individual",to:R.toString(),type:"reaction",reaction:{message_id:t,emoji:i}};return this.send(JSON.stringify(A))}};
|
|
2
2
|
//# sourceMappingURL=messages.js.map
|
package/dist/api/messages.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/api/messages.ts","../../src/utils/logger.ts","../../src/api/base.ts"],"sourcesContent":["import type { WabaConfigType } from '../types/config';\nimport { ComponentTypesEnum, HttpMethodsEnum, MessageTypesEnum, WabaConfigEnum } from '../types/enums';\n\nimport * as m from '../types/messages';\nimport type { RequesterClass, RequesterResponseInterface } from '../types/request';\nimport BaseAPI from './base';\n\nexport default class MessagesApi extends BaseAPI implements m.MessagesClass {\n private readonly commonMethod = HttpMethodsEnum.Post;\n private readonly commonEndpoint = 'messages';\n\n constructor(config: WabaConfigType, client: RequesterClass) {\n super(config, client);\n }\n\n bodyBuilder<T extends MessageTypesEnum, C extends ComponentTypesEnum>(\n type: T,\n payload:\n | m.AudioMediaObject\n | [m.ContactObject]\n | m.DocumentMediaObject\n | m.ImageMediaObject\n | m.InteractiveObject\n | m.LocationObject\n | m.MessageTemplateObject<C>\n | m.StickerMediaObject\n | m.TextObject\n | m.VideoMediaObject,\n toNumber: string,\n replyMessageId?: string,\n ) {\n const body: m.MessageRequestBody<T> = {\n messaging_product: 'whatsapp',\n recipient_type: 'individual',\n to: toNumber,\n type: type,\n [type]: payload,\n };\n\n if (replyMessageId) body['context'] = { message_id: replyMessageId };\n\n return body;\n }\n\n private send(body: BodyInit | null): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.client.sendRequest(\n this.commonMethod,\n `${this.config[WabaConfigEnum.PhoneNumberId]}/${this.commonEndpoint}`,\n this.config[WabaConfigEnum.RequestTimeout],\n body,\n );\n }\n\n async audio(\n body: m.AudioMediaObject,\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Audio, body, recipient.toString(), replyMessageId)),\n );\n }\n\n async contacts(\n body: [m.ContactObject],\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Contacts, body, recipient.toString(), replyMessageId)),\n );\n }\n\n async document(\n body: m.DocumentMediaObject,\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Document, body, recipient.toString(), replyMessageId)),\n );\n }\n\n async image(\n body: m.ImageMediaObject,\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Image, body, recipient.toString(), replyMessageId)),\n );\n }\n\n async interactive(\n body: m.InteractiveObject,\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Interactive, body, recipient.toString(), replyMessageId)),\n );\n }\n\n async location(\n body: m.LocationObject,\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Location, body, recipient.toString(), replyMessageId)),\n );\n }\n\n async sticker(\n body: m.StickerMediaObject,\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Sticker, body, recipient.toString(), replyMessageId)),\n );\n }\n\n async template(\n body: m.MessageTemplateObject<ComponentTypesEnum>,\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Template, body, recipient.toString(), replyMessageId)),\n );\n }\n\n async text(\n body: m.TextObject,\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Text, body, recipient.toString(), replyMessageId)),\n );\n }\n\n async video(\n body: m.VideoMediaObject,\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Video, body, recipient.toString(), replyMessageId)),\n );\n }\n\n async status(body: m.StatusObject): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n const mp: m.GeneralMessageBody = { messaging_product: 'whatsapp' };\n const bodyToSend: m.StatusRequestBody = Object.assign(mp, body);\n\n return this.send(JSON.stringify(bodyToSend));\n }\n}\n","// @ts-nocheck\nimport type { LoggerInterface } from '../types/logger';\n\nexport default class Logger implements LoggerInterface {\n private name: string;\n private debug: boolean;\n\n constructor(name: string, debug: boolean = false) {\n this.name = name;\n this.debug = debug;\n }\n\n log(...data: any[]) {\n if (this.debug) {\n let prefix = `[ ${Date.now()} ]`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.log.apply(console, [prefix, ': ', ...data]);\n }\n }\n\n error(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - ERROR`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.error.apply(console, [prefix, ': ', ...data]);\n }\n\n warn(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - WARN`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.warn.apply(console, [prefix, ': ', ...data]);\n }\n\n info(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - INFO`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.info.apply(console, [prefix, ': ', ...data]);\n }\n}\n","import Logger from '../utils/logger';\nimport type { BaseClass } from '../types/base';\nimport type { WabaConfigType } from '../types/config';\nimport type { RequesterClass } from '../types/request';\n\nconst LIB_NAME = 'BaseAPI';\nconst LOG_LOCAL = false;\nconst LOGGER = new Logger(LIB_NAME, process.env.DEBUG === 'true' || LOG_LOCAL);\n\nexport default class BaseAPI implements BaseClass {\n protected config: WabaConfigType;\n protected client: RequesterClass;\n\n constructor(config: WabaConfigType, client: RequesterClass) {\n this.config = config;\n this.client = client;\n LOGGER.log('Initialized with HTTPSClient');\n }\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GCGA,IAAqBI,EAArB,KAAuD,CAC3C,KACA,MAER,YAAYC,EAAcC,EAAiB,GAAO,CAC9C,KAAK,KAAOD,EACZ,KAAK,MAAQC,CACjB,CAEA,OAAOC,EAAa,CAChB,GAAI,KAAK,MAAO,CACZ,IAAIC,EAAS,KAAK,KAAK,IAAI,CAAC,KACxB,KAAK,OACLA,GAAU,MAAM,KAAK,IAAI,IAE7B,QAAQ,IAAI,MAAM,QAAS,CAACA,EAAQ,KAAM,GAAGD,CAAI,CAAC,CACtD,CACJ,CAEA,SAASA,EAAa,CAClB,IAAIC,EAAS,KAAK,KAAK,IAAI,CAAC,aACxB,KAAK,OACLA,GAAU,MAAM,KAAK,IAAI,IAE7B,QAAQ,MAAM,MAAM,QAAS,CAACA,EAAQ,KAAM,GAAGD,CAAI,CAAC,CACxD,CAEA,QAAQA,EAAa,CACjB,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,OAAO,OADd,CAAE,kBAAmB,UAAW,EACPF,CAAI,EAE9D,OAAO,KAAK,KAAK,KAAK,UAAUE,CAAU,CAAC,CAC/C,CACJ","names":["messages_exports","__export","MessagesApi","__toCommonJS","Logger","name","debug","data","prefix","LIB_NAME","LOG_LOCAL","LOGGER","Logger","BaseAPI","config","client","MessagesApi","BaseAPI","config","client","type","payload","toNumber","replyMessageId","body","recipient","bodyToSend"]}
|
|
1
|
+
{"version":3,"sources":["../../src/api/messages.ts","../../src/utils/logger.ts","../../src/api/base.ts"],"sourcesContent":["import type { WabaConfigType } from '../types/config';\nimport {\n ComponentTypesEnum,\n HttpMethodsEnum,\n MessageTypesEnum,\n WabaConfigEnum,\n InteractiveTypesEnum,\n} from '../types/enums';\n\nimport * as m from '../types/messages';\nimport type { RequesterClass, RequesterResponseInterface } from '../types/request';\nimport BaseAPI from './base';\n\n/**\n * Maps each message type to its appropriate payload type\n */\nexport type MessagePayloadType<T extends MessageTypesEnum> = T extends MessageTypesEnum.Audio\n ? m.AudioMediaObject\n : T extends MessageTypesEnum.Contacts\n ? [m.ContactObject]\n : T extends MessageTypesEnum.Document\n ? m.DocumentMediaObject\n : T extends MessageTypesEnum.Image\n ? m.ImageMediaObject\n : T extends MessageTypesEnum.Interactive\n ? m.InteractiveObject\n : T extends MessageTypesEnum.Location\n ? m.LocationObject\n : T extends MessageTypesEnum.Template\n ? m.MessageTemplateObject<ComponentTypesEnum>\n : T extends MessageTypesEnum.Sticker\n ? m.StickerMediaObject\n : T extends MessageTypesEnum.Text\n ? m.TextObject\n : T extends MessageTypesEnum.Video\n ? m.VideoMediaObject\n : T extends MessageTypesEnum.Reaction\n ? { message_id: string; emoji: string }\n : never;\n\nexport default class MessagesApi extends BaseAPI implements m.MessagesClass {\n private readonly commonMethod = HttpMethodsEnum.Post;\n private readonly commonEndpoint = 'messages';\n\n constructor(config: WabaConfigType, client: RequesterClass) {\n super(config, client);\n }\n\n /**\n * Builds the request body for WhatsApp API messages\n * @param type The type of message to send\n * @param payload The message payload object\n * @param toNumber The recipient's phone number\n * @param replyMessageId Optional message ID to reply to\n * @returns The formatted request body\n */\n bodyBuilder<T extends MessageTypesEnum>(\n type: T,\n payload: MessagePayloadType<T>,\n toNumber: string,\n replyMessageId?: string,\n ) {\n const body: m.MessageRequestBody<T> = {\n messaging_product: 'whatsapp',\n recipient_type: 'individual',\n to: toNumber,\n type: type,\n [type]: payload,\n };\n\n if (replyMessageId) body['context'] = { message_id: replyMessageId };\n\n return body;\n }\n\n /**\n * Sends a request to the WhatsApp API\n * @param body The request body to send\n * @returns Promise with the API response\n */\n private send(body: BodyInit | null): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.client.sendRequest(\n this.commonMethod,\n `${this.config[WabaConfigEnum.PhoneNumberId]}/${this.commonEndpoint}`,\n this.config[WabaConfigEnum.RequestTimeout],\n body,\n );\n }\n\n /**\n * Sends an audio message via WhatsApp\n * @param body The audio media object\n * @param recipient Recipient's phone number\n * @param replyMessageId Optional message ID to reply to\n * @returns Promise with the message response\n */\n async audio(\n body: m.AudioMediaObject,\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Audio, body, recipient.toString(), replyMessageId)),\n );\n }\n\n /**\n * Sends a contact card via WhatsApp\n * @param body The contact object\n * @param recipient Recipient's phone number\n * @param replyMessageId Optional message ID to reply to\n * @returns Promise with the message response\n */\n async contacts(\n body: [m.ContactObject],\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Contacts, body, recipient.toString(), replyMessageId)),\n );\n }\n\n /**\n * Sends a document via WhatsApp\n * @param body The document media object\n * @param recipient Recipient's phone number\n * @param replyMessageId Optional message ID to reply to\n * @returns Promise with the message response\n */\n async document(\n body: m.DocumentMediaObject,\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Document, body, recipient.toString(), replyMessageId)),\n );\n }\n\n /**\n * Sends an image via WhatsApp\n * @param body The image media object\n * @param recipient Recipient's phone number\n * @param replyMessageId Optional message ID to reply to\n * @returns Promise with the message response\n */\n async image(\n body: m.ImageMediaObject,\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Image, body, recipient.toString(), replyMessageId)),\n );\n }\n\n /**\n * Sends an interactive message via WhatsApp\n * @param body The interactive object (buttons, lists, etc.)\n * @param recipient Recipient's phone number\n * @param replyMessageId Optional message ID to reply to\n * @returns Promise with the message response\n */\n async interactive(\n body: m.InteractiveObject,\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Interactive, body, recipient.toString(), replyMessageId)),\n );\n }\n\n /**\n * Sends a location via WhatsApp\n * @param body The location object with coordinates\n * @param recipient Recipient's phone number\n * @param replyMessageId Optional message ID to reply to\n * @returns Promise with the message response\n */\n async location(\n body: m.LocationObject,\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Location, body, recipient.toString(), replyMessageId)),\n );\n }\n\n /**\n * Sends a sticker via WhatsApp\n * @param body The sticker media object\n * @param recipient Recipient's phone number\n * @param replyMessageId Optional message ID to reply to\n * @returns Promise with the message response\n */\n async sticker(\n body: m.StickerMediaObject,\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Sticker, body, recipient.toString(), replyMessageId)),\n );\n }\n\n /**\n * Sends a template message via WhatsApp\n * @param body The message template object\n * @param recipient Recipient's phone number\n * @param replyMessageId Optional message ID to reply to\n * @returns Promise with the message response\n */\n async template(\n body: m.MessageTemplateObject<ComponentTypesEnum>,\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Template, body, recipient.toString(), replyMessageId)),\n );\n }\n\n /**\n * Sends a text message via WhatsApp\n * @param body The text object containing the message\n * @param recipient Recipient's phone number\n * @param replyMessageId Optional message ID to reply to\n * @returns Promise with the message response\n */\n async text(\n body: m.TextObject,\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Text, body, recipient.toString(), replyMessageId)),\n );\n }\n\n /**\n * Sends a video via WhatsApp\n * @param body The video media object\n * @param recipient Recipient's phone number\n * @param replyMessageId Optional message ID to reply to\n * @returns Promise with the message response\n */\n async video(\n body: m.VideoMediaObject,\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Video, body, recipient.toString(), replyMessageId)),\n );\n }\n\n /**\n * Updates message status (used for read receipts and typing indicators)\n * @param body The status object\n * @returns Promise with the response\n */\n async status(body: m.StatusObject): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n const bodyToSend = {\n messaging_product: 'whatsapp',\n ...body,\n };\n\n return this.send(JSON.stringify(bodyToSend));\n }\n\n /**\n * Marks a message as read in WhatsApp\n * @param messageId ID of the message to mark as read\n * @returns Promise with the response\n */\n async markAsRead(messageId: string): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.status({\n status: 'read',\n message_id: messageId,\n });\n }\n\n /**\n * Marks a message as read and shows a typing indicator in WhatsApp\n * @param messageId ID of the message to mark as read\n * @returns Promise with the response\n */\n async showTypingIndicator(messageId: string): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.status({\n status: 'read',\n message_id: messageId,\n typing_indicator: {\n type: 'text',\n },\n });\n }\n\n /**\n * Sends an interactive list message\n * @param body The list message content\n * @param recipient Recipient phone number\n * @param replyMessageId Optional message ID to reply to\n * @returns Promise with the response\n */\n async interactiveList(\n body: m.InteractiveObject & { type: InteractiveTypesEnum.List },\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Interactive, body, recipient.toString(), replyMessageId)),\n );\n }\n\n /**\n * Sends an interactive CTA URL message\n * @param body The CTA URL message content\n * @param recipient Recipient phone number\n * @param replyMessageId Optional message ID to reply to\n * @returns Promise with the response\n */\n async interactiveCtaUrl(\n body: m.InteractiveObject & { type: InteractiveTypesEnum.CtaUrl },\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Interactive, body, recipient.toString(), replyMessageId)),\n );\n }\n\n /**\n * Sends a location request message\n * @param body The location request message content\n * @param recipient Recipient phone number\n * @param replyMessageId Optional message ID to reply to\n * @returns Promise with the response\n */\n async interactiveLocationRequest(\n body: m.InteractiveObject & { type: InteractiveTypesEnum.LocationRequest },\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Interactive, body, recipient.toString(), replyMessageId)),\n );\n }\n\n /**\n * Sends an address message to request shipping address from the user\n * Note: This feature is only available for businesses based in India and their India customers\n * @param body The address message content\n * @param recipient Recipient phone number\n * @param replyMessageId Optional message ID to reply to\n * @returns Promise with the response\n */\n async interactiveAddressMessage(\n body: m.InteractiveObject & { type: InteractiveTypesEnum.AddressMessage },\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Interactive, body, recipient.toString(), replyMessageId)),\n );\n }\n\n /**\n * Sends an interactive reply buttons message\n * @param body The reply buttons message content\n * @param recipient Recipient phone number\n * @param replyMessageId Optional message ID to reply to\n * @returns Promise with the response\n */\n async interactiveReplyButtons(\n body: m.InteractiveObject & { type: InteractiveTypesEnum.Button },\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Interactive, body, recipient.toString(), replyMessageId)),\n );\n }\n\n /**\n * Sends an interactive Flow message\n * @param body The Flow message content\n * @param recipient Recipient phone number\n * @param replyMessageId Optional message ID to reply to\n * @returns Promise with the response\n */\n async interactiveFlow(\n body: m.InteractiveObject & { type: InteractiveTypesEnum.Flow },\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Interactive, body, recipient.toString(), replyMessageId)),\n );\n }\n\n /**\n * Sends a reaction to a message (emoji response)\n * @param messageId ID of the message to react to\n * @param emoji The emoji to send as reaction (e.g. \"😀\", \"❤️\", \"👍\")\n * @param recipient Recipient phone number\n * @returns Promise with the response\n */\n async reaction(\n messageId: string,\n emoji: string,\n recipient: number,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n const body = {\n messaging_product: 'whatsapp',\n recipient_type: 'individual',\n to: recipient.toString(),\n type: 'reaction',\n reaction: {\n message_id: messageId,\n emoji: emoji,\n },\n };\n\n return this.send(JSON.stringify(body));\n }\n}\n","// @ts-nocheck\nimport type { LoggerInterface } from '../types/logger';\n\nexport default class Logger implements LoggerInterface {\n private name: string;\n private debug: boolean;\n\n constructor(name: string, debug: boolean = false) {\n this.name = name;\n this.debug = debug;\n }\n\n log(...data: any[]) {\n if (this.debug) {\n let prefix = `[ ${Date.now()} ]`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.log.apply(console, [prefix, ': ', ...data]);\n }\n }\n\n error(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - ERROR`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.error.apply(console, [prefix, ': ', ...data]);\n }\n\n warn(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - WARN`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.warn.apply(console, [prefix, ': ', ...data]);\n }\n\n info(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - INFO`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.info.apply(console, [prefix, ': ', ...data]);\n }\n}\n","import Logger from '../utils/logger';\nimport type { BaseClass } from '../types/base';\nimport type { WabaConfigType } from '../types/config';\nimport type { RequesterClass } from '../types/request';\n\nconst LIB_NAME = 'BaseAPI';\nconst LOG_LOCAL = false;\nconst LOGGER = new Logger(LIB_NAME, process.env.DEBUG === 'true' || LOG_LOCAL);\n\nexport default class BaseAPI implements BaseClass {\n protected config: WabaConfigType;\n protected client: RequesterClass;\n\n constructor(config: WabaConfigType, client: RequesterClass) {\n this.config = config;\n this.client = client;\n LOGGER.log('Initialized with HTTPSClient');\n }\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GCGA,IAAqBI,EAArB,KAAuD,CAC3C,KACA,MAER,YAAYC,EAAcC,EAAiB,GAAO,CAC9C,KAAK,KAAOD,EACZ,KAAK,MAAQC,CACjB,CAEA,OAAOC,EAAa,CAChB,GAAI,KAAK,MAAO,CACZ,IAAIC,EAAS,KAAK,KAAK,IAAI,CAAC,KACxB,KAAK,OACLA,GAAU,MAAM,KAAK,IAAI,IAE7B,QAAQ,IAAI,MAAM,QAAS,CAACA,EAAQ,KAAM,GAAGD,CAAI,CAAC,CACtD,CACJ,CAEA,SAASA,EAAa,CAClB,IAAIC,EAAS,KAAK,KAAK,IAAI,CAAC,aACxB,KAAK,OACL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CAAC,CAC7G,CACJ,CASA,MAAM,SACFI,EACAC,EACAH,EACuD,CACvD,IAAMD,EAAO,CACT,kBAAmB,WACnB,eAAgB,aAChB,GAAIC,EAAU,SAAS,EACvB,KAAM,WACN,SAAU,CACN,WAAYE,EACZ,MAAOC,CACX,CACJ,EAEA,OAAO,KAAK,KAAK,KAAK,UAAUJ,CAAI,CAAC,CACzC,CACJ","names":["messages_exports","__export","MessagesApi","__toCommonJS","Logger","name","debug","data","prefix","LIB_NAME","LOG_LOCAL","LOGGER","Logger","BaseAPI","config","client","MessagesApi","BaseAPI","config","client","type","payload","toNumber","replyMessageId","body","recipient","bodyToSend","messageId","emoji"]}
|
package/dist/api/messages.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var S=class{name;debug;constructor(t,i=!1){this.name=t,this.debug=i}log(...t){if(this.debug){let i=`[ ${Date.now()} ]`;this.name&&(i+=` - ${this.name}`),console.log.apply(console,[i,": ",...t])}}error(...t){let i=`[ ${Date.now()} ] - ERROR`;this.name&&(i+=` - ${this.name}`),console.error.apply(console,[i,": ",...t])}warn(...t){let i=`[ ${Date.now()} ] - WARN`;this.name&&(i+=` - ${this.name}`),console.warn.apply(console,[i,": ",...t])}info(...t){let i=`[ ${Date.now()} ] - INFO`;this.name&&(i+=` - ${this.name}`),console.info.apply(console,[i,": ",...t])}};var
|
|
1
|
+
var S=class{name;debug;constructor(t,i=!1){this.name=t,this.debug=i}log(...t){if(this.debug){let i=`[ ${Date.now()} ]`;this.name&&(i+=` - ${this.name}`),console.log.apply(console,[i,": ",...t])}}error(...t){let i=`[ ${Date.now()} ] - ERROR`;this.name&&(i+=` - ${this.name}`),console.error.apply(console,[i,": ",...t])}warn(...t){let i=`[ ${Date.now()} ] - WARN`;this.name&&(i+=` - ${this.name}`),console.warn.apply(console,[i,": ",...t])}info(...t){let i=`[ ${Date.now()} ] - INFO`;this.name&&(i+=` - ${this.name}`),console.info.apply(console,[i,": ",...t])}};var O="BaseAPI",I=!1,T=new S(O,process.env.DEBUG==="true"||I),A=class{config;client;constructor(t,i){this.config=t,this.client=i,T.log("Initialized with HTTPSClient")}};var P=class extends A{commonMethod="POST";commonEndpoint="messages";constructor(t,i){super(t,i)}bodyBuilder(t,i,R,p){let D={messaging_product:"whatsapp",recipient_type:"individual",to:R,type:t,[t]:i};return p&&(D.context={message_id:p}),D}send(t){return this.client.sendRequest(this.commonMethod,`${this.config.WA_PHONE_NUMBER_ID}/${this.commonEndpoint}`,this.config.REQUEST_TIMEOUT,t)}async audio(t,i,R){return this.send(JSON.stringify(this.bodyBuilder("audio",t,i.toString(),R)))}async contacts(t,i,R){return this.send(JSON.stringify(this.bodyBuilder("contacts",t,i.toString(),R)))}async document(t,i,R){return this.send(JSON.stringify(this.bodyBuilder("document",t,i.toString(),R)))}async image(t,i,R){return this.send(JSON.stringify(this.bodyBuilder("image",t,i.toString(),R)))}async interactive(t,i,R){return this.send(JSON.stringify(this.bodyBuilder("interactive",t,i.toString(),R)))}async location(t,i,R){return this.send(JSON.stringify(this.bodyBuilder("location",t,i.toString(),R)))}async sticker(t,i,R){return this.send(JSON.stringify(this.bodyBuilder("sticker",t,i.toString(),R)))}async template(t,i,R){return this.send(JSON.stringify(this.bodyBuilder("template",t,i.toString(),R)))}async text(t,i,R){return this.send(JSON.stringify(this.bodyBuilder("text",t,i.toString(),R)))}async video(t,i,R){return this.send(JSON.stringify(this.bodyBuilder("video",t,i.toString(),R)))}async status(t){let i={messaging_product:"whatsapp",...t};return this.send(JSON.stringify(i))}async markAsRead(t){return this.status({status:"read",message_id:t})}async showTypingIndicator(t){return this.status({status:"read",message_id:t,typing_indicator:{type:"text"}})}async interactiveList(t,i,R){return this.send(JSON.stringify(this.bodyBuilder("interactive",t,i.toString(),R)))}async interactiveCtaUrl(t,i,R){return this.send(JSON.stringify(this.bodyBuilder("interactive",t,i.toString(),R)))}async interactiveLocationRequest(t,i,R){return this.send(JSON.stringify(this.bodyBuilder("interactive",t,i.toString(),R)))}async interactiveAddressMessage(t,i,R){return this.send(JSON.stringify(this.bodyBuilder("interactive",t,i.toString(),R)))}async interactiveReplyButtons(t,i,R){return this.send(JSON.stringify(this.bodyBuilder("interactive",t,i.toString(),R)))}async interactiveFlow(t,i,R){return this.send(JSON.stringify(this.bodyBuilder("interactive",t,i.toString(),R)))}async reaction(t,i,R){let p={messaging_product:"whatsapp",recipient_type:"individual",to:R.toString(),type:"reaction",reaction:{message_id:t,emoji:i}};return this.send(JSON.stringify(p))}};export{P as default};
|
|
2
2
|
//# sourceMappingURL=messages.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/logger.ts","../../src/api/base.ts","../../src/api/messages.ts"],"sourcesContent":["// @ts-nocheck\nimport type { LoggerInterface } from '../types/logger';\n\nexport default class Logger implements LoggerInterface {\n private name: string;\n private debug: boolean;\n\n constructor(name: string, debug: boolean = false) {\n this.name = name;\n this.debug = debug;\n }\n\n log(...data: any[]) {\n if (this.debug) {\n let prefix = `[ ${Date.now()} ]`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.log.apply(console, [prefix, ': ', ...data]);\n }\n }\n\n error(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - ERROR`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.error.apply(console, [prefix, ': ', ...data]);\n }\n\n warn(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - WARN`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.warn.apply(console, [prefix, ': ', ...data]);\n }\n\n info(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - INFO`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.info.apply(console, [prefix, ': ', ...data]);\n }\n}\n","import Logger from '../utils/logger';\nimport type { BaseClass } from '../types/base';\nimport type { WabaConfigType } from '../types/config';\nimport type { RequesterClass } from '../types/request';\n\nconst LIB_NAME = 'BaseAPI';\nconst LOG_LOCAL = false;\nconst LOGGER = new Logger(LIB_NAME, process.env.DEBUG === 'true' || LOG_LOCAL);\n\nexport default class BaseAPI implements BaseClass {\n protected config: WabaConfigType;\n protected client: RequesterClass;\n\n constructor(config: WabaConfigType, client: RequesterClass) {\n this.config = config;\n this.client = client;\n LOGGER.log('Initialized with HTTPSClient');\n }\n}\n","import type { WabaConfigType } from '../types/config';\nimport { ComponentTypesEnum, HttpMethodsEnum, MessageTypesEnum, WabaConfigEnum } from '../types/enums';\n\nimport * as m from '../types/messages';\nimport type { RequesterClass, RequesterResponseInterface } from '../types/request';\nimport BaseAPI from './base';\n\nexport default class MessagesApi extends BaseAPI implements m.MessagesClass {\n private readonly commonMethod = HttpMethodsEnum.Post;\n private readonly commonEndpoint = 'messages';\n\n constructor(config: WabaConfigType, client: RequesterClass) {\n super(config, client);\n }\n\n bodyBuilder<T extends MessageTypesEnum, C extends ComponentTypesEnum>(\n type: T,\n payload:\n | m.AudioMediaObject\n | [m.ContactObject]\n | m.DocumentMediaObject\n | m.ImageMediaObject\n | m.InteractiveObject\n | m.LocationObject\n | m.MessageTemplateObject<C>\n | m.StickerMediaObject\n | m.TextObject\n | m.VideoMediaObject,\n toNumber: string,\n replyMessageId?: string,\n ) {\n const body: m.MessageRequestBody<T> = {\n messaging_product: 'whatsapp',\n recipient_type: 'individual',\n to: toNumber,\n type: type,\n [type]: payload,\n };\n\n if (replyMessageId) body['context'] = { message_id: replyMessageId };\n\n return body;\n }\n\n private send(body: BodyInit | null): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.client.sendRequest(\n this.commonMethod,\n `${this.config[WabaConfigEnum.PhoneNumberId]}/${this.commonEndpoint}`,\n this.config[WabaConfigEnum.RequestTimeout],\n body,\n );\n }\n\n async audio(\n body: m.AudioMediaObject,\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Audio, body, recipient.toString(), replyMessageId)),\n );\n }\n\n async contacts(\n body: [m.ContactObject],\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Contacts, body, recipient.toString(), replyMessageId)),\n );\n }\n\n async document(\n body: m.DocumentMediaObject,\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Document, body, recipient.toString(), replyMessageId)),\n );\n }\n\n async image(\n body: m.ImageMediaObject,\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Image, body, recipient.toString(), replyMessageId)),\n );\n }\n\n async interactive(\n body: m.InteractiveObject,\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Interactive, body, recipient.toString(), replyMessageId)),\n );\n }\n\n async location(\n body: m.LocationObject,\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Location, body, recipient.toString(), replyMessageId)),\n );\n }\n\n async sticker(\n body: m.StickerMediaObject,\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Sticker, body, recipient.toString(), replyMessageId)),\n );\n }\n\n async template(\n body: m.MessageTemplateObject<ComponentTypesEnum>,\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Template, body, recipient.toString(), replyMessageId)),\n );\n }\n\n async text(\n body: m.TextObject,\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Text, body, recipient.toString(), replyMessageId)),\n );\n }\n\n async video(\n body: m.VideoMediaObject,\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Video, body, recipient.toString(), replyMessageId)),\n );\n }\n\n async status(body: m.StatusObject): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n const mp: m.GeneralMessageBody = { messaging_product: 'whatsapp' };\n const bodyToSend: m.StatusRequestBody = Object.assign(mp, body);\n\n return this.send(JSON.stringify(bodyToSend));\n }\n}\n"],"mappings":"AAGA,IAAqBA,EAArB,KAAuD,CAC3C,KACA,MAER,YAAYC,EAAcC,EAAiB,GAAO,CAC9C,KAAK,KAAOD,EACZ,KAAK,MAAQC,CACjB,CAEA,OAAOC,EAAa,CAChB,GAAI,KAAK,MAAO,CACZ,IAAIC,EAAS,KAAK,KAAK,IAAI,CAAC,KACxB,KAAK,OACLA,GAAU,MAAM,KAAK,IAAI,IAE7B,QAAQ,IAAI,MAAM,QAAS,CAACA,EAAQ,KAAM,GAAGD,CAAI,CAAC,CACtD,CACJ,CAEA,SAASA,EAAa,CAClB,IAAIC,EAAS,KAAK,KAAK,IAAI,CAAC,aACxB,KAAK,OACLA,GAAU,MAAM,KAAK,IAAI,IAE7B,QAAQ,MAAM,MAAM,QAAS,CAACA,EAAQ,KAAM,GAAGD,CAAI,CAAC,CACxD,CAEA,QAAQA,EAAa,CACjB,IAAIC,EAAS,KAAK,KAAK,IAAI,CAAC,YACxB,KAAK,OACLA,GAAU,MAAM,KAAK,IAAI,IAE7B,QAAQ,KAAK,MAAM,QAAS,CAACA,EAAQ,KAAM,GAAGD,CAAI,CAAC,CACvD,CAEA,QAAQA,EAAa,CACjB,IAAIC,EAAS,KAAK,KAAK,IAAI,CAAC,YACxB,KAAK,OACLA,GAAU,MAAM,KAAK,IAAI,IA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D,OAAO,KAAK,KACR,KAAK,UAAU,KAAK,oBAAoCC,EAAMC,EAAU,SAAS,EAAGF,CAAc,CAAC,CACvG,CACJ,CAEA,MAAM,YACFC,EACAC,EACAF,EACuD,CACvD,OAAO,KAAK,KACR,KAAK,UAAU,KAAK,0BAA0CC,EAAMC,EAAU,SAAS,EAAGF,CAAc,CAAC,CAC7G,CACJ,CAEA,MAAM,SACFC,EACAC,EACAF,EACuD,CACvD,OAAO,KAAK,KACR,KAAK,UAAU,KAAK,uBAAuCC,EAAMC,EAAU,SAAS,EAAGF,CAAc,CAAC,CAC1G,CACJ,CAEA,MAAM,QACFC,EACAC,EACAF,EACuD,CACvD,OAAO,KAAK,KACR,KAAK,UAAU,KAAK,sBAAsCC,EAAMC,EAAU,SAAS,EAAGF,CAAc,CAAC,CACzG,CACJ,CAEA,MAAM,SACFC,EACAC,EACAF,EACuD,CACvD,OAAO,KAAK,KACR,KAAK,UAAU,KAAK,uBAAuCC,EAAMC,EAAU,SAAS,EAAGF,CAAc,CAAC,CAC1G,CACJ,CAEA,MAAM,KACFC,EACAC,EACAF,EACuD,CACvD,OAAO,KAAK,KACR,KAAK,UAAU,KAAK,mBAAmCC,EAAMC,EAAU,SAAS,EAAGF,CAAc,CAAC,CACtG,CACJ,CAEA,MAAM,MACFC,EACAC,EACAF,EACuD,CACvD,OAAO,KAAK,KACR,KAAK,UAAU,KAAK,oBAAoCC,EAAMC,EAAU,SAAS,EAAGF,CAAc,CAAC,CACvG,CACJ,CAEA,MAAM,OAAOC,EAA+E,CAExF,IAAME,EAAkC,OAAO,OADd,CAAE,kBAAmB,UAAW,EACPF,CAAI,EAE9D,OAAO,KAAK,KAAK,KAAK,UAAUE,CAAU,CAAC,CAC/C,CACJ","names":["Logger","name","debug","data","prefix","LIB_NAME","LOG_LOCAL","LOGGER","Logger","BaseAPI","config","client","MessagesApi","BaseAPI","config","client","type","payload","toNumber","replyMessageId","body","recipient","bodyToSend"]}
|
|
1
|
+
{"version":3,"sources":["../../src/utils/logger.ts","../../src/api/base.ts","../../src/api/messages.ts"],"sourcesContent":["// @ts-nocheck\nimport type { LoggerInterface } from '../types/logger';\n\nexport default class Logger implements LoggerInterface {\n private name: string;\n private debug: boolean;\n\n constructor(name: string, debug: boolean = false) {\n this.name = name;\n this.debug = debug;\n }\n\n log(...data: any[]) {\n if (this.debug) {\n let prefix = `[ ${Date.now()} ]`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.log.apply(console, [prefix, ': ', ...data]);\n }\n }\n\n error(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - ERROR`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.error.apply(console, [prefix, ': ', ...data]);\n }\n\n warn(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - WARN`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.warn.apply(console, [prefix, ': ', ...data]);\n }\n\n info(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - INFO`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.info.apply(console, [prefix, ': ', ...data]);\n }\n}\n","import Logger from '../utils/logger';\nimport type { BaseClass } from '../types/base';\nimport type { WabaConfigType } from '../types/config';\nimport type { RequesterClass } from '../types/request';\n\nconst LIB_NAME = 'BaseAPI';\nconst LOG_LOCAL = false;\nconst LOGGER = new Logger(LIB_NAME, process.env.DEBUG === 'true' || LOG_LOCAL);\n\nexport default class BaseAPI implements BaseClass {\n protected config: WabaConfigType;\n protected client: RequesterClass;\n\n constructor(config: WabaConfigType, client: RequesterClass) {\n this.config = config;\n this.client = client;\n LOGGER.log('Initialized with HTTPSClient');\n }\n}\n","import type { WabaConfigType } from '../types/config';\nimport {\n ComponentTypesEnum,\n HttpMethodsEnum,\n MessageTypesEnum,\n WabaConfigEnum,\n InteractiveTypesEnum,\n} from '../types/enums';\n\nimport * as m from '../types/messages';\nimport type { RequesterClass, RequesterResponseInterface } from '../types/request';\nimport BaseAPI from './base';\n\n/**\n * Maps each message type to its appropriate payload type\n */\nexport type MessagePayloadType<T extends MessageTypesEnum> = T extends MessageTypesEnum.Audio\n ? m.AudioMediaObject\n : T extends MessageTypesEnum.Contacts\n ? [m.ContactObject]\n : T extends MessageTypesEnum.Document\n ? m.DocumentMediaObject\n : T extends MessageTypesEnum.Image\n ? m.ImageMediaObject\n : T extends MessageTypesEnum.Interactive\n ? m.InteractiveObject\n : T extends MessageTypesEnum.Location\n ? m.LocationObject\n : T extends MessageTypesEnum.Template\n ? m.MessageTemplateObject<ComponentTypesEnum>\n : T extends MessageTypesEnum.Sticker\n ? m.StickerMediaObject\n : T extends MessageTypesEnum.Text\n ? m.TextObject\n : T extends MessageTypesEnum.Video\n ? m.VideoMediaObject\n : T extends MessageTypesEnum.Reaction\n ? { message_id: string; emoji: string }\n : never;\n\nexport default class MessagesApi extends BaseAPI implements m.MessagesClass {\n private readonly commonMethod = HttpMethodsEnum.Post;\n private readonly commonEndpoint = 'messages';\n\n constructor(config: WabaConfigType, client: RequesterClass) {\n super(config, client);\n }\n\n /**\n * Builds the request body for WhatsApp API messages\n * @param type The type of message to send\n * @param payload The message payload object\n * @param toNumber The recipient's phone number\n * @param replyMessageId Optional message ID to reply to\n * @returns The formatted request body\n */\n bodyBuilder<T extends MessageTypesEnum>(\n type: T,\n payload: MessagePayloadType<T>,\n toNumber: string,\n replyMessageId?: string,\n ) {\n const body: m.MessageRequestBody<T> = {\n messaging_product: 'whatsapp',\n recipient_type: 'individual',\n to: toNumber,\n type: type,\n [type]: payload,\n };\n\n if (replyMessageId) body['context'] = { message_id: replyMessageId };\n\n return body;\n }\n\n /**\n * Sends a request to the WhatsApp API\n * @param body The request body to send\n * @returns Promise with the API response\n */\n private send(body: BodyInit | null): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.client.sendRequest(\n this.commonMethod,\n `${this.config[WabaConfigEnum.PhoneNumberId]}/${this.commonEndpoint}`,\n this.config[WabaConfigEnum.RequestTimeout],\n body,\n );\n }\n\n /**\n * Sends an audio message via WhatsApp\n * @param body The audio media object\n * @param recipient Recipient's phone number\n * @param replyMessageId Optional message ID to reply to\n * @returns Promise with the message response\n */\n async audio(\n body: m.AudioMediaObject,\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Audio, body, recipient.toString(), replyMessageId)),\n );\n }\n\n /**\n * Sends a contact card via WhatsApp\n * @param body The contact object\n * @param recipient Recipient's phone number\n * @param replyMessageId Optional message ID to reply to\n * @returns Promise with the message response\n */\n async contacts(\n body: [m.ContactObject],\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Contacts, body, recipient.toString(), replyMessageId)),\n );\n }\n\n /**\n * Sends a document via WhatsApp\n * @param body The document media object\n * @param recipient Recipient's phone number\n * @param replyMessageId Optional message ID to reply to\n * @returns Promise with the message response\n */\n async document(\n body: m.DocumentMediaObject,\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Document, body, recipient.toString(), replyMessageId)),\n );\n }\n\n /**\n * Sends an image via WhatsApp\n * @param body The image media object\n * @param recipient Recipient's phone number\n * @param replyMessageId Optional message ID to reply to\n * @returns Promise with the message response\n */\n async image(\n body: m.ImageMediaObject,\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Image, body, recipient.toString(), replyMessageId)),\n );\n }\n\n /**\n * Sends an interactive message via WhatsApp\n * @param body The interactive object (buttons, lists, etc.)\n * @param recipient Recipient's phone number\n * @param replyMessageId Optional message ID to reply to\n * @returns Promise with the message response\n */\n async interactive(\n body: m.InteractiveObject,\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Interactive, body, recipient.toString(), replyMessageId)),\n );\n }\n\n /**\n * Sends a location via WhatsApp\n * @param body The location object with coordinates\n * @param recipient Recipient's phone number\n * @param replyMessageId Optional message ID to reply to\n * @returns Promise with the message response\n */\n async location(\n body: m.LocationObject,\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Location, body, recipient.toString(), replyMessageId)),\n );\n }\n\n /**\n * Sends a sticker via WhatsApp\n * @param body The sticker media object\n * @param recipient Recipient's phone number\n * @param replyMessageId Optional message ID to reply to\n * @returns Promise with the message response\n */\n async sticker(\n body: m.StickerMediaObject,\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Sticker, body, recipient.toString(), replyMessageId)),\n );\n }\n\n /**\n * Sends a template message via WhatsApp\n * @param body The message template object\n * @param recipient Recipient's phone number\n * @param replyMessageId Optional message ID to reply to\n * @returns Promise with the message response\n */\n async template(\n body: m.MessageTemplateObject<ComponentTypesEnum>,\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Template, body, recipient.toString(), replyMessageId)),\n );\n }\n\n /**\n * Sends a text message via WhatsApp\n * @param body The text object containing the message\n * @param recipient Recipient's phone number\n * @param replyMessageId Optional message ID to reply to\n * @returns Promise with the message response\n */\n async text(\n body: m.TextObject,\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Text, body, recipient.toString(), replyMessageId)),\n );\n }\n\n /**\n * Sends a video via WhatsApp\n * @param body The video media object\n * @param recipient Recipient's phone number\n * @param replyMessageId Optional message ID to reply to\n * @returns Promise with the message response\n */\n async video(\n body: m.VideoMediaObject,\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Video, body, recipient.toString(), replyMessageId)),\n );\n }\n\n /**\n * Updates message status (used for read receipts and typing indicators)\n * @param body The status object\n * @returns Promise with the response\n */\n async status(body: m.StatusObject): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n const bodyToSend = {\n messaging_product: 'whatsapp',\n ...body,\n };\n\n return this.send(JSON.stringify(bodyToSend));\n }\n\n /**\n * Marks a message as read in WhatsApp\n * @param messageId ID of the message to mark as read\n * @returns Promise with the response\n */\n async markAsRead(messageId: string): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.status({\n status: 'read',\n message_id: messageId,\n });\n }\n\n /**\n * Marks a message as read and shows a typing indicator in WhatsApp\n * @param messageId ID of the message to mark as read\n * @returns Promise with the response\n */\n async showTypingIndicator(messageId: string): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.status({\n status: 'read',\n message_id: messageId,\n typing_indicator: {\n type: 'text',\n },\n });\n }\n\n /**\n * Sends an interactive list message\n * @param body The list message content\n * @param recipient Recipient phone number\n * @param replyMessageId Optional message ID to reply to\n * @returns Promise with the response\n */\n async interactiveList(\n body: m.InteractiveObject & { type: InteractiveTypesEnum.List },\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Interactive, body, recipient.toString(), replyMessageId)),\n );\n }\n\n /**\n * Sends an interactive CTA URL message\n * @param body The CTA URL message content\n * @param recipient Recipient phone number\n * @param replyMessageId Optional message ID to reply to\n * @returns Promise with the response\n */\n async interactiveCtaUrl(\n body: m.InteractiveObject & { type: InteractiveTypesEnum.CtaUrl },\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Interactive, body, recipient.toString(), replyMessageId)),\n );\n }\n\n /**\n * Sends a location request message\n * @param body The location request message content\n * @param recipient Recipient phone number\n * @param replyMessageId Optional message ID to reply to\n * @returns Promise with the response\n */\n async interactiveLocationRequest(\n body: m.InteractiveObject & { type: InteractiveTypesEnum.LocationRequest },\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Interactive, body, recipient.toString(), replyMessageId)),\n );\n }\n\n /**\n * Sends an address message to request shipping address from the user\n * Note: This feature is only available for businesses based in India and their India customers\n * @param body The address message content\n * @param recipient Recipient phone number\n * @param replyMessageId Optional message ID to reply to\n * @returns Promise with the response\n */\n async interactiveAddressMessage(\n body: m.InteractiveObject & { type: InteractiveTypesEnum.AddressMessage },\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Interactive, body, recipient.toString(), replyMessageId)),\n );\n }\n\n /**\n * Sends an interactive reply buttons message\n * @param body The reply buttons message content\n * @param recipient Recipient phone number\n * @param replyMessageId Optional message ID to reply to\n * @returns Promise with the response\n */\n async interactiveReplyButtons(\n body: m.InteractiveObject & { type: InteractiveTypesEnum.Button },\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Interactive, body, recipient.toString(), replyMessageId)),\n );\n }\n\n /**\n * Sends an interactive Flow message\n * @param body The Flow message content\n * @param recipient Recipient phone number\n * @param replyMessageId Optional message ID to reply to\n * @returns Promise with the response\n */\n async interactiveFlow(\n body: m.InteractiveObject & { type: InteractiveTypesEnum.Flow },\n recipient: number,\n replyMessageId?: string,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.send(\n JSON.stringify(this.bodyBuilder(MessageTypesEnum.Interactive, body, recipient.toString(), replyMessageId)),\n );\n }\n\n /**\n * Sends a reaction to a message (emoji response)\n * @param messageId ID of the message to react to\n * @param emoji The emoji to send as reaction (e.g. \"😀\", \"❤️\", \"👍\")\n * @param recipient Recipient phone number\n * @returns Promise with the response\n */\n async reaction(\n messageId: string,\n emoji: string,\n recipient: number,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n const body = {\n messaging_product: 'whatsapp',\n recipient_type: 'individual',\n to: recipient.toString(),\n type: 'reaction',\n reaction: {\n message_id: messageId,\n emoji: emoji,\n },\n };\n\n return this.send(JSON.stringify(body));\n }\n}\n"],"mappings":"AAGA,IAAqBA,EAArB,KAAuD,CAC3C,KACA,MAER,YAAYC,EAAcC,EAAiB,GAAO,CAC9C,KAAK,KAAOD,EACZ,KAAK,MAAQC,CACjB,CAEA,OAAOC,EAAa,CAChB,GAAI,KAAK,MAAO,CACZ,IAAIC,EAAS,KAAK,KAAK,IAAI,CAAC,KACxB,KAAK,OACLA,GAAU,MAAM,KAAK,IAAI,IAE7B,QAAQ,IAAI,MAAM,QAAS,CAACA,EAAQ,KAAM,GAAGD,CAAI,CAAC,CACtD,CACJ,CAEA,SAASA,EAAa,CAClB,IAAIC,EAAS,KAAK,KAAK,IAAI,CAAC,aACxB,KAAK,OACLA,GAAU,MAAM,KAAK,IAAI,IAE7B,QAAQ,MAAM,MAAM,QAAS,CAACA,EAAQ,KAAM,GAAGD,CAAI,CAAC,CACxD,CAEA,QAAQA,EAAa,CACjB,IAAIC,EAAS,KAAK,KAAK,IAAI,CAAC,YACxB,KAAK,OACLA,GAAU,MAAM,KAAK,IAAI,IAE7B,QAAQ,KAAK,MAAM,QAAS,CAACA,EAAQ,KAAM,GAAGD,CAAI,CAAC,CACvD,CAEA,QAAQA,EAAa,CACjB,IAAIC,EAAS,KAAK,KAAK,IAAI,CAAC,YACxB,KAAK,O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OACR,WAAYA,EACZ,iBAAkB,CACd,KAAM,MACV,CACJ,CAAC,CACL,CASA,MAAM,gBACFH,EACAC,EACAF,EACuD,CACvD,OAAO,KAAK,KACR,KAAK,UAAU,KAAK,0BAA0CC,EAAMC,EAAU,SAAS,EAAGF,CAAc,CAAC,CAC7G,CACJ,CASA,MAAM,kBACFC,EACAC,EACAF,EACuD,CACvD,OAAO,KAAK,KACR,KAAK,UAAU,KAAK,0BAA0CC,EAAMC,EAAU,SAAS,EAAGF,CAAc,CAAC,CAC7G,CACJ,CASA,MAAM,2BACFC,EACAC,EACAF,EACuD,CACvD,OAAO,KAAK,KACR,KAAK,UAAU,KAAK,0BAA0CC,EAAMC,EAAU,SAAS,EAAGF,CAAc,CAAC,CAC7G,CACJ,CAUA,MAAM,0BACFC,EACAC,EACAF,EACuD,CACvD,OAAO,KAAK,KACR,KAAK,UAAU,KAAK,0BAA0CC,EAAMC,EAAU,SAAS,EAAGF,CAAc,CAAC,CAC7G,CACJ,CASA,MAAM,wBACFC,EACAC,EACAF,EACuD,CACvD,OAAO,KAAK,KACR,KAAK,UAAU,KAAK,0BAA0CC,EAAMC,EAAU,SAAS,EAAGF,CAAc,CAAC,CAC7G,CACJ,CASA,MAAM,gBACFC,EACAC,EACAF,EACuD,CACvD,OAAO,KAAK,KACR,KAAK,UAAU,KAAK,0BAA0CC,EAAMC,EAAU,SAAS,EAAGF,CAAc,CAAC,CAC7G,CACJ,CASA,MAAM,SACFI,EACAC,EACAH,EACuD,CACvD,IAAMD,EAAO,CACT,kBAAmB,WACnB,eAAgB,aAChB,GAAIC,EAAU,SAAS,EACvB,KAAM,WACN,SAAU,CACN,WAAYE,EACZ,MAAOC,CACX,CACJ,EAEA,OAAO,KAAK,KAAK,KAAK,UAAUJ,CAAI,CAAC,CACzC,CACJ","names":["Logger","name","debug","data","prefix","LIB_NAME","LOG_LOCAL","LOGGER","Logger","BaseAPI","config","client","MessagesApi","BaseAPI","config","client","type","payload","toNumber","replyMessageId","body","recipient","bodyToSend","messageId","emoji"]}
|
|
@@ -2,7 +2,7 @@ import { PhoneNumberClass, PhoneNumberResponse, PhoneNumbersResponse, RequestVer
|
|
|
2
2
|
import { WabaConfigType } from '../types/config.mjs';
|
|
3
3
|
import { RequesterClass, RequesterResponseInterface, ResponseSuccess } from '../types/request.mjs';
|
|
4
4
|
import BaseAPI from './base.mjs';
|
|
5
|
-
import '../enums-
|
|
5
|
+
import '../enums-DLut7LZL.mjs';
|
|
6
6
|
import '../types/base.mjs';
|
|
7
7
|
|
|
8
8
|
declare class PhoneNumberApi extends BaseAPI implements PhoneNumberClass {
|
|
@@ -2,7 +2,7 @@ import { PhoneNumberClass, PhoneNumberResponse, PhoneNumbersResponse, RequestVer
|
|
|
2
2
|
import { WabaConfigType } from '../types/config.js';
|
|
3
3
|
import { RequesterClass, RequesterResponseInterface, ResponseSuccess } from '../types/request.js';
|
|
4
4
|
import BaseAPI from './base.js';
|
|
5
|
-
import '../enums-
|
|
5
|
+
import '../enums-DLut7LZL.js';
|
|
6
6
|
import '../types/base.js';
|
|
7
7
|
|
|
8
8
|
declare class PhoneNumberApi extends BaseAPI implements PhoneNumberClass {
|
package/dist/api/phoneNumber.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var U=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var I=Object.prototype.hasOwnProperty;var K=(A,t)=>{for(var R in t)U(A,R,{get:t[R],enumerable:!0})},T=(A,t,R,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let S of O(t))!I.call(A,S)&&S!==R&&U(A,S,{get:()=>t[S],enumerable:!(i=B(t,S))||i.enumerable});return A};var p=A=>T(U({},"__esModule",{value:!0}),A);var f={};K(f,{default:()=>N});module.exports=p(f);var G=A=>{if(!A||Object.keys(A).length===0)return"";let t=new URLSearchParams;for(let[i,S]of Object.entries(A))S!==void 0&&t.append(i,String(S));let R=t.toString();return R?`?${R}`:""};var P=class{name;debug;constructor(t,R=!1){this.name=t,this.debug=R}log(...t){if(this.debug){let R=`[ ${Date.now()} ]`;this.name&&(R+=` - ${this.name}`),console.log.apply(console,[R,": ",...t])}}error(...t){let R=`[ ${Date.now()} ] - ERROR`;this.name&&(R+=` - ${this.name}`),console.error.apply(console,[R,": ",...t])}warn(...t){let R=`[ ${Date.now()} ] - WARN`;this.name&&(R+=` - ${this.name}`),console.warn.apply(console,[R,": ",...t])}info(...t){let R=`[ ${Date.now()} ] - INFO`;this.name&&(R+=` - ${this.name}`),console.info.apply(console,[R,": ",...t])}};var l="BaseAPI",M=!1,_=new P(l,process.env.DEBUG==="true"||M),D=class{config;client;constructor(t,R){this.config=t,this.client=R,_.log("Initialized with HTTPSClient")}};var N=class extends D{endpoint="phone_numbers";constructor(t,R){super(t,R)}async getPhoneNumberById(t){let R=t?G({fields:t}):"";return this.client.sendRequest("GET",`${this.config.WA_PHONE_NUMBER_ID}${R}`,this.config.REQUEST_TIMEOUT,null)}async getPhoneNumbers(){return this.client.sendRequest("GET",`${this.config.WA_BUSINESS_ACCOUNT_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,null)}async requestVerificationCode(t){return this.client.sendRequest("POST",`${this.config.WA_PHONE_NUMBER_ID}/request_code`,this.config.REQUEST_TIMEOUT,JSON.stringify(t))}async verifyCode(t){return this.client.sendRequest("POST",`${this.config.WA_PHONE_NUMBER_ID}/verify_code`,this.config.REQUEST_TIMEOUT,JSON.stringify(t))}};
|
|
2
2
|
//# sourceMappingURL=phoneNumber.js.map
|
package/dist/api/phoneNumber.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var N=A=>{if(!A||Object.keys(A).length===0)return"";let t=new URLSearchParams;for(let[
|
|
1
|
+
var N=A=>{if(!A||Object.keys(A).length===0)return"";let t=new URLSearchParams;for(let[U,i]of Object.entries(A))i!==void 0&&t.append(U,String(i));let R=t.toString();return R?`?${R}`:""};var S=class{name;debug;constructor(t,R=!1){this.name=t,this.debug=R}log(...t){if(this.debug){let R=`[ ${Date.now()} ]`;this.name&&(R+=` - ${this.name}`),console.log.apply(console,[R,": ",...t])}}error(...t){let R=`[ ${Date.now()} ] - ERROR`;this.name&&(R+=` - ${this.name}`),console.error.apply(console,[R,": ",...t])}warn(...t){let R=`[ ${Date.now()} ] - WARN`;this.name&&(R+=` - ${this.name}`),console.warn.apply(console,[R,": ",...t])}info(...t){let R=`[ ${Date.now()} ] - INFO`;this.name&&(R+=` - ${this.name}`),console.info.apply(console,[R,": ",...t])}};var G="BaseAPI",B=!1,O=new S(G,process.env.DEBUG==="true"||B),P=class{config;client;constructor(t,R){this.config=t,this.client=R,O.log("Initialized with HTTPSClient")}};var D=class extends P{endpoint="phone_numbers";constructor(t,R){super(t,R)}async getPhoneNumberById(t){let R=t?N({fields:t}):"";return this.client.sendRequest("GET",`${this.config.WA_PHONE_NUMBER_ID}${R}`,this.config.REQUEST_TIMEOUT,null)}async getPhoneNumbers(){return this.client.sendRequest("GET",`${this.config.WA_BUSINESS_ACCOUNT_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,null)}async requestVerificationCode(t){return this.client.sendRequest("POST",`${this.config.WA_PHONE_NUMBER_ID}/request_code`,this.config.REQUEST_TIMEOUT,JSON.stringify(t))}async verifyCode(t){return this.client.sendRequest("POST",`${this.config.WA_PHONE_NUMBER_ID}/verify_code`,this.config.REQUEST_TIMEOUT,JSON.stringify(t))}};export{D as default};
|
|
2
2
|
//# sourceMappingURL=phoneNumber.mjs.map
|
package/dist/api/qrCode.d.mts
CHANGED
|
@@ -2,7 +2,7 @@ import { WabaConfigType } from '../types/config.mjs';
|
|
|
2
2
|
import { RequesterClass, RequesterResponseInterface, ResponseSuccess } from '../types/request.mjs';
|
|
3
3
|
import BaseAPI from './base.mjs';
|
|
4
4
|
import { QrCodeClass, CreateQrCodeRequest, QrCodeResponse, QrCodesResponse, UpdateQrCodeRequest } from '../types/qrCode.mjs';
|
|
5
|
-
import '../enums-
|
|
5
|
+
import '../enums-DLut7LZL.mjs';
|
|
6
6
|
import '../types/base.mjs';
|
|
7
7
|
|
|
8
8
|
declare class QrCodeAPI extends BaseAPI implements QrCodeClass {
|
package/dist/api/qrCode.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { WabaConfigType } from '../types/config.js';
|
|
|
2
2
|
import { RequesterClass, RequesterResponseInterface, ResponseSuccess } from '../types/request.js';
|
|
3
3
|
import BaseAPI from './base.js';
|
|
4
4
|
import { QrCodeClass, CreateQrCodeRequest, QrCodeResponse, QrCodesResponse, UpdateQrCodeRequest } from '../types/qrCode.js';
|
|
5
|
-
import '../enums-
|
|
5
|
+
import '../enums-DLut7LZL.js';
|
|
6
6
|
import '../types/base.js';
|
|
7
7
|
|
|
8
8
|
declare class QrCodeAPI extends BaseAPI implements QrCodeClass {
|
package/dist/api/qrCode.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var i=Object.defineProperty;var G=Object.getOwnPropertyDescriptor;var B=Object.getOwnPropertyNames;var O=Object.prototype.hasOwnProperty;var I=(A,t)=>{for(var R in t)i(A,R,{get:t[R],enumerable:!0})},K=(A,t,R,U)=>{if(t&&typeof t=="object"||typeof t=="function")for(let S of B(t))!O.call(A,S)&&S!==R&&i(A,S,{get:()=>t[S],enumerable:!(U=G(t,S))||U.enumerable});return A};var T=A=>K(i({},"__esModule",{value:!0}),A);var _={};I(_,{default:()=>N});module.exports=T(_);var P=class{name;debug;constructor(t,R=!1){this.name=t,this.debug=R}log(...t){if(this.debug){let R=`[ ${Date.now()} ]`;this.name&&(R+=` - ${this.name}`),console.log.apply(console,[R,": ",...t])}}error(...t){let R=`[ ${Date.now()} ] - ERROR`;this.name&&(R+=` - ${this.name}`),console.error.apply(console,[R,": ",...t])}warn(...t){let R=`[ ${Date.now()} ] - WARN`;this.name&&(R+=` - ${this.name}`),console.warn.apply(console,[R,": ",...t])}info(...t){let R=`[ ${Date.now()} ] - INFO`;this.name&&(R+=` - ${this.name}`),console.info.apply(console,[R,": ",...t])}};var p="BaseAPI",l=!1,M=new P(p,process.env.DEBUG==="true"||l),D=class{config;client;constructor(t,R){this.config=t,this.client=R,M.log("Initialized with HTTPSClient")}};var N=class extends D{endpoint="message_qrdls";constructor(t,R){super(t,R)}async createQrCode(t){return this.client.sendRequest("POST",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,JSON.stringify(t))}async getQrCodes(){return this.client.sendRequest("GET",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,null)}async getQrCode(t){return this.client.sendRequest("GET",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}/${t}`,this.config.REQUEST_TIMEOUT,null)}async updateQrCode(t){return this.client.sendRequest("POST",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,JSON.stringify(t))}async deleteQrCode(t){return this.client.sendRequest("DELETE",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}/${t}`,this.config.REQUEST_TIMEOUT,null)}};
|
|
2
2
|
//# sourceMappingURL=qrCode.js.map
|
package/dist/api/qrCode.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var A=class{name;debug;constructor(t,R=!1){this.name=t,this.debug=R}log(...t){if(this.debug){let R=`[ ${Date.now()} ]`;this.name&&(R+=` - ${this.name}`),console.log.apply(console,[R,": ",...t])}}error(...t){let R=`[ ${Date.now()} ] - ERROR`;this.name&&(R+=` - ${this.name}`),console.error.apply(console,[R,": ",...t])}warn(...t){let R=`[ ${Date.now()} ] - WARN`;this.name&&(R+=` - ${this.name}`),console.warn.apply(console,[R,": ",...t])}info(...t){let R=`[ ${Date.now()} ] - INFO`;this.name&&(R+=` - ${this.name}`),console.info.apply(console,[R,": ",...t])}};var
|
|
1
|
+
var A=class{name;debug;constructor(t,R=!1){this.name=t,this.debug=R}log(...t){if(this.debug){let R=`[ ${Date.now()} ]`;this.name&&(R+=` - ${this.name}`),console.log.apply(console,[R,": ",...t])}}error(...t){let R=`[ ${Date.now()} ] - ERROR`;this.name&&(R+=` - ${this.name}`),console.error.apply(console,[R,": ",...t])}warn(...t){let R=`[ ${Date.now()} ] - WARN`;this.name&&(R+=` - ${this.name}`),console.warn.apply(console,[R,": ",...t])}info(...t){let R=`[ ${Date.now()} ] - INFO`;this.name&&(R+=` - ${this.name}`),console.info.apply(console,[R,": ",...t])}};var N="BaseAPI",i=!1,U=new A(N,process.env.DEBUG==="true"||i),S=class{config;client;constructor(t,R){this.config=t,this.client=R,U.log("Initialized with HTTPSClient")}};var P=class extends S{endpoint="message_qrdls";constructor(t,R){super(t,R)}async createQrCode(t){return this.client.sendRequest("POST",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,JSON.stringify(t))}async getQrCodes(){return this.client.sendRequest("GET",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,null)}async getQrCode(t){return this.client.sendRequest("GET",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}/${t}`,this.config.REQUEST_TIMEOUT,null)}async updateQrCode(t){return this.client.sendRequest("POST",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,JSON.stringify(t))}async deleteQrCode(t){return this.client.sendRequest("DELETE",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}/${t}`,this.config.REQUEST_TIMEOUT,null)}};export{P as default};
|
|
2
2
|
//# sourceMappingURL=qrCode.mjs.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RegistrationClass } from '../types/registration.mjs';
|
|
2
2
|
import { WabaConfigType } from '../types/config.mjs';
|
|
3
|
-
import { j as DataLocalizationRegionEnum } from '../enums-
|
|
3
|
+
import { j as DataLocalizationRegionEnum } from '../enums-DLut7LZL.mjs';
|
|
4
4
|
import { RequesterClass, RequesterResponseInterface, ResponseSuccess } from '../types/request.mjs';
|
|
5
5
|
import BaseAPI from './base.mjs';
|
|
6
6
|
import '../types/base.mjs';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RegistrationClass } from '../types/registration.js';
|
|
2
2
|
import { WabaConfigType } from '../types/config.js';
|
|
3
|
-
import { j as DataLocalizationRegionEnum } from '../enums-
|
|
3
|
+
import { j as DataLocalizationRegionEnum } from '../enums-DLut7LZL.js';
|
|
4
4
|
import { RequesterClass, RequesterResponseInterface, ResponseSuccess } from '../types/request.js';
|
|
5
5
|
import BaseAPI from './base.js';
|
|
6
6
|
import '../types/base.js';
|
package/dist/api/registration.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var G=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var B=Object.getOwnPropertyNames;var O=Object.prototype.hasOwnProperty;var I=(A,R)=>{for(var t in R)G(A,t,{get:R[t],enumerable:!0})},K=(A,R,t,N)=>{if(R&&typeof R=="object"||typeof R=="function")for(let S of B(R))!O.call(A,S)&&S!==t&&G(A,S,{get:()=>R[S],enumerable:!(N=i(R,S))||N.enumerable});return A};var T=A=>K(G({},"__esModule",{value:!0}),A);var p={};I(p,{default:()=>U});module.exports=T(p);var D=class{name;debug;constructor(R,t=!1){this.name=R,this.debug=t}log(...R){if(this.debug){let t=`[ ${Date.now()} ]`;this.name&&(t+=` - ${this.name}`),console.log.apply(console,[t,": ",...R])}}error(...R){let t=`[ ${Date.now()} ] - ERROR`;this.name&&(t+=` - ${this.name}`),console.error.apply(console,[t,": ",...R])}warn(...R){let t=`[ ${Date.now()} ] - WARN`;this.name&&(t+=` - ${this.name}`),console.warn.apply(console,[t,": ",...R])}info(...R){let t=`[ ${Date.now()} ] - INFO`;this.name&&(t+=` - ${this.name}`),console.info.apply(console,[t,": ",...R])}};var M="BaseAPI",l=!1,_=new D(M,process.env.DEBUG==="true"||l),P=class{config;client;constructor(R,t){this.config=R,this.client=t,_.log("Initialized with HTTPSClient")}};var U=class extends P{constructor(R,t){super(R,t)}async register(R,t){let N={messaging_product:"whatsapp",pin:R,...t&&{data_localization_region:t}};return this.client.sendRequest("POST",`${this.config.WA_PHONE_NUMBER_ID}/register`,this.config.REQUEST_TIMEOUT,JSON.stringify(N))}async deregister(){return this.client.sendRequest("POST",`${this.config.WA_PHONE_NUMBER_ID}/deregister`,this.config.REQUEST_TIMEOUT,null)}};
|
|
2
2
|
//# sourceMappingURL=registration.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var A=class{name;debug;constructor(t,R=!1){this.name=t,this.debug=R}log(...t){if(this.debug){let R=`[ ${Date.now()} ]`;this.name&&(R+=` - ${this.name}`),console.log.apply(console,[R,": ",...t])}}error(...t){let R=`[ ${Date.now()} ] - ERROR`;this.name&&(R+=` - ${this.name}`),console.error.apply(console,[R,": ",...t])}warn(...t){let R=`[ ${Date.now()} ] - WARN`;this.name&&(R+=` - ${this.name}`),console.warn.apply(console,[R,": ",...t])}info(...t){let R=`[ ${Date.now()} ] - INFO`;this.name&&(R+=` - ${this.name}`),console.info.apply(console,[R,": ",...t])}};var
|
|
1
|
+
var A=class{name;debug;constructor(t,R=!1){this.name=t,this.debug=R}log(...t){if(this.debug){let R=`[ ${Date.now()} ]`;this.name&&(R+=` - ${this.name}`),console.log.apply(console,[R,": ",...t])}}error(...t){let R=`[ ${Date.now()} ] - ERROR`;this.name&&(R+=` - ${this.name}`),console.error.apply(console,[R,": ",...t])}warn(...t){let R=`[ ${Date.now()} ] - WARN`;this.name&&(R+=` - ${this.name}`),console.warn.apply(console,[R,": ",...t])}info(...t){let R=`[ ${Date.now()} ] - INFO`;this.name&&(R+=` - ${this.name}`),console.info.apply(console,[R,": ",...t])}};var U="BaseAPI",G=!1,i=new A(U,process.env.DEBUG==="true"||G),S=class{config;client;constructor(t,R){this.config=t,this.client=R,i.log("Initialized with HTTPSClient")}};var D=class extends S{constructor(t,R){super(t,R)}async register(t,R){let N={messaging_product:"whatsapp",pin:t,...R&&{data_localization_region:R}};return this.client.sendRequest("POST",`${this.config.WA_PHONE_NUMBER_ID}/register`,this.config.REQUEST_TIMEOUT,JSON.stringify(N))}async deregister(){return this.client.sendRequest("POST",`${this.config.WA_PHONE_NUMBER_ID}/deregister`,this.config.REQUEST_TIMEOUT,null)}};export{D as default};
|
|
2
2
|
//# sourceMappingURL=registration.mjs.map
|
package/dist/api/template.d.mts
CHANGED
|
@@ -2,7 +2,7 @@ import { WabaConfigType } from '../types/config.mjs';
|
|
|
2
2
|
import { RequesterClass, RequesterResponseInterface, ResponseSuccess, ResponsePagination } from '../types/request.mjs';
|
|
3
3
|
import { TemplateClass, TemplateResponse, TemplateRequestBody, TemplateGetParams, TemplateDeleteParams } from '../types/template.mjs';
|
|
4
4
|
import BaseAPI from './base.mjs';
|
|
5
|
-
import '../enums-
|
|
5
|
+
import '../enums-DLut7LZL.mjs';
|
|
6
6
|
import '../types/base.mjs';
|
|
7
7
|
|
|
8
8
|
declare class TemplateApi extends BaseAPI implements TemplateClass {
|
package/dist/api/template.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { WabaConfigType } from '../types/config.js';
|
|
|
2
2
|
import { RequesterClass, RequesterResponseInterface, ResponseSuccess, ResponsePagination } from '../types/request.js';
|
|
3
3
|
import { TemplateClass, TemplateResponse, TemplateRequestBody, TemplateGetParams, TemplateDeleteParams } from '../types/template.js';
|
|
4
4
|
import BaseAPI from './base.js';
|
|
5
|
-
import '../enums-
|
|
5
|
+
import '../enums-DLut7LZL.js';
|
|
6
6
|
import '../types/base.js';
|
|
7
7
|
|
|
8
8
|
declare class TemplateApi extends BaseAPI implements TemplateClass {
|
package/dist/api/template.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var G=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var
|
|
1
|
+
"use strict";var G=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var O=Object.prototype.hasOwnProperty;var T=(A,t)=>{for(var R in t)G(A,R,{get:t[R],enumerable:!0})},p=(A,t,R,D)=>{if(t&&typeof t=="object"||typeof t=="function")for(let S of l(t))!O.call(A,S)&&S!==R&&G(A,S,{get:()=>t[S],enumerable:!(D=B(t,S))||D.enumerable});return A};var I=A=>p(G({},"__esModule",{value:!0}),A);var H={};T(H,{default:()=>N});module.exports=I(H);var U=A=>{if(!A||Object.keys(A).length===0)return"";let t=new URLSearchParams;for(let[D,S]of Object.entries(A))S!==void 0&&t.append(D,String(S));let R=t.toString();return R?`?${R}`:""};var P=class{name;debug;constructor(t,R=!1){this.name=t,this.debug=R}log(...t){if(this.debug){let R=`[ ${Date.now()} ]`;this.name&&(R+=` - ${this.name}`),console.log.apply(console,[R,": ",...t])}}error(...t){let R=`[ ${Date.now()} ] - ERROR`;this.name&&(R+=` - ${this.name}`),console.error.apply(console,[R,": ",...t])}warn(...t){let R=`[ ${Date.now()} ] - WARN`;this.name&&(R+=` - ${this.name}`),console.warn.apply(console,[R,": ",...t])}info(...t){let R=`[ ${Date.now()} ] - INFO`;this.name&&(R+=` - ${this.name}`),console.info.apply(console,[R,": ",...t])}};var K="BaseAPI",M=!1,_=new P(K,process.env.DEBUG==="true"||M),i=class{config;client;constructor(t,R){this.config=t,this.client=R,_.log("Initialized with HTTPSClient")}};var N=class extends i{endpoint="message_templates";constructor(t,R){super(t,R)}async getTemplate(t){return this.client.sendRequest("GET",`${t}`,this.config.REQUEST_TIMEOUT,null)}async updateTemplate(t,R){return this.client.sendRequest("POST",`${t}`,this.config.REQUEST_TIMEOUT,JSON.stringify(R))}async getTemplates(t){return this.client.sendRequest("GET",`${this.config.WA_BUSINESS_ACCOUNT_ID}/${this.endpoint}${U(t)}`,this.config.REQUEST_TIMEOUT,null)}async createTemplate(t){return this.client.sendRequest("POST",`${this.config.WA_BUSINESS_ACCOUNT_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,JSON.stringify(t))}async deleteTemplate(t){return this.client.sendRequest("DELETE",`${this.config.WA_BUSINESS_ACCOUNT_ID}/${this.endpoint}${U(t)}`,this.config.REQUEST_TIMEOUT,null)}};
|
|
2
2
|
//# sourceMappingURL=template.js.map
|
package/dist/api/template.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var i=A=>{if(!A||Object.keys(A).length===0)return"";let t=new URLSearchParams;for(let[G,N]of Object.entries(A))N!==void 0&&t.append(G,String(N));let R=t.toString();return R?`?${R}`:""};var S=class{name;debug;constructor(t,R=!1){this.name=t,this.debug=R}log(...t){if(this.debug){let R=`[ ${Date.now()} ]`;this.name&&(R+=` - ${this.name}`),console.log.apply(console,[R,": ",...t])}}error(...t){let R=`[ ${Date.now()} ] - ERROR`;this.name&&(R+=` - ${this.name}`),console.error.apply(console,[R,": ",...t])}warn(...t){let R=`[ ${Date.now()} ] - WARN`;this.name&&(R+=` - ${this.name}`),console.warn.apply(console,[R,": ",...t])}info(...t){let R=`[ ${Date.now()} ] - INFO`;this.name&&(R+=` - ${this.name}`),console.info.apply(console,[R,": ",...t])}};var U="BaseAPI",B=!1,
|
|
1
|
+
var i=A=>{if(!A||Object.keys(A).length===0)return"";let t=new URLSearchParams;for(let[G,N]of Object.entries(A))N!==void 0&&t.append(G,String(N));let R=t.toString();return R?`?${R}`:""};var S=class{name;debug;constructor(t,R=!1){this.name=t,this.debug=R}log(...t){if(this.debug){let R=`[ ${Date.now()} ]`;this.name&&(R+=` - ${this.name}`),console.log.apply(console,[R,": ",...t])}}error(...t){let R=`[ ${Date.now()} ] - ERROR`;this.name&&(R+=` - ${this.name}`),console.error.apply(console,[R,": ",...t])}warn(...t){let R=`[ ${Date.now()} ] - WARN`;this.name&&(R+=` - ${this.name}`),console.warn.apply(console,[R,": ",...t])}info(...t){let R=`[ ${Date.now()} ] - INFO`;this.name&&(R+=` - ${this.name}`),console.info.apply(console,[R,": ",...t])}};var U="BaseAPI",B=!1,l=new S(U,process.env.DEBUG==="true"||B),P=class{config;client;constructor(t,R){this.config=t,this.client=R,l.log("Initialized with HTTPSClient")}};var D=class extends P{endpoint="message_templates";constructor(t,R){super(t,R)}async getTemplate(t){return this.client.sendRequest("GET",`${t}`,this.config.REQUEST_TIMEOUT,null)}async updateTemplate(t,R){return this.client.sendRequest("POST",`${t}`,this.config.REQUEST_TIMEOUT,JSON.stringify(R))}async getTemplates(t){return this.client.sendRequest("GET",`${this.config.WA_BUSINESS_ACCOUNT_ID}/${this.endpoint}${i(t)}`,this.config.REQUEST_TIMEOUT,null)}async createTemplate(t){return this.client.sendRequest("POST",`${this.config.WA_BUSINESS_ACCOUNT_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,JSON.stringify(t))}async deleteTemplate(t){return this.client.sendRequest("DELETE",`${this.config.WA_BUSINESS_ACCOUNT_ID}/${this.endpoint}${i(t)}`,this.config.REQUEST_TIMEOUT,null)}};export{D as default};
|
|
2
2
|
//# sourceMappingURL=template.mjs.map
|