meta-cloud-api 0.0.17 → 0.0.19
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/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/messages.d.mts +74 -84
- package/dist/api/messages.d.ts +74 -84
- 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/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/types/index.d.mts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/messages.d.mts +77 -87
- package/dist/types/messages.d.ts +77 -87
- package/dist/types/messages.js +1 -1
- package/dist/types/messages.js.map +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,6 +1,6 @@
|
|
|
1
1
|
import { WabaConfigType } from '../types/config.js';
|
|
2
2
|
import { M as MessageTypesEnum, b as ComponentTypesEnum, I as InteractiveTypesEnum } from '../enums-DLut7LZL.js';
|
|
3
|
-
import { MessagesClass, AudioMediaObject, ContactObject, DocumentMediaObject, ImageMediaObject, InteractiveObject, LocationObject, MessageTemplateObject, StickerMediaObject, TextObject, VideoMediaObject, MessageRequestBody, MessagesResponse,
|
|
3
|
+
import { MessagesClass, AudioMediaObject, ContactObject, DocumentMediaObject, ImageMediaObject, InteractiveObject, LocationObject, MessageTemplateObject, StickerMediaObject, TextObject, VideoMediaObject, MessageRequestBody, MessageRequestParams as MessageRequestParams$1, MessagesResponse, TextMessageParams as TextMessageParams$1, StatusParams as StatusParams$1, ReactionParams as ReactionParams$1 } 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';
|
|
@@ -12,6 +12,26 @@ type MessagePayloadType<T extends MessageTypesEnum> = T extends MessageTypesEnum
|
|
|
12
12
|
message_id: string;
|
|
13
13
|
emoji: string;
|
|
14
14
|
} : never;
|
|
15
|
+
interface MessageRequestParams<T> {
|
|
16
|
+
body: T;
|
|
17
|
+
to: string;
|
|
18
|
+
replyMessageId?: string;
|
|
19
|
+
}
|
|
20
|
+
interface TextMessageParams extends MessageRequestParams<TextObject | string> {
|
|
21
|
+
previewUrl?: boolean;
|
|
22
|
+
}
|
|
23
|
+
interface ReactionParams {
|
|
24
|
+
messageId: string;
|
|
25
|
+
emoji: string;
|
|
26
|
+
to: string;
|
|
27
|
+
}
|
|
28
|
+
interface StatusParams {
|
|
29
|
+
status: string;
|
|
30
|
+
messageId: string;
|
|
31
|
+
typingIndicator?: {
|
|
32
|
+
type: string;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
15
35
|
declare class MessagesApi extends BaseAPI implements MessagesClass {
|
|
16
36
|
private readonly commonMethod;
|
|
17
37
|
private readonly commonEndpoint;
|
|
@@ -20,11 +40,11 @@ declare class MessagesApi extends BaseAPI implements MessagesClass {
|
|
|
20
40
|
* Builds the request body for WhatsApp API messages
|
|
21
41
|
* @param type The type of message to send
|
|
22
42
|
* @param payload The message payload object
|
|
23
|
-
* @param
|
|
43
|
+
* @param to The recipient's phone number
|
|
24
44
|
* @param replyMessageId Optional message ID to reply to
|
|
25
45
|
* @returns The formatted request body
|
|
26
46
|
*/
|
|
27
|
-
bodyBuilder<T extends MessageTypesEnum>(type: T, payload: MessagePayloadType<T>,
|
|
47
|
+
bodyBuilder<T extends MessageTypesEnum>(type: T, payload: MessagePayloadType<T>, to: string, replyMessageId?: string): MessageRequestBody<T>;
|
|
28
48
|
/**
|
|
29
49
|
* Sends a request to the WhatsApp API
|
|
30
50
|
* @param body The request body to send
|
|
@@ -33,171 +53,141 @@ declare class MessagesApi extends BaseAPI implements MessagesClass {
|
|
|
33
53
|
private send;
|
|
34
54
|
/**
|
|
35
55
|
* Sends an audio message via WhatsApp
|
|
36
|
-
* @param
|
|
37
|
-
* @param recipient Recipient's phone number
|
|
38
|
-
* @param replyMessageId Optional message ID to reply to
|
|
56
|
+
* @param params The audio message parameter object
|
|
39
57
|
* @returns Promise with the message response
|
|
40
58
|
*/
|
|
41
|
-
audio(
|
|
59
|
+
audio(params: MessageRequestParams$1<AudioMediaObject>): Promise<RequesterResponseInterface<MessagesResponse>>;
|
|
42
60
|
/**
|
|
43
61
|
* Sends a contact card via WhatsApp
|
|
44
|
-
* @param
|
|
45
|
-
* @param recipient Recipient's phone number
|
|
46
|
-
* @param replyMessageId Optional message ID to reply to
|
|
62
|
+
* @param params The contact message parameter object
|
|
47
63
|
* @returns Promise with the message response
|
|
48
64
|
*/
|
|
49
|
-
contacts(
|
|
65
|
+
contacts(params: MessageRequestParams$1<[ContactObject]>): Promise<RequesterResponseInterface<MessagesResponse>>;
|
|
50
66
|
/**
|
|
51
67
|
* Sends a document via WhatsApp
|
|
52
|
-
* @param
|
|
53
|
-
* @param recipient Recipient's phone number
|
|
54
|
-
* @param replyMessageId Optional message ID to reply to
|
|
68
|
+
* @param params The document message parameter object
|
|
55
69
|
* @returns Promise with the message response
|
|
56
70
|
*/
|
|
57
|
-
document(
|
|
71
|
+
document(params: MessageRequestParams$1<DocumentMediaObject>): Promise<RequesterResponseInterface<MessagesResponse>>;
|
|
58
72
|
/**
|
|
59
73
|
* Sends an image via WhatsApp
|
|
60
|
-
* @param
|
|
61
|
-
* @param recipient Recipient's phone number
|
|
62
|
-
* @param replyMessageId Optional message ID to reply to
|
|
74
|
+
* @param params The image message parameter object
|
|
63
75
|
* @returns Promise with the message response
|
|
64
76
|
*/
|
|
65
|
-
image(
|
|
77
|
+
image(params: MessageRequestParams$1<ImageMediaObject>): Promise<RequesterResponseInterface<MessagesResponse>>;
|
|
66
78
|
/**
|
|
67
79
|
* Sends an interactive message via WhatsApp
|
|
68
|
-
* @param
|
|
69
|
-
* @param recipient Recipient's phone number
|
|
70
|
-
* @param replyMessageId Optional message ID to reply to
|
|
80
|
+
* @param params The interactive message parameter object
|
|
71
81
|
* @returns Promise with the message response
|
|
72
82
|
*/
|
|
73
|
-
interactive(
|
|
83
|
+
interactive(params: MessageRequestParams$1<InteractiveObject>): Promise<RequesterResponseInterface<MessagesResponse>>;
|
|
74
84
|
/**
|
|
75
85
|
* Sends a location via WhatsApp
|
|
76
|
-
* @param
|
|
77
|
-
* @param recipient Recipient's phone number
|
|
78
|
-
* @param replyMessageId Optional message ID to reply to
|
|
86
|
+
* @param params The location message parameter object
|
|
79
87
|
* @returns Promise with the message response
|
|
80
88
|
*/
|
|
81
|
-
location(
|
|
89
|
+
location(params: MessageRequestParams$1<LocationObject>): Promise<RequesterResponseInterface<MessagesResponse>>;
|
|
82
90
|
/**
|
|
83
91
|
* Sends a sticker via WhatsApp
|
|
84
|
-
* @param
|
|
85
|
-
* @param recipient Recipient's phone number
|
|
86
|
-
* @param replyMessageId Optional message ID to reply to
|
|
92
|
+
* @param params The sticker message parameter object
|
|
87
93
|
* @returns Promise with the message response
|
|
88
94
|
*/
|
|
89
|
-
sticker(
|
|
95
|
+
sticker(params: MessageRequestParams$1<StickerMediaObject>): Promise<RequesterResponseInterface<MessagesResponse>>;
|
|
90
96
|
/**
|
|
91
97
|
* Sends a template message via WhatsApp
|
|
92
|
-
* @param
|
|
93
|
-
* @param recipient Recipient's phone number
|
|
94
|
-
* @param replyMessageId Optional message ID to reply to
|
|
98
|
+
* @param params The template message parameter object
|
|
95
99
|
* @returns Promise with the message response
|
|
96
100
|
*/
|
|
97
|
-
template(
|
|
101
|
+
template(params: MessageRequestParams$1<MessageTemplateObject<ComponentTypesEnum>>): Promise<RequesterResponseInterface<MessagesResponse>>;
|
|
98
102
|
/**
|
|
99
103
|
* Sends a text message via WhatsApp
|
|
100
|
-
* @param
|
|
101
|
-
* @param recipient Recipient's phone number
|
|
102
|
-
* @param replyMessageId Optional message ID to reply to
|
|
104
|
+
* @param params The text message parameter object
|
|
103
105
|
* @returns Promise with the message response
|
|
104
106
|
*/
|
|
105
|
-
text(
|
|
107
|
+
text(params: TextMessageParams$1): Promise<RequesterResponseInterface<MessagesResponse>>;
|
|
106
108
|
/**
|
|
107
109
|
* Sends a video via WhatsApp
|
|
108
|
-
* @param
|
|
109
|
-
* @param recipient Recipient's phone number
|
|
110
|
-
* @param replyMessageId Optional message ID to reply to
|
|
110
|
+
* @param params The video message parameter object
|
|
111
111
|
* @returns Promise with the message response
|
|
112
112
|
*/
|
|
113
|
-
video(
|
|
113
|
+
video(params: MessageRequestParams$1<VideoMediaObject>): Promise<RequesterResponseInterface<MessagesResponse>>;
|
|
114
114
|
/**
|
|
115
115
|
* Updates message status (used for read receipts and typing indicators)
|
|
116
|
-
* @param
|
|
116
|
+
* @param params The status update parameter object
|
|
117
117
|
* @returns Promise with the response
|
|
118
118
|
*/
|
|
119
|
-
status(
|
|
119
|
+
status(params: StatusParams$1): Promise<RequesterResponseInterface<MessagesResponse>>;
|
|
120
120
|
/**
|
|
121
121
|
* Marks a message as read in WhatsApp
|
|
122
|
-
* @param
|
|
122
|
+
* @param params The parameter object to mark message as read
|
|
123
123
|
* @returns Promise with the response
|
|
124
124
|
*/
|
|
125
|
-
markAsRead(
|
|
125
|
+
markAsRead(params: {
|
|
126
|
+
messageId: string;
|
|
127
|
+
}): Promise<RequesterResponseInterface<MessagesResponse>>;
|
|
126
128
|
/**
|
|
127
129
|
* Marks a message as read and shows a typing indicator in WhatsApp
|
|
128
|
-
* @param
|
|
130
|
+
* @param params The typing indicator parameter object
|
|
129
131
|
* @returns Promise with the response
|
|
130
132
|
*/
|
|
131
|
-
showTypingIndicator(
|
|
133
|
+
showTypingIndicator(params: {
|
|
134
|
+
messageId: string;
|
|
135
|
+
}): Promise<RequesterResponseInterface<MessagesResponse>>;
|
|
132
136
|
/**
|
|
133
137
|
* Sends an interactive list message
|
|
134
|
-
* @param
|
|
135
|
-
* @param recipient Recipient phone number
|
|
136
|
-
* @param replyMessageId Optional message ID to reply to
|
|
138
|
+
* @param params The list message parameter object
|
|
137
139
|
* @returns Promise with the response
|
|
138
140
|
*/
|
|
139
|
-
interactiveList(
|
|
141
|
+
interactiveList(params: MessageRequestParams$1<InteractiveObject & {
|
|
140
142
|
type: InteractiveTypesEnum.List;
|
|
141
|
-
}
|
|
143
|
+
}>): Promise<RequesterResponseInterface<MessagesResponse>>;
|
|
142
144
|
/**
|
|
143
145
|
* Sends an interactive CTA URL message
|
|
144
|
-
* @param
|
|
145
|
-
* @param recipient Recipient phone number
|
|
146
|
-
* @param replyMessageId Optional message ID to reply to
|
|
146
|
+
* @param params The CTA URL message parameter object
|
|
147
147
|
* @returns Promise with the response
|
|
148
148
|
*/
|
|
149
|
-
interactiveCtaUrl(
|
|
149
|
+
interactiveCtaUrl(params: MessageRequestParams$1<InteractiveObject & {
|
|
150
150
|
type: InteractiveTypesEnum.CtaUrl;
|
|
151
|
-
}
|
|
151
|
+
}>): Promise<RequesterResponseInterface<MessagesResponse>>;
|
|
152
152
|
/**
|
|
153
153
|
* Sends a location request message
|
|
154
|
-
* @param
|
|
155
|
-
* @param recipient Recipient phone number
|
|
156
|
-
* @param replyMessageId Optional message ID to reply to
|
|
154
|
+
* @param params The location request message parameter object
|
|
157
155
|
* @returns Promise with the response
|
|
158
156
|
*/
|
|
159
|
-
interactiveLocationRequest(
|
|
157
|
+
interactiveLocationRequest(params: MessageRequestParams$1<InteractiveObject & {
|
|
160
158
|
type: InteractiveTypesEnum.LocationRequest;
|
|
161
|
-
}
|
|
159
|
+
}>): Promise<RequesterResponseInterface<MessagesResponse>>;
|
|
162
160
|
/**
|
|
163
161
|
* Sends an address message to request shipping address from the user
|
|
164
162
|
* Note: This feature is only available for businesses based in India and their India customers
|
|
165
|
-
* @param
|
|
166
|
-
* @param recipient Recipient phone number
|
|
167
|
-
* @param replyMessageId Optional message ID to reply to
|
|
163
|
+
* @param params The address message parameter object
|
|
168
164
|
* @returns Promise with the response
|
|
169
165
|
*/
|
|
170
|
-
interactiveAddressMessage(
|
|
166
|
+
interactiveAddressMessage(params: MessageRequestParams$1<InteractiveObject & {
|
|
171
167
|
type: InteractiveTypesEnum.AddressMessage;
|
|
172
|
-
}
|
|
168
|
+
}>): Promise<RequesterResponseInterface<MessagesResponse>>;
|
|
173
169
|
/**
|
|
174
170
|
* Sends an interactive reply buttons message
|
|
175
|
-
* @param
|
|
176
|
-
* @param recipient Recipient phone number
|
|
177
|
-
* @param replyMessageId Optional message ID to reply to
|
|
171
|
+
* @param params The reply buttons message parameter object
|
|
178
172
|
* @returns Promise with the response
|
|
179
173
|
*/
|
|
180
|
-
interactiveReplyButtons(
|
|
174
|
+
interactiveReplyButtons(params: MessageRequestParams$1<InteractiveObject & {
|
|
181
175
|
type: InteractiveTypesEnum.Button;
|
|
182
|
-
}
|
|
176
|
+
}>): Promise<RequesterResponseInterface<MessagesResponse>>;
|
|
183
177
|
/**
|
|
184
178
|
* Sends an interactive Flow message
|
|
185
|
-
* @param
|
|
186
|
-
* @param recipient Recipient phone number
|
|
187
|
-
* @param replyMessageId Optional message ID to reply to
|
|
179
|
+
* @param params The Flow message parameter object
|
|
188
180
|
* @returns Promise with the response
|
|
189
181
|
*/
|
|
190
|
-
interactiveFlow(
|
|
182
|
+
interactiveFlow(params: MessageRequestParams$1<InteractiveObject & {
|
|
191
183
|
type: InteractiveTypesEnum.Flow;
|
|
192
|
-
}
|
|
184
|
+
}>): Promise<RequesterResponseInterface<MessagesResponse>>;
|
|
193
185
|
/**
|
|
194
186
|
* Sends a reaction to a message (emoji response)
|
|
195
|
-
* @param
|
|
196
|
-
* @param emoji The emoji to send as reaction (e.g. "😀", "❤️", "👍")
|
|
197
|
-
* @param recipient Recipient phone number
|
|
187
|
+
* @param params The reaction message parameter object
|
|
198
188
|
* @returns Promise with the response
|
|
199
189
|
*/
|
|
200
|
-
reaction(
|
|
190
|
+
reaction(params: ReactionParams$1): Promise<RequesterResponseInterface<MessagesResponse>>;
|
|
201
191
|
}
|
|
202
192
|
|
|
203
|
-
export { type MessagePayloadType, MessagesApi as default };
|
|
193
|
+
export { type MessagePayloadType, type MessageRequestParams, type ReactionParams, type StatusParams, type TextMessageParams, MessagesApi as default };
|
package/dist/api/messages.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var I=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var O=Object.prototype.hasOwnProperty;var D=(s,t)=>{for(var i in t)I(s,i,{get:t[i],enumerable:!0})},T=(s,t,i,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let R of N(t))!O.call(s,R)&&R!==i&&I(s,R,{get:()=>t[R],enumerable:!(e=M(t,R))||e.enumerable});return s};var l=s=>T(I({},"__esModule",{value:!0}),s);var f={};D(f,{default:()=>A});module.exports=l(f);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 B="BaseAPI",U=!1,G=new p(B,process.env.DEBUG==="true"||U),P=class{config;client;constructor(t,i){this.config=t,this.client=i,G.log("Initialized with HTTPSClient")}};var A=class extends P{commonMethod="POST";commonEndpoint="messages";constructor(t,i){super(t,i)}bodyBuilder(t,i,e,R){let a={messaging_product:"whatsapp",recipient_type:"individual",to:e,type:t,[t]:i};return R&&(a.context={message_id:R}),a}send(t){return this.client.sendRequest(this.commonMethod,`${this.config.WA_PHONE_NUMBER_ID}/${this.commonEndpoint}`,this.config.REQUEST_TIMEOUT,t)}async audio(t){let{body:i,to:e,replyMessageId:R}=t;return this.send(JSON.stringify(this.bodyBuilder("audio",i,e,R)))}async contacts(t){let{body:i,to:e,replyMessageId:R}=t;return this.send(JSON.stringify(this.bodyBuilder("contacts",i,e,R)))}async document(t){let{body:i,to:e,replyMessageId:R}=t;return this.send(JSON.stringify(this.bodyBuilder("document",i,e,R)))}async image(t){let{body:i,to:e,replyMessageId:R}=t;return this.send(JSON.stringify(this.bodyBuilder("image",i,e,R)))}async interactive(t){let{body:i,to:e,replyMessageId:R}=t;return this.send(JSON.stringify(this.bodyBuilder("interactive",i,e,R)))}async location(t){let{body:i,to:e,replyMessageId:R}=t;return this.send(JSON.stringify(this.bodyBuilder("location",i,e,R)))}async sticker(t){let{body:i,to:e,replyMessageId:R}=t;return this.send(JSON.stringify(this.bodyBuilder("sticker",i,e,R)))}async template(t){let{body:i,to:e,replyMessageId:R}=t;return this.send(JSON.stringify(this.bodyBuilder("template",i,e,R)))}async text(t){let{body:i,previewUrl:e,to:R,replyMessageId:a}=t,S;return typeof i=="string"?S={body:i,preview_url:e}:S=i,this.send(JSON.stringify(this.bodyBuilder("text",S,R,a)))}async video(t){let{body:i,to:e,replyMessageId:R}=t;return this.send(JSON.stringify(this.bodyBuilder("video",i,e,R)))}async status(t){let{status:i,messageId:e,typingIndicator:R}=t,a={messaging_product:"whatsapp",status:i,message_id:e,...R&&{typing_indicator:R}};return this.send(JSON.stringify(a))}async markAsRead(t){return this.status({status:"read",messageId:t.messageId})}async showTypingIndicator(t){return this.status({status:"read",messageId:t.messageId,typingIndicator:{type:"text"}})}async interactiveList(t){let{body:i,to:e,replyMessageId:R}=t;return this.send(JSON.stringify(this.bodyBuilder("interactive",i,e,R)))}async interactiveCtaUrl(t){let{body:i,to:e,replyMessageId:R}=t;return this.send(JSON.stringify(this.bodyBuilder("interactive",i,e,R)))}async interactiveLocationRequest(t){let{body:i,to:e,replyMessageId:R}=t;return this.send(JSON.stringify(this.bodyBuilder("interactive",i,e,R)))}async interactiveAddressMessage(t){let{body:i,to:e,replyMessageId:R}=t;return this.send(JSON.stringify(this.bodyBuilder("interactive",i,e,R)))}async interactiveReplyButtons(t){let{body:i,to:e,replyMessageId:R}=t;return this.send(JSON.stringify(this.bodyBuilder("interactive",i,e,R)))}async interactiveFlow(t){let{body:i,to:e,replyMessageId:R}=t;return this.send(JSON.stringify(this.bodyBuilder("interactive",i,e,R)))}async reaction(t){let{messageId:i,emoji:e,to:R}=t,a={messaging_product:"whatsapp",recipient_type:"individual",to:R,type:"reaction",reaction:{message_id:i,emoji:e}};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 {\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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AAK,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":["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"]}
|
|
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 InteractiveTypesEnum,\n MessageTypesEnum,\n WabaConfigEnum,\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\n// Request object interface type definitions\nexport interface MessageRequestParams<T> {\n body: T;\n to: string;\n replyMessageId?: string;\n}\n\nexport interface TextMessageParams extends MessageRequestParams<m.TextObject | string> {\n previewUrl?: boolean;\n}\n\nexport interface ReactionParams {\n messageId: string;\n emoji: string;\n to: string;\n}\n\nexport interface StatusParams {\n status: string;\n messageId: string;\n typingIndicator?: {\n type: string;\n };\n}\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 to 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 to: string,\n replyMessageId?: string,\n ) {\n const body: m.MessageRequestBody<T> = {\n messaging_product: 'whatsapp',\n recipient_type: 'individual',\n to,\n 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 params The audio message parameter object\n * @returns Promise with the message response\n */\n async audio(\n params: m.MessageRequestParams<m.AudioMediaObject>,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n const { body, to, replyMessageId } = params;\n return this.send(JSON.stringify(this.bodyBuilder(MessageTypesEnum.Audio, body, to, replyMessageId)));\n }\n\n /**\n * Sends a contact card via WhatsApp\n * @param params The contact message parameter object\n * @returns Promise with the message response\n */\n async contacts(\n params: m.MessageRequestParams<[m.ContactObject]>,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n const { body, to, replyMessageId } = params;\n return this.send(JSON.stringify(this.bodyBuilder(MessageTypesEnum.Contacts, body, to, replyMessageId)));\n }\n\n /**\n * Sends a document via WhatsApp\n * @param params The document message parameter object\n * @returns Promise with the message response\n */\n async document(\n params: m.MessageRequestParams<m.DocumentMediaObject>,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n const { body, to, replyMessageId } = params;\n return this.send(JSON.stringify(this.bodyBuilder(MessageTypesEnum.Document, body, to, replyMessageId)));\n }\n\n /**\n * Sends an image via WhatsApp\n * @param params The image message parameter object\n * @returns Promise with the message response\n */\n async image(\n params: m.MessageRequestParams<m.ImageMediaObject>,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n const { body, to, replyMessageId } = params;\n return this.send(JSON.stringify(this.bodyBuilder(MessageTypesEnum.Image, body, to, replyMessageId)));\n }\n\n /**\n * Sends an interactive message via WhatsApp\n * @param params The interactive message parameter object\n * @returns Promise with the message response\n */\n async interactive(\n params: m.MessageRequestParams<m.InteractiveObject>,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n const { body, to, replyMessageId } = params;\n return this.send(JSON.stringify(this.bodyBuilder(MessageTypesEnum.Interactive, body, to, replyMessageId)));\n }\n\n /**\n * Sends a location via WhatsApp\n * @param params The location message parameter object\n * @returns Promise with the message response\n */\n async location(\n params: m.MessageRequestParams<m.LocationObject>,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n const { body, to, replyMessageId } = params;\n return this.send(JSON.stringify(this.bodyBuilder(MessageTypesEnum.Location, body, to, replyMessageId)));\n }\n\n /**\n * Sends a sticker via WhatsApp\n * @param params The sticker message parameter object\n * @returns Promise with the message response\n */\n async sticker(\n params: m.MessageRequestParams<m.StickerMediaObject>,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n const { body, to, replyMessageId } = params;\n return this.send(JSON.stringify(this.bodyBuilder(MessageTypesEnum.Sticker, body, to, replyMessageId)));\n }\n\n /**\n * Sends a template message via WhatsApp\n * @param params The template message parameter object\n * @returns Promise with the message response\n */\n async template(\n params: m.MessageRequestParams<m.MessageTemplateObject<ComponentTypesEnum>>,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n const { body, to, replyMessageId } = params;\n return this.send(JSON.stringify(this.bodyBuilder(MessageTypesEnum.Template, body, to, replyMessageId)));\n }\n\n /**\n * Sends a text message via WhatsApp\n * @param params The text message parameter object\n * @returns Promise with the message response\n */\n async text(params: m.TextMessageParams): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n const { body, previewUrl, to, replyMessageId } = params;\n\n let textObject: m.TextObject;\n if (typeof body === 'string') {\n textObject = {\n body: body,\n preview_url: previewUrl,\n };\n } else {\n textObject = body;\n }\n\n return this.send(JSON.stringify(this.bodyBuilder(MessageTypesEnum.Text, textObject, to, replyMessageId)));\n }\n\n /**\n * Sends a video via WhatsApp\n * @param params The video message parameter object\n * @returns Promise with the message response\n */\n async video(\n params: m.MessageRequestParams<m.VideoMediaObject>,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n const { body, to, replyMessageId } = params;\n return this.send(JSON.stringify(this.bodyBuilder(MessageTypesEnum.Video, body, to, replyMessageId)));\n }\n\n /**\n * Updates message status (used for read receipts and typing indicators)\n * @param params The status update parameter object\n * @returns Promise with the response\n */\n async status(params: m.StatusParams): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n const { status, messageId, typingIndicator } = params;\n\n const bodyToSend = {\n messaging_product: 'whatsapp',\n status: status,\n message_id: messageId,\n ...(typingIndicator && { typing_indicator: typingIndicator }),\n };\n\n return this.send(JSON.stringify(bodyToSend));\n }\n\n /**\n * Marks a message as read in WhatsApp\n * @param params The parameter object to mark message as read\n * @returns Promise with the response\n */\n async markAsRead(params: { messageId: string }): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.status({\n status: 'read',\n messageId: params.messageId,\n });\n }\n\n /**\n * Marks a message as read and shows a typing indicator in WhatsApp\n * @param params The typing indicator parameter object\n * @returns Promise with the response\n */\n async showTypingIndicator(params: { messageId: string }): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.status({\n status: 'read',\n messageId: params.messageId,\n typingIndicator: {\n type: 'text',\n },\n });\n }\n\n /**\n * Sends an interactive list message\n * @param params The list message parameter object\n * @returns Promise with the response\n */\n async interactiveList(\n params: m.MessageRequestParams<m.InteractiveObject & { type: InteractiveTypesEnum.List }>,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n const { body, to, replyMessageId } = params;\n return this.send(JSON.stringify(this.bodyBuilder(MessageTypesEnum.Interactive, body, to, replyMessageId)));\n }\n\n /**\n * Sends an interactive CTA URL message\n * @param params The CTA URL message parameter object\n * @returns Promise with the response\n */\n async interactiveCtaUrl(\n params: m.MessageRequestParams<m.InteractiveObject & { type: InteractiveTypesEnum.CtaUrl }>,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n const { body, to, replyMessageId } = params;\n return this.send(JSON.stringify(this.bodyBuilder(MessageTypesEnum.Interactive, body, to, replyMessageId)));\n }\n\n /**\n * Sends a location request message\n * @param params The location request message parameter object\n * @returns Promise with the response\n */\n async interactiveLocationRequest(\n params: m.MessageRequestParams<m.InteractiveObject & { type: InteractiveTypesEnum.LocationRequest }>,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n const { body, to, replyMessageId } = params;\n return this.send(JSON.stringify(this.bodyBuilder(MessageTypesEnum.Interactive, body, to, replyMessageId)));\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 params The address message parameter object\n * @returns Promise with the response\n */\n async interactiveAddressMessage(\n params: m.MessageRequestParams<m.InteractiveObject & { type: InteractiveTypesEnum.AddressMessage }>,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n const { body, to, replyMessageId } = params;\n return this.send(JSON.stringify(this.bodyBuilder(MessageTypesEnum.Interactive, body, to, replyMessageId)));\n }\n\n /**\n * Sends an interactive reply buttons message\n * @param params The reply buttons message parameter object\n * @returns Promise with the response\n */\n async interactiveReplyButtons(\n params: m.MessageRequestParams<m.InteractiveObject & { type: InteractiveTypesEnum.Button }>,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n const { body, to, replyMessageId } = params;\n return this.send(JSON.stringify(this.bodyBuilder(MessageTypesEnum.Interactive, body, to, replyMessageId)));\n }\n\n /**\n * Sends an interactive Flow message\n * @param params The Flow message parameter object\n * @returns Promise with the response\n */\n async interactiveFlow(\n params: m.MessageRequestParams<m.InteractiveObject & { type: InteractiveTypesEnum.Flow }>,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n const { body, to, replyMessageId } = params;\n return this.send(JSON.stringify(this.bodyBuilder(MessageTypesEnum.Interactive, body, to, replyMessageId)));\n }\n\n /**\n * Sends a reaction to a message (emoji response)\n * @param params The reaction message parameter object\n * @returns Promise with the response\n */\n async reaction(params: m.ReactionParams): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n const { messageId, emoji, to } = params;\n\n const body = {\n messaging_product: 'whatsapp',\n recipient_type: 'individual',\n to: to,\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,QAA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,KAAM,WACN,SAAU,CACN,WAAYO,EACZ,MAAOG,CACX,CACJ,EAEA,OAAO,KAAK,KAAK,KAAK,UAAUR,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","to","replyMessageId","body","params","previewUrl","textObject","status","messageId","typingIndicator","bodyToSend","emoji"]}
|
package/dist/api/messages.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var a=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 I="BaseAPI",M=!1,N=new a(I,process.env.DEBUG==="true"||M),p=class{config;client;constructor(t,i){this.config=t,this.client=i,N.log("Initialized with HTTPSClient")}};var A=class extends p{commonMethod="POST";commonEndpoint="messages";constructor(t,i){super(t,i)}bodyBuilder(t,i,e,R){let s={messaging_product:"whatsapp",recipient_type:"individual",to:e,type:t,[t]:i};return R&&(s.context={message_id:R}),s}send(t){return this.client.sendRequest(this.commonMethod,`${this.config.WA_PHONE_NUMBER_ID}/${this.commonEndpoint}`,this.config.REQUEST_TIMEOUT,t)}async audio(t){let{body:i,to:e,replyMessageId:R}=t;return this.send(JSON.stringify(this.bodyBuilder("audio",i,e,R)))}async contacts(t){let{body:i,to:e,replyMessageId:R}=t;return this.send(JSON.stringify(this.bodyBuilder("contacts",i,e,R)))}async document(t){let{body:i,to:e,replyMessageId:R}=t;return this.send(JSON.stringify(this.bodyBuilder("document",i,e,R)))}async image(t){let{body:i,to:e,replyMessageId:R}=t;return this.send(JSON.stringify(this.bodyBuilder("image",i,e,R)))}async interactive(t){let{body:i,to:e,replyMessageId:R}=t;return this.send(JSON.stringify(this.bodyBuilder("interactive",i,e,R)))}async location(t){let{body:i,to:e,replyMessageId:R}=t;return this.send(JSON.stringify(this.bodyBuilder("location",i,e,R)))}async sticker(t){let{body:i,to:e,replyMessageId:R}=t;return this.send(JSON.stringify(this.bodyBuilder("sticker",i,e,R)))}async template(t){let{body:i,to:e,replyMessageId:R}=t;return this.send(JSON.stringify(this.bodyBuilder("template",i,e,R)))}async text(t){let{body:i,previewUrl:e,to:R,replyMessageId:s}=t,P;return typeof i=="string"?P={body:i,preview_url:e}:P=i,this.send(JSON.stringify(this.bodyBuilder("text",P,R,s)))}async video(t){let{body:i,to:e,replyMessageId:R}=t;return this.send(JSON.stringify(this.bodyBuilder("video",i,e,R)))}async status(t){let{status:i,messageId:e,typingIndicator:R}=t,s={messaging_product:"whatsapp",status:i,message_id:e,...R&&{typing_indicator:R}};return this.send(JSON.stringify(s))}async markAsRead(t){return this.status({status:"read",messageId:t.messageId})}async showTypingIndicator(t){return this.status({status:"read",messageId:t.messageId,typingIndicator:{type:"text"}})}async interactiveList(t){let{body:i,to:e,replyMessageId:R}=t;return this.send(JSON.stringify(this.bodyBuilder("interactive",i,e,R)))}async interactiveCtaUrl(t){let{body:i,to:e,replyMessageId:R}=t;return this.send(JSON.stringify(this.bodyBuilder("interactive",i,e,R)))}async interactiveLocationRequest(t){let{body:i,to:e,replyMessageId:R}=t;return this.send(JSON.stringify(this.bodyBuilder("interactive",i,e,R)))}async interactiveAddressMessage(t){let{body:i,to:e,replyMessageId:R}=t;return this.send(JSON.stringify(this.bodyBuilder("interactive",i,e,R)))}async interactiveReplyButtons(t){let{body:i,to:e,replyMessageId:R}=t;return this.send(JSON.stringify(this.bodyBuilder("interactive",i,e,R)))}async interactiveFlow(t){let{body:i,to:e,replyMessageId:R}=t;return this.send(JSON.stringify(this.bodyBuilder("interactive",i,e,R)))}async reaction(t){let{messageId:i,emoji:e,to:R}=t,s={messaging_product:"whatsapp",recipient_type:"individual",to:R,type:"reaction",reaction:{message_id:i,emoji:e}};return this.send(JSON.stringify(s))}};export{A 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 {\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,MAA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uD,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"]}
|
|
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 InteractiveTypesEnum,\n MessageTypesEnum,\n WabaConfigEnum,\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\n// Request object interface type definitions\nexport interface MessageRequestParams<T> {\n body: T;\n to: string;\n replyMessageId?: string;\n}\n\nexport interface TextMessageParams extends MessageRequestParams<m.TextObject | string> {\n previewUrl?: boolean;\n}\n\nexport interface ReactionParams {\n messageId: string;\n emoji: string;\n to: string;\n}\n\nexport interface StatusParams {\n status: string;\n messageId: string;\n typingIndicator?: {\n type: string;\n };\n}\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 to 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 to: string,\n replyMessageId?: string,\n ) {\n const body: m.MessageRequestBody<T> = {\n messaging_product: 'whatsapp',\n recipient_type: 'individual',\n to,\n 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 params The audio message parameter object\n * @returns Promise with the message response\n */\n async audio(\n params: m.MessageRequestParams<m.AudioMediaObject>,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n const { body, to, replyMessageId } = params;\n return this.send(JSON.stringify(this.bodyBuilder(MessageTypesEnum.Audio, body, to, replyMessageId)));\n }\n\n /**\n * Sends a contact card via WhatsApp\n * @param params The contact message parameter object\n * @returns Promise with the message response\n */\n async contacts(\n params: m.MessageRequestParams<[m.ContactObject]>,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n const { body, to, replyMessageId } = params;\n return this.send(JSON.stringify(this.bodyBuilder(MessageTypesEnum.Contacts, body, to, replyMessageId)));\n }\n\n /**\n * Sends a document via WhatsApp\n * @param params The document message parameter object\n * @returns Promise with the message response\n */\n async document(\n params: m.MessageRequestParams<m.DocumentMediaObject>,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n const { body, to, replyMessageId } = params;\n return this.send(JSON.stringify(this.bodyBuilder(MessageTypesEnum.Document, body, to, replyMessageId)));\n }\n\n /**\n * Sends an image via WhatsApp\n * @param params The image message parameter object\n * @returns Promise with the message response\n */\n async image(\n params: m.MessageRequestParams<m.ImageMediaObject>,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n const { body, to, replyMessageId } = params;\n return this.send(JSON.stringify(this.bodyBuilder(MessageTypesEnum.Image, body, to, replyMessageId)));\n }\n\n /**\n * Sends an interactive message via WhatsApp\n * @param params The interactive message parameter object\n * @returns Promise with the message response\n */\n async interactive(\n params: m.MessageRequestParams<m.InteractiveObject>,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n const { body, to, replyMessageId } = params;\n return this.send(JSON.stringify(this.bodyBuilder(MessageTypesEnum.Interactive, body, to, replyMessageId)));\n }\n\n /**\n * Sends a location via WhatsApp\n * @param params The location message parameter object\n * @returns Promise with the message response\n */\n async location(\n params: m.MessageRequestParams<m.LocationObject>,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n const { body, to, replyMessageId } = params;\n return this.send(JSON.stringify(this.bodyBuilder(MessageTypesEnum.Location, body, to, replyMessageId)));\n }\n\n /**\n * Sends a sticker via WhatsApp\n * @param params The sticker message parameter object\n * @returns Promise with the message response\n */\n async sticker(\n params: m.MessageRequestParams<m.StickerMediaObject>,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n const { body, to, replyMessageId } = params;\n return this.send(JSON.stringify(this.bodyBuilder(MessageTypesEnum.Sticker, body, to, replyMessageId)));\n }\n\n /**\n * Sends a template message via WhatsApp\n * @param params The template message parameter object\n * @returns Promise with the message response\n */\n async template(\n params: m.MessageRequestParams<m.MessageTemplateObject<ComponentTypesEnum>>,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n const { body, to, replyMessageId } = params;\n return this.send(JSON.stringify(this.bodyBuilder(MessageTypesEnum.Template, body, to, replyMessageId)));\n }\n\n /**\n * Sends a text message via WhatsApp\n * @param params The text message parameter object\n * @returns Promise with the message response\n */\n async text(params: m.TextMessageParams): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n const { body, previewUrl, to, replyMessageId } = params;\n\n let textObject: m.TextObject;\n if (typeof body === 'string') {\n textObject = {\n body: body,\n preview_url: previewUrl,\n };\n } else {\n textObject = body;\n }\n\n return this.send(JSON.stringify(this.bodyBuilder(MessageTypesEnum.Text, textObject, to, replyMessageId)));\n }\n\n /**\n * Sends a video via WhatsApp\n * @param params The video message parameter object\n * @returns Promise with the message response\n */\n async video(\n params: m.MessageRequestParams<m.VideoMediaObject>,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n const { body, to, replyMessageId } = params;\n return this.send(JSON.stringify(this.bodyBuilder(MessageTypesEnum.Video, body, to, replyMessageId)));\n }\n\n /**\n * Updates message status (used for read receipts and typing indicators)\n * @param params The status update parameter object\n * @returns Promise with the response\n */\n async status(params: m.StatusParams): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n const { status, messageId, typingIndicator } = params;\n\n const bodyToSend = {\n messaging_product: 'whatsapp',\n status: status,\n message_id: messageId,\n ...(typingIndicator && { typing_indicator: typingIndicator }),\n };\n\n return this.send(JSON.stringify(bodyToSend));\n }\n\n /**\n * Marks a message as read in WhatsApp\n * @param params The parameter object to mark message as read\n * @returns Promise with the response\n */\n async markAsRead(params: { messageId: string }): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.status({\n status: 'read',\n messageId: params.messageId,\n });\n }\n\n /**\n * Marks a message as read and shows a typing indicator in WhatsApp\n * @param params The typing indicator parameter object\n * @returns Promise with the response\n */\n async showTypingIndicator(params: { messageId: string }): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n return this.status({\n status: 'read',\n messageId: params.messageId,\n typingIndicator: {\n type: 'text',\n },\n });\n }\n\n /**\n * Sends an interactive list message\n * @param params The list message parameter object\n * @returns Promise with the response\n */\n async interactiveList(\n params: m.MessageRequestParams<m.InteractiveObject & { type: InteractiveTypesEnum.List }>,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n const { body, to, replyMessageId } = params;\n return this.send(JSON.stringify(this.bodyBuilder(MessageTypesEnum.Interactive, body, to, replyMessageId)));\n }\n\n /**\n * Sends an interactive CTA URL message\n * @param params The CTA URL message parameter object\n * @returns Promise with the response\n */\n async interactiveCtaUrl(\n params: m.MessageRequestParams<m.InteractiveObject & { type: InteractiveTypesEnum.CtaUrl }>,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n const { body, to, replyMessageId } = params;\n return this.send(JSON.stringify(this.bodyBuilder(MessageTypesEnum.Interactive, body, to, replyMessageId)));\n }\n\n /**\n * Sends a location request message\n * @param params The location request message parameter object\n * @returns Promise with the response\n */\n async interactiveLocationRequest(\n params: m.MessageRequestParams<m.InteractiveObject & { type: InteractiveTypesEnum.LocationRequest }>,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n const { body, to, replyMessageId } = params;\n return this.send(JSON.stringify(this.bodyBuilder(MessageTypesEnum.Interactive, body, to, replyMessageId)));\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 params The address message parameter object\n * @returns Promise with the response\n */\n async interactiveAddressMessage(\n params: m.MessageRequestParams<m.InteractiveObject & { type: InteractiveTypesEnum.AddressMessage }>,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n const { body, to, replyMessageId } = params;\n return this.send(JSON.stringify(this.bodyBuilder(MessageTypesEnum.Interactive, body, to, replyMessageId)));\n }\n\n /**\n * Sends an interactive reply buttons message\n * @param params The reply buttons message parameter object\n * @returns Promise with the response\n */\n async interactiveReplyButtons(\n params: m.MessageRequestParams<m.InteractiveObject & { type: InteractiveTypesEnum.Button }>,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n const { body, to, replyMessageId } = params;\n return this.send(JSON.stringify(this.bodyBuilder(MessageTypesEnum.Interactive, body, to, replyMessageId)));\n }\n\n /**\n * Sends an interactive Flow message\n * @param params The Flow message parameter object\n * @returns Promise with the response\n */\n async interactiveFlow(\n params: m.MessageRequestParams<m.InteractiveObject & { type: InteractiveTypesEnum.Flow }>,\n ): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n const { body, to, replyMessageId } = params;\n return this.send(JSON.stringify(this.bodyBuilder(MessageTypesEnum.Interactive, body, to, replyMessageId)));\n }\n\n /**\n * Sends a reaction to a message (emoji response)\n * @param params The reaction message parameter object\n * @returns Promise with the response\n */\n async reaction(params: m.ReactionParams): Promise<RequesterResponseInterface<m.MessagesResponse>> {\n const { messageId, emoji, to } = params;\n\n const body = {\n messaging_product: 'whatsapp',\n recipient_type: 'individual',\n to: to,\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,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AK,0BAA0CD,EAAMF,EAAIC,CAAc,CAAC,CAAC,CAC7G,CAQA,MAAM,0BACFE,EACuD,CACvD,GAAM,CAAE,KAAAD,EAAM,GAAAF,EAAI,eAAAC,CAAe,EAAIE,EACrC,OAAO,KAAK,KAAK,KAAK,UAAU,KAAK,0BAA0CD,EAAMF,EAAIC,CAAc,CAAC,CAAC,CAC7G,CAOA,MAAM,wBACFE,EACuD,CACvD,GAAM,CAAE,KAAAD,EAAM,GAAAF,EAAI,eAAAC,CAAe,EAAIE,EACrC,OAAO,KAAK,KAAK,KAAK,UAAU,KAAK,0BAA0CD,EAAMF,EAAIC,CAAc,CAAC,CAAC,CAC7G,CAOA,MAAM,gBACFE,EACuD,CACvD,GAAM,CAAE,KAAAD,EAAM,GAAAF,EAAI,eAAAC,CAAe,EAAIE,EACrC,OAAO,KAAK,KAAK,KAAK,UAAU,KAAK,0BAA0CD,EAAMF,EAAIC,CAAc,CAAC,CAAC,CAC7G,CAOA,MAAM,SAASE,EAAmF,CAC9F,GAAM,CAAE,UAAAI,EAAW,MAAAG,EAAO,GAAAV,CAAG,EAAIG,EAE3BD,EAAO,CACT,kBAAmB,WACnB,eAAgB,aAChB,GAAIF,EACJ,KAAM,WACN,SAAU,CACN,WAAYO,EACZ,MAAOG,CACX,CACJ,EAEA,OAAO,KAAK,KAAK,KAAK,UAAUR,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","to","replyMessageId","body","params","previewUrl","textObject","status","messageId","typingIndicator","bodyToSend","emoji"]}
|
package/dist/index.d.mts
CHANGED
|
@@ -5,7 +5,7 @@ export { GeneralHeaderInterface, GeneralRequestBody, Paging, RequesterClass, Req
|
|
|
5
5
|
export { BaseClass } from './types/base.mjs';
|
|
6
6
|
export { HttpsClientClass, HttpsClientResponseClass, ResponseHeaderValue, ResponseHeaders, ResponseJSONBody } from './types/httpsClient.mjs';
|
|
7
7
|
export { LoggerInterface } from './types/logger.mjs';
|
|
8
|
-
export { AudioMediaObject, AudioMessageRequestBody, ContactObject, ContactsMessageRequestBody, DocumentMediaObject, DocumentMessageRequestBody, GeneralMessageBody, ImageMediaObject, ImageMessageRequestBody, InteractiveMessageRequestBody, InteractiveObject, LocationMessageRequestBody, LocationObject, MessageRequestBody, MessageTemplateObject, MessageTemplateRequestBody, MessagesClass, MessagesResponse, ReactionMessageRequestBody, StatusObject, StatusRequestBody, StickerMediaObject, StickerMessageRequestBody, TextMessageRequestBody, TextObject, TypingIndicatorObject, VideoMediaObject, VideoMessageRequestBody } from './types/messages.mjs';
|
|
8
|
+
export { AudioMediaObject, AudioMessageRequestBody, ContactObject, ContactsMessageRequestBody, DocumentMediaObject, DocumentMessageRequestBody, GeneralMessageBody, ImageMediaObject, ImageMessageRequestBody, InteractiveMessageRequestBody, InteractiveObject, LocationMessageRequestBody, LocationObject, MessageRequestBody, MessageRequestParams, MessageTemplateObject, MessageTemplateRequestBody, MessagesClass, MessagesResponse, ReactionMessageRequestBody, ReactionParams, StatusObject, StatusParams, StatusRequestBody, StickerMediaObject, StickerMessageRequestBody, TextMessageParams, TextMessageRequestBody, TextObject, TypingIndicatorObject, VideoMediaObject, VideoMessageRequestBody } from './types/messages.mjs';
|
|
9
9
|
export { WhatsAppClass, WhatsAppConfig } from './types/whatsapp.mjs';
|
|
10
10
|
export { ComponentTypes, CopyCodeButton, FlowButton, MPMButton, OTPButton, PhoneNumberButton, QuickReplyButton, SPMButton, TemplateBody, TemplateButton, TemplateClass, TemplateDeleteParams, TemplateFooter, TemplateFormat, TemplateGetParams, TemplateHeader, TemplateHeaderExample, TemplateRequestBody, TemplateResponse, URLButton } from './types/template.mjs';
|
|
11
11
|
export { AccountMode, CodeVerificationStatus, Cursors, HealthStatus, HealthStatusEntity, MessagingLimitTier, PhoneNumberClass, PhoneNumberResponse, PhoneNumbersResponse, PlatformType, QualityRating, QualityScore, RequestVerificationCodeRequest, Throughput, ThroughputLevel, TwoStepVerificationParams, VerifyCodeRequest } from './types/phoneNumber.mjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export { GeneralHeaderInterface, GeneralRequestBody, Paging, RequesterClass, Req
|
|
|
5
5
|
export { BaseClass } from './types/base.js';
|
|
6
6
|
export { HttpsClientClass, HttpsClientResponseClass, ResponseHeaderValue, ResponseHeaders, ResponseJSONBody } from './types/httpsClient.js';
|
|
7
7
|
export { LoggerInterface } from './types/logger.js';
|
|
8
|
-
export { AudioMediaObject, AudioMessageRequestBody, ContactObject, ContactsMessageRequestBody, DocumentMediaObject, DocumentMessageRequestBody, GeneralMessageBody, ImageMediaObject, ImageMessageRequestBody, InteractiveMessageRequestBody, InteractiveObject, LocationMessageRequestBody, LocationObject, MessageRequestBody, MessageTemplateObject, MessageTemplateRequestBody, MessagesClass, MessagesResponse, ReactionMessageRequestBody, StatusObject, StatusRequestBody, StickerMediaObject, StickerMessageRequestBody, TextMessageRequestBody, TextObject, TypingIndicatorObject, VideoMediaObject, VideoMessageRequestBody } from './types/messages.js';
|
|
8
|
+
export { AudioMediaObject, AudioMessageRequestBody, ContactObject, ContactsMessageRequestBody, DocumentMediaObject, DocumentMessageRequestBody, GeneralMessageBody, ImageMediaObject, ImageMessageRequestBody, InteractiveMessageRequestBody, InteractiveObject, LocationMessageRequestBody, LocationObject, MessageRequestBody, MessageRequestParams, MessageTemplateObject, MessageTemplateRequestBody, MessagesClass, MessagesResponse, ReactionMessageRequestBody, ReactionParams, StatusObject, StatusParams, StatusRequestBody, StickerMediaObject, StickerMessageRequestBody, TextMessageParams, TextMessageRequestBody, TextObject, TypingIndicatorObject, VideoMediaObject, VideoMessageRequestBody } from './types/messages.js';
|
|
9
9
|
export { WhatsAppClass, WhatsAppConfig } from './types/whatsapp.js';
|
|
10
10
|
export { ComponentTypes, CopyCodeButton, FlowButton, MPMButton, OTPButton, PhoneNumberButton, QuickReplyButton, SPMButton, TemplateBody, TemplateButton, TemplateClass, TemplateDeleteParams, TemplateFooter, TemplateFormat, TemplateGetParams, TemplateHeader, TemplateHeaderExample, TemplateRequestBody, TemplateResponse, URLButton } from './types/template.js';
|
|
11
11
|
export { AccountMode, CodeVerificationStatus, Cursors, HealthStatus, HealthStatusEntity, MessagingLimitTier, PhoneNumberClass, PhoneNumberResponse, PhoneNumbersResponse, PlatformType, QualityRating, QualityScore, RequestVerificationCodeRequest, Throughput, ThroughputLevel, TwoStepVerificationParams, VerifyCodeRequest } from './types/phoneNumber.js';
|