@rempays/shared-core 1.0.2-beta.17 → 1.0.2-beta.18
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { SendTextParams, SendTemplateParams, SendInteractiveParams, SendInteractiveListParams, SendImageParams, SendDocumentParams, SendLocationParams, SetTypingParams, MarkAsReadParams, SendAudioParams, SendVideoParams, MediaInfoResponse, CreateTemplateParams,
|
|
1
|
+
import type { SendTextParams, SendTemplateParams, SendInteractiveParams, SendInteractiveListParams, SendImageParams, SendDocumentParams, SendLocationParams, SetTypingParams, MarkAsReadParams, SendAudioParams, SendVideoParams, MediaInfoResponse, CreateTemplateParams, BusinessProfileResponse, UpdateDisplayNameParams, DisplayNameStatusResponse } from "./types";
|
|
2
2
|
export declare class FacebookApi {
|
|
3
3
|
private static token;
|
|
4
4
|
private static phoneNumberId;
|
|
@@ -39,7 +39,6 @@ export declare class FacebookApi {
|
|
|
39
39
|
static getBusinessProfile(): Promise<{
|
|
40
40
|
data: BusinessProfileResponse[];
|
|
41
41
|
}>;
|
|
42
|
-
static updateBusinessProfile(params: BusinessProfileParams): Promise<any>;
|
|
43
42
|
static updateDisplayName(params: UpdateDisplayNameParams): Promise<any>;
|
|
44
43
|
static getDisplayNameStatus(): Promise<DisplayNameStatusResponse>;
|
|
45
44
|
}
|
|
@@ -36,6 +36,10 @@ class FacebookApi {
|
|
|
36
36
|
await this.init();
|
|
37
37
|
const url = `https://graph.facebook.com/${this.apiVersion}/${this.phoneNumberId}/${path}`;
|
|
38
38
|
try {
|
|
39
|
+
console.log("[layer-core/facebook-api] Sending message", {
|
|
40
|
+
url,
|
|
41
|
+
payload,
|
|
42
|
+
});
|
|
39
43
|
const http = (0, http_1.getHttpClient)(this.token);
|
|
40
44
|
const { data } = await http.post(url, payload);
|
|
41
45
|
return data;
|
|
@@ -48,8 +52,8 @@ class FacebookApi {
|
|
|
48
52
|
}
|
|
49
53
|
}
|
|
50
54
|
/*
|
|
51
|
-
|
|
52
|
-
|
|
55
|
+
TEXT
|
|
56
|
+
*/
|
|
53
57
|
static async sendText(params) {
|
|
54
58
|
const payload = {
|
|
55
59
|
messaging_product: "whatsapp",
|
|
@@ -64,8 +68,8 @@ class FacebookApi {
|
|
|
64
68
|
return await this.post("messages", payload);
|
|
65
69
|
}
|
|
66
70
|
/*
|
|
67
|
-
|
|
68
|
-
|
|
71
|
+
TEMPLATE
|
|
72
|
+
*/
|
|
69
73
|
static async sendTemplate(params) {
|
|
70
74
|
const payload = {
|
|
71
75
|
messaging_product: "whatsapp",
|
|
@@ -80,8 +84,8 @@ class FacebookApi {
|
|
|
80
84
|
return await this.post("messages", payload);
|
|
81
85
|
}
|
|
82
86
|
/*
|
|
83
|
-
|
|
84
|
-
|
|
87
|
+
BUTTONS
|
|
88
|
+
*/
|
|
85
89
|
static async sendInteractiveButtons(params) {
|
|
86
90
|
const payload = {
|
|
87
91
|
messaging_product: "whatsapp",
|
|
@@ -103,8 +107,8 @@ class FacebookApi {
|
|
|
103
107
|
return await this.post("messages", payload);
|
|
104
108
|
}
|
|
105
109
|
/*
|
|
106
|
-
|
|
107
|
-
|
|
110
|
+
LIST
|
|
111
|
+
*/
|
|
108
112
|
static async sendInteractiveList(params) {
|
|
109
113
|
const payload = {
|
|
110
114
|
messaging_product: "whatsapp",
|
|
@@ -135,8 +139,8 @@ class FacebookApi {
|
|
|
135
139
|
return await this.post("messages", payload);
|
|
136
140
|
}
|
|
137
141
|
/*
|
|
138
|
-
|
|
139
|
-
|
|
142
|
+
IMAGE
|
|
143
|
+
*/
|
|
140
144
|
static async sendImage(params) {
|
|
141
145
|
const payload = {
|
|
142
146
|
messaging_product: "whatsapp",
|
|
@@ -145,14 +149,14 @@ class FacebookApi {
|
|
|
145
149
|
image: {
|
|
146
150
|
link: params.link,
|
|
147
151
|
id: params.id,
|
|
148
|
-
caption: params.caption
|
|
152
|
+
caption: params.caption,
|
|
149
153
|
},
|
|
150
154
|
};
|
|
151
155
|
return await this.post("messages", payload);
|
|
152
156
|
}
|
|
153
157
|
/*
|
|
154
|
-
|
|
155
|
-
|
|
158
|
+
DOCUMENT
|
|
159
|
+
*/
|
|
156
160
|
static async sendDocument(params) {
|
|
157
161
|
const payload = {
|
|
158
162
|
messaging_product: "whatsapp",
|
|
@@ -168,8 +172,8 @@ class FacebookApi {
|
|
|
168
172
|
return await this.post("messages", payload);
|
|
169
173
|
}
|
|
170
174
|
/*
|
|
171
|
-
|
|
172
|
-
|
|
175
|
+
AUDIO (NEW)
|
|
176
|
+
*/
|
|
173
177
|
static async sendAudio(params) {
|
|
174
178
|
const payload = {
|
|
175
179
|
messaging_product: "whatsapp",
|
|
@@ -183,8 +187,8 @@ class FacebookApi {
|
|
|
183
187
|
return await this.post("messages", payload);
|
|
184
188
|
}
|
|
185
189
|
/*
|
|
186
|
-
|
|
187
|
-
|
|
190
|
+
VIDEO (NEW)
|
|
191
|
+
*/
|
|
188
192
|
static async sendVideo(params) {
|
|
189
193
|
const payload = {
|
|
190
194
|
messaging_product: "whatsapp",
|
|
@@ -199,8 +203,8 @@ class FacebookApi {
|
|
|
199
203
|
return await this.post("messages", payload);
|
|
200
204
|
}
|
|
201
205
|
/*
|
|
202
|
-
|
|
203
|
-
|
|
206
|
+
LOCATION
|
|
207
|
+
*/
|
|
204
208
|
static async sendLocation(params) {
|
|
205
209
|
const payload = {
|
|
206
210
|
messaging_product: "whatsapp",
|
|
@@ -216,8 +220,8 @@ class FacebookApi {
|
|
|
216
220
|
return await this.post("messages", payload);
|
|
217
221
|
}
|
|
218
222
|
/*
|
|
219
|
-
|
|
220
|
-
|
|
223
|
+
TYPING
|
|
224
|
+
*/
|
|
221
225
|
static async setTyping(params) {
|
|
222
226
|
const payload = {
|
|
223
227
|
messaging_product: "whatsapp",
|
|
@@ -228,8 +232,8 @@ class FacebookApi {
|
|
|
228
232
|
return await this.post("messages", payload);
|
|
229
233
|
}
|
|
230
234
|
/*
|
|
231
|
-
|
|
232
|
-
|
|
235
|
+
READ
|
|
236
|
+
*/
|
|
233
237
|
static async markAsRead(params) {
|
|
234
238
|
const payload = {
|
|
235
239
|
messaging_product: "whatsapp",
|
|
@@ -239,8 +243,8 @@ class FacebookApi {
|
|
|
239
243
|
return await this.post("messages", payload);
|
|
240
244
|
}
|
|
241
245
|
/*
|
|
242
|
-
|
|
243
|
-
|
|
246
|
+
MEDIA INFO (NEW)
|
|
247
|
+
*/
|
|
244
248
|
static async getMediaInfo(mediaId) {
|
|
245
249
|
await this.init();
|
|
246
250
|
const http = (0, http_1.getHttpClient)(this.token);
|
|
@@ -249,8 +253,8 @@ class FacebookApi {
|
|
|
249
253
|
return data;
|
|
250
254
|
}
|
|
251
255
|
/*
|
|
252
|
-
|
|
253
|
-
|
|
256
|
+
DOWNLOAD MEDIA (NEW)
|
|
257
|
+
*/
|
|
254
258
|
static async downloadMedia(mediaId) {
|
|
255
259
|
await this.init();
|
|
256
260
|
const media = await this.getMediaInfo(mediaId);
|
|
@@ -261,8 +265,8 @@ class FacebookApi {
|
|
|
261
265
|
return data;
|
|
262
266
|
}
|
|
263
267
|
/*
|
|
264
|
-
|
|
265
|
-
|
|
268
|
+
GOOGLE MAP URL (NEW)
|
|
269
|
+
*/
|
|
266
270
|
static buildGoogleMapsUrl(latitude, longitude) {
|
|
267
271
|
return `https://www.google.com/maps?q=${latitude},${longitude}`;
|
|
268
272
|
}
|
|
@@ -284,9 +288,9 @@ class FacebookApi {
|
|
|
284
288
|
components: [
|
|
285
289
|
{
|
|
286
290
|
type: "BODY",
|
|
287
|
-
text: params.bodyText
|
|
288
|
-
}
|
|
289
|
-
]
|
|
291
|
+
text: params.bodyText,
|
|
292
|
+
},
|
|
293
|
+
],
|
|
290
294
|
};
|
|
291
295
|
const { data } = await http.post(url, payload);
|
|
292
296
|
return data;
|
|
@@ -296,25 +300,30 @@ class FacebookApi {
|
|
|
296
300
|
const http = (0, http_1.getHttpClient)(this.token);
|
|
297
301
|
const url = `https://graph.facebook.com/${this.apiVersion}/${wabaId}/message_templates`;
|
|
298
302
|
const { data } = await http.delete(url, {
|
|
299
|
-
params: { name }
|
|
303
|
+
params: { name },
|
|
300
304
|
});
|
|
301
305
|
return data;
|
|
302
306
|
}
|
|
303
307
|
/*
|
|
304
|
-
|
|
305
|
-
|
|
308
|
+
PROFILE PICTURE UPLOAD (TWO-STEP)
|
|
309
|
+
*/
|
|
306
310
|
/**
|
|
307
311
|
* Updates the business profile picture using a direct URL.
|
|
308
312
|
* @param url Public URL of the image
|
|
309
313
|
*/
|
|
310
314
|
static async updateProfilePicture(url) {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
}
|
|
315
|
+
await this.init();
|
|
316
|
+
const http = (0, http_1.getHttpClient)(this.token);
|
|
317
|
+
const urlEnv = `https://graph.facebook.com/${this.apiVersion}/${this.phoneNumberId}/profile_picture`;
|
|
318
|
+
const payload = {
|
|
319
|
+
profile_picture_url: url,
|
|
320
|
+
};
|
|
321
|
+
const { data } = await http.post(urlEnv, payload);
|
|
322
|
+
return data;
|
|
314
323
|
}
|
|
315
324
|
/*
|
|
316
|
-
|
|
317
|
-
|
|
325
|
+
CHAT MEDIA UPLOAD
|
|
326
|
+
*/
|
|
318
327
|
/**
|
|
319
328
|
* Uploads media for chat (messages).
|
|
320
329
|
* @param buffer Media binary data
|
|
@@ -326,19 +335,19 @@ class FacebookApi {
|
|
|
326
335
|
const url = `https://graph.facebook.com/${this.apiVersion}/${this.phoneNumberId}/media`;
|
|
327
336
|
const formData = new FormData();
|
|
328
337
|
const blob = new Blob([buffer], { type: mimeType });
|
|
329
|
-
formData.append(
|
|
330
|
-
formData.append(
|
|
331
|
-
formData.append(
|
|
338
|
+
formData.append("file", blob, "media");
|
|
339
|
+
formData.append("type", mimeType);
|
|
340
|
+
formData.append("messaging_product", "whatsapp");
|
|
332
341
|
const { data } = await http.post(url, formData, {
|
|
333
342
|
headers: {
|
|
334
|
-
|
|
335
|
-
}
|
|
343
|
+
"Content-Type": "multipart/form-data",
|
|
344
|
+
},
|
|
336
345
|
});
|
|
337
346
|
return data; // Returns { id: "media_id" }
|
|
338
347
|
}
|
|
339
348
|
/*
|
|
340
|
-
|
|
341
|
-
|
|
349
|
+
BUSINESS PROFILE
|
|
350
|
+
*/
|
|
342
351
|
static async getBusinessProfile() {
|
|
343
352
|
await this.init();
|
|
344
353
|
const http = (0, http_1.getHttpClient)(this.token);
|
|
@@ -349,16 +358,9 @@ class FacebookApi {
|
|
|
349
358
|
// Returning the full structure { data: [ ... ] } as requested
|
|
350
359
|
return data;
|
|
351
360
|
}
|
|
352
|
-
static async updateBusinessProfile(params) {
|
|
353
|
-
const payload = {
|
|
354
|
-
messaging_product: "whatsapp",
|
|
355
|
-
...params
|
|
356
|
-
};
|
|
357
|
-
return await this.post("whatsapp_business_profile", payload);
|
|
358
|
-
}
|
|
359
361
|
/*
|
|
360
|
-
|
|
361
|
-
|
|
362
|
+
DISPLAY NAME
|
|
363
|
+
*/
|
|
362
364
|
static async updateDisplayName(params) {
|
|
363
365
|
await this.init();
|
|
364
366
|
const http = (0, http_1.getHttpClient)(this.token);
|
|
@@ -366,8 +368,8 @@ class FacebookApi {
|
|
|
366
368
|
const url = `https://graph.facebook.com/${this.apiVersion}/${this.phoneNumberId}`;
|
|
367
369
|
const { data } = await http.post(url, null, {
|
|
368
370
|
params: {
|
|
369
|
-
new_display_name: params.new_display_name
|
|
370
|
-
}
|
|
371
|
+
new_display_name: params.new_display_name,
|
|
372
|
+
},
|
|
371
373
|
});
|
|
372
374
|
return data;
|
|
373
375
|
}
|
|
@@ -378,8 +380,8 @@ class FacebookApi {
|
|
|
378
380
|
const url = `https://graph.facebook.com/${this.apiVersion}/${this.phoneNumberId}`;
|
|
379
381
|
const { data } = await http.get(url, {
|
|
380
382
|
params: {
|
|
381
|
-
fields: "verified_name,name_status,new_display_name,new_name_status"
|
|
382
|
-
}
|
|
383
|
+
fields: "verified_name,name_status,new_display_name,new_name_status",
|
|
384
|
+
},
|
|
383
385
|
});
|
|
384
386
|
return data;
|
|
385
387
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rempays/shared-core",
|
|
3
|
-
"version": "1.0.2-beta.
|
|
3
|
+
"version": "1.0.2-beta.18",
|
|
4
4
|
"description": "Core utilities layer for RemPays platform with AWS services integration (Cognito, S3, Secrets Manager, Textract, Facebook API, DynamoDB)",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|