@rempays/shared-core 1.0.2-beta.16 → 1.0.2-beta.17
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.
|
@@ -3,8 +3,7 @@ export declare class FacebookApi {
|
|
|
3
3
|
private static token;
|
|
4
4
|
private static phoneNumberId;
|
|
5
5
|
private static apiVersion;
|
|
6
|
-
|
|
7
|
-
constructor(token?: string, phoneNumberId?: string, apiVersion?: string, appId?: string);
|
|
6
|
+
constructor(token?: string, phoneNumberId?: string, apiVersion?: string);
|
|
8
7
|
private static init;
|
|
9
8
|
private static post;
|
|
10
9
|
static sendText(params: SendTextParams): Promise<any>;
|
|
@@ -25,11 +24,10 @@ export declare class FacebookApi {
|
|
|
25
24
|
static createTemplate(params: CreateTemplateParams): Promise<any>;
|
|
26
25
|
static deleteTemplate(wabaId: string, name: string): Promise<any>;
|
|
27
26
|
/**
|
|
28
|
-
*
|
|
29
|
-
* @param
|
|
30
|
-
* @param mimeType Image MIME type (image/jpeg or image/png)
|
|
27
|
+
* Updates the business profile picture using a direct URL.
|
|
28
|
+
* @param url Public URL of the image
|
|
31
29
|
*/
|
|
32
|
-
static updateProfilePicture(
|
|
30
|
+
static updateProfilePicture(url: string): Promise<any>;
|
|
33
31
|
/**
|
|
34
32
|
* Uploads media for chat (messages).
|
|
35
33
|
* @param buffer Media binary data
|
|
@@ -3,15 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.FacebookApi = void 0;
|
|
4
4
|
const http_1 = require("./http");
|
|
5
5
|
class FacebookApi {
|
|
6
|
-
constructor(token, phoneNumberId, apiVersion
|
|
6
|
+
constructor(token, phoneNumberId, apiVersion) {
|
|
7
7
|
if (token)
|
|
8
8
|
FacebookApi.token = token;
|
|
9
9
|
if (phoneNumberId)
|
|
10
10
|
FacebookApi.phoneNumberId = phoneNumberId;
|
|
11
11
|
if (apiVersion)
|
|
12
12
|
FacebookApi.apiVersion = apiVersion;
|
|
13
|
-
if (appId)
|
|
14
|
-
FacebookApi.appId = appId;
|
|
15
13
|
}
|
|
16
14
|
static async init() {
|
|
17
15
|
if (this.token && this.phoneNumberId && this.apiVersion)
|
|
@@ -21,7 +19,6 @@ class FacebookApi {
|
|
|
21
19
|
this.phoneNumberId || process.env.FACEBOOK_PHONE_NUMBER_ID || null;
|
|
22
20
|
this.apiVersion =
|
|
23
21
|
this.apiVersion || process.env.FACEBOOK_API_VERSION || "v18.0";
|
|
24
|
-
this.appId = this.appId || process.env.FACEBOOK_APP_ID || null;
|
|
25
22
|
if (!this.token || !this.phoneNumberId) {
|
|
26
23
|
throw new Error("Facebook API environment variables are not properly configured (FACEBOOK_API_TOKEN, FACEBOOK_PHONE_NUMBER_ID)");
|
|
27
24
|
}
|
|
@@ -307,38 +304,12 @@ class FacebookApi {
|
|
|
307
304
|
PROFILE PICTURE UPLOAD (TWO-STEP)
|
|
308
305
|
*/
|
|
309
306
|
/**
|
|
310
|
-
*
|
|
311
|
-
* @param
|
|
312
|
-
* @param mimeType Image MIME type (image/jpeg or image/png)
|
|
307
|
+
* Updates the business profile picture using a direct URL.
|
|
308
|
+
* @param url Public URL of the image
|
|
313
309
|
*/
|
|
314
|
-
static async updateProfilePicture(
|
|
315
|
-
await this.init();
|
|
316
|
-
if (!this.appId) {
|
|
317
|
-
throw new Error("FACEBOOK_APP_ID is required for profile picture uploads");
|
|
318
|
-
}
|
|
319
|
-
const http = (0, http_1.getHttpClient)(this.token);
|
|
320
|
-
// 1. Create upload session
|
|
321
|
-
const sessionUrl = `https://graph.facebook.com/${this.apiVersion}/${this.appId}/uploads`;
|
|
322
|
-
const { data: sessionData } = await http.post(sessionUrl, null, {
|
|
323
|
-
params: {
|
|
324
|
-
file_length: buffer.length,
|
|
325
|
-
file_type: mimeType,
|
|
326
|
-
access_token: this.token
|
|
327
|
-
}
|
|
328
|
-
});
|
|
329
|
-
const sessionId = sessionData.id;
|
|
330
|
-
// 2. Upload the file data
|
|
331
|
-
const uploadUrl = `https://graph.facebook.com/${this.apiVersion}/${sessionId}`;
|
|
332
|
-
const { data: uploadData } = await http.post(uploadUrl, buffer, {
|
|
333
|
-
headers: {
|
|
334
|
-
'file_offset': 0,
|
|
335
|
-
'Content-Type': mimeType
|
|
336
|
-
}
|
|
337
|
-
});
|
|
338
|
-
const handle = uploadData.h;
|
|
339
|
-
// 3. Update the business profile with the handle
|
|
310
|
+
static async updateProfilePicture(url) {
|
|
340
311
|
return await this.updateBusinessProfile({
|
|
341
|
-
|
|
312
|
+
profile_picture_url: url
|
|
342
313
|
});
|
|
343
314
|
}
|
|
344
315
|
/*
|
|
@@ -417,4 +388,3 @@ exports.FacebookApi = FacebookApi;
|
|
|
417
388
|
FacebookApi.token = null;
|
|
418
389
|
FacebookApi.phoneNumberId = null;
|
|
419
390
|
FacebookApi.apiVersion = null;
|
|
420
|
-
FacebookApi.appId = null;
|
|
@@ -147,6 +147,7 @@ export interface BusinessProfileParams {
|
|
|
147
147
|
websites?: string[];
|
|
148
148
|
vertical?: WhatsAppBusinessVertical;
|
|
149
149
|
profile_picture_handle?: string;
|
|
150
|
+
profile_picture_url?: string;
|
|
150
151
|
}
|
|
151
152
|
export type WhatsAppBusinessVertical = "" | "UNDEFINED" | "OTHER" | "AUTO" | "BEAUTY" | "APPAREL" | "EDU" | "ENTERTAIN" | "EVENT_PLAN" | "FINANCE" | "GROCERY" | "GOVT" | "HOTEL" | "HEALTH" | "NONPROFIT" | "PROF_SERVICES" | "RETAIL" | "TRAVEL" | "RESTAURANT" | "NOT_A_BIZ";
|
|
152
153
|
export interface BusinessProfileResponse {
|
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.17",
|
|
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",
|