@natyapp/meta 1.6.0 → 1.6.2
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/Entities/connection.d.ts +2 -1
- package/dist/Entities/whatsappMessage.d.ts +10 -0
- package/dist/services/axiosInstances.d.ts +1 -0
- package/dist/services/axiosInstances.js +5 -1
- package/dist/useCases/message/whatsappResponse.d.ts +1 -0
- package/dist/useCases/message/whatsappResponse.js +24 -0
- package/package.json +1 -1
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
export declare class ConnectionEntity {
|
|
2
|
+
_id: string;
|
|
2
3
|
id: string;
|
|
3
4
|
companyId: string;
|
|
4
5
|
appId: string;
|
|
5
6
|
appSecret: string;
|
|
6
7
|
accessToken: string;
|
|
8
|
+
accountId: string;
|
|
7
9
|
businessId: string;
|
|
8
10
|
phoneNumberId: string;
|
|
9
11
|
phoneNumber: number;
|
|
10
12
|
isActive: boolean;
|
|
11
|
-
_id: string;
|
|
12
13
|
updatedAt: string;
|
|
13
14
|
createdAt: string;
|
|
14
15
|
constructor(props: Omit<ConnectionEntity, "_id" | "updatedAt" | "createdAt" | "id" | "isActive">, id?: string);
|
|
@@ -59,5 +59,15 @@ type statusesType = {
|
|
|
59
59
|
pricing_model: string;
|
|
60
60
|
category: string;
|
|
61
61
|
};
|
|
62
|
+
errors: errorsType[];
|
|
63
|
+
};
|
|
64
|
+
type errorsType = {
|
|
65
|
+
code: number;
|
|
66
|
+
title: string;
|
|
67
|
+
message: string;
|
|
68
|
+
error_data: {
|
|
69
|
+
details: string;
|
|
70
|
+
};
|
|
71
|
+
href: string;
|
|
62
72
|
};
|
|
63
73
|
export {};
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.updateInterceptor = exports.api = exports.axiosInstanceGeneral = exports.axiosInstanceForDownloadMedia = exports.newAxiosInstance = void 0;
|
|
6
|
+
exports.newFacebookInstance = exports.updateInterceptor = exports.api = exports.axiosInstanceGeneral = exports.axiosInstanceForDownloadMedia = exports.newAxiosInstance = void 0;
|
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
|
8
8
|
const axiosInterceptors_1 = require("../configs/axiosInterceptors");
|
|
9
9
|
const newAxiosInstance = ({ url = "https://graph.facebook.com/v18.0/", phone_number_id, accessToken, }) => axios_1.default.create({
|
|
@@ -42,3 +42,7 @@ const updateInterceptor = async (interceptors, callback) => {
|
|
|
42
42
|
});
|
|
43
43
|
};
|
|
44
44
|
exports.updateInterceptor = updateInterceptor;
|
|
45
|
+
const newFacebookInstance = () => axios_1.default.create({
|
|
46
|
+
baseURL: "https://graph.facebook.com/v18.0/"
|
|
47
|
+
});
|
|
48
|
+
exports.newFacebookInstance = newFacebookInstance;
|
|
@@ -59,4 +59,5 @@ export declare class WhatsappResponse {
|
|
|
59
59
|
send_audio(stream: string, filetype: "audio/aac" | "audio/mp4" | "audio/mpeg" | "audio/amr" | "audio/ogg" | "link"): Promise<ISendMessageReturn | null>;
|
|
60
60
|
download_media(url: string, mimetype: string): Promise<any>;
|
|
61
61
|
get_media_url(media_id: string): Promise<any>;
|
|
62
|
+
update_long_lived_token(client_id: string, client_secret: string, fb_exchange_token: string): Promise<string | undefined>;
|
|
62
63
|
}
|
|
@@ -27,6 +27,11 @@ class WhatsappResponse {
|
|
|
27
27
|
const connection = getConnections.isSuccess.find(item => item.phoneNumberId === this.phone_number_id);
|
|
28
28
|
if (!connection)
|
|
29
29
|
throw new Error("Não foi possível encontrar a instância");
|
|
30
|
+
const longLivedToken = await this.update_long_lived_token(connection.appId, connection.appSecret, connection.accessToken);
|
|
31
|
+
if (longLivedToken) {
|
|
32
|
+
connection.accessToken = longLivedToken;
|
|
33
|
+
await services_1.connectionMutations.update(connection._id, connection);
|
|
34
|
+
}
|
|
30
35
|
const token = connection.accessToken;
|
|
31
36
|
this.token = token;
|
|
32
37
|
this.apiCall = (0, services_1.newAxiosInstance)({
|
|
@@ -401,5 +406,24 @@ class WhatsappResponse {
|
|
|
401
406
|
console.log(err.response.data.error);
|
|
402
407
|
}
|
|
403
408
|
}
|
|
409
|
+
async update_long_lived_token(client_id, client_secret, fb_exchange_token) {
|
|
410
|
+
try {
|
|
411
|
+
const fbApi = (0, services_1.newFacebookInstance)();
|
|
412
|
+
const getLongLivedToken = await fbApi.get("/oauth/access_token", {
|
|
413
|
+
params: {
|
|
414
|
+
grant_type: "fb_exchange_token",
|
|
415
|
+
client_id: client_id,
|
|
416
|
+
client_secret: client_secret,
|
|
417
|
+
fb_exchange_token: fb_exchange_token,
|
|
418
|
+
},
|
|
419
|
+
});
|
|
420
|
+
return getLongLivedToken.data.access_token;
|
|
421
|
+
}
|
|
422
|
+
catch (err) {
|
|
423
|
+
console.log("Não foi possível requisitar o token de vida longa");
|
|
424
|
+
console.log(err.response.data.error);
|
|
425
|
+
return undefined;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
404
428
|
}
|
|
405
429
|
exports.WhatsappResponse = WhatsappResponse;
|