meta-cloud-api 0.0.1-beta.0 → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/base.d.mts +12 -0
- package/dist/api/base.d.ts +12 -0
- package/dist/api/base.js +2 -0
- package/dist/api/base.js.map +1 -0
- package/dist/api/base.mjs +2 -0
- package/dist/api/base.mjs.map +1 -0
- package/dist/api/encryption.d.mts +15 -0
- package/dist/api/encryption.d.ts +15 -0
- package/dist/api/encryption.js +2 -0
- package/dist/api/encryption.js.map +1 -0
- package/dist/api/encryption.mjs +2 -0
- package/dist/api/encryption.mjs.map +1 -0
- package/dist/api/flow.d.mts +114 -0
- package/dist/api/flow.d.ts +114 -0
- package/dist/api/flow.js +2 -0
- package/dist/api/flow.js.map +1 -0
- package/dist/api/flow.mjs +2 -0
- package/dist/api/flow.mjs.map +1 -0
- package/dist/api/index.d.mts +25 -0
- package/dist/api/index.d.ts +25 -0
- package/dist/api/index.js +2 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/index.mjs +2 -0
- package/dist/api/index.mjs.map +1 -0
- package/dist/api/media.d.mts +17 -0
- package/dist/api/media.d.ts +17 -0
- package/dist/api/media.js +2 -0
- package/dist/api/media.js.map +1 -0
- package/dist/api/media.mjs +2 -0
- package/dist/api/media.mjs.map +1 -0
- package/dist/api/messages.d.mts +27 -0
- package/dist/api/messages.d.ts +27 -0
- package/dist/api/messages.js +2 -0
- package/dist/api/messages.js.map +1 -0
- package/dist/api/messages.mjs +2 -0
- package/dist/api/messages.mjs.map +1 -0
- package/dist/api/phoneNumber.d.mts +17 -0
- package/dist/api/phoneNumber.d.ts +17 -0
- package/dist/api/phoneNumber.js +2 -0
- package/dist/api/phoneNumber.js.map +1 -0
- package/dist/api/phoneNumber.mjs +2 -0
- package/dist/api/phoneNumber.mjs.map +1 -0
- package/dist/api/qrCode.d.mts +18 -0
- package/dist/api/qrCode.d.ts +18 -0
- package/dist/api/qrCode.js +2 -0
- package/dist/api/qrCode.js.map +1 -0
- package/dist/api/qrCode.mjs +2 -0
- package/dist/api/qrCode.mjs.map +1 -0
- package/dist/api/registration.d.mts +14 -0
- package/dist/api/registration.d.ts +14 -0
- package/dist/api/registration.js +2 -0
- package/dist/api/registration.js.map +1 -0
- package/dist/api/registration.mjs +2 -0
- package/dist/api/registration.mjs.map +1 -0
- package/dist/api/template.d.mts +18 -0
- package/dist/api/template.d.ts +18 -0
- package/dist/api/template.js +2 -0
- package/dist/api/template.js.map +1 -0
- package/dist/api/template.mjs +2 -0
- package/dist/api/template.mjs.map +1 -0
- package/dist/api/twoStepVerification.d.mts +13 -0
- package/dist/api/twoStepVerification.d.ts +13 -0
- package/dist/api/twoStepVerification.js +2 -0
- package/dist/api/twoStepVerification.js.map +1 -0
- package/dist/api/twoStepVerification.mjs +2 -0
- package/dist/api/twoStepVerification.mjs.map +1 -0
- package/dist/api/waba.d.mts +16 -0
- package/dist/api/waba.d.ts +16 -0
- package/dist/api/waba.js +2 -0
- package/dist/api/waba.js.map +1 -0
- package/dist/api/waba.mjs +2 -0
- package/dist/api/waba.mjs.map +1 -0
- package/dist/enums-D6WRUWH9.d.mts +585 -0
- package/dist/enums-D6WRUWH9.d.ts +585 -0
- package/dist/httpsClient.d.mts +22 -0
- package/dist/httpsClient.d.ts +22 -0
- package/dist/httpsClient.js +2 -0
- package/dist/httpsClient.js.map +1 -0
- package/dist/httpsClient.mjs +2 -0
- package/dist/httpsClient.mjs.map +1 -0
- package/dist/index.d.mts +35 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/dist/request.d.mts +22 -0
- package/dist/request.d.ts +22 -0
- package/dist/request.js +2 -0
- package/dist/request.js.map +1 -0
- package/dist/request.mjs +2 -0
- package/dist/request.mjs.map +1 -0
- package/dist/types/base.d.mts +8 -0
- package/dist/types/base.d.ts +8 -0
- package/dist/types/base.js +2 -0
- package/dist/types/base.js.map +1 -0
- package/dist/types/base.mjs +1 -0
- package/dist/types/base.mjs.map +1 -0
- package/dist/types/config.d.mts +59 -0
- package/dist/types/config.d.ts +59 -0
- package/dist/types/config.js +2 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/config.mjs +1 -0
- package/dist/types/config.mjs.map +1 -0
- package/dist/types/encryption.d.mts +13 -0
- package/dist/types/encryption.d.ts +13 -0
- package/dist/types/encryption.js +2 -0
- package/dist/types/encryption.js.map +1 -0
- package/dist/types/encryption.mjs +1 -0
- package/dist/types/encryption.mjs.map +1 -0
- package/dist/types/enums.d.mts +1 -0
- package/dist/types/enums.d.ts +1 -0
- package/dist/types/enums.js +2 -0
- package/dist/types/enums.js.map +1 -0
- package/dist/types/enums.mjs +2 -0
- package/dist/types/enums.mjs.map +1 -0
- package/dist/types/flow.d.mts +245 -0
- package/dist/types/flow.d.ts +245 -0
- package/dist/types/flow.js +2 -0
- package/dist/types/flow.js.map +1 -0
- package/dist/types/flow.mjs +2 -0
- package/dist/types/flow.mjs.map +1 -0
- package/dist/types/httpsClient.d.mts +19 -0
- package/dist/types/httpsClient.d.ts +19 -0
- package/dist/types/httpsClient.js +2 -0
- package/dist/types/httpsClient.js.map +1 -0
- package/dist/types/httpsClient.mjs +1 -0
- package/dist/types/httpsClient.mjs.map +1 -0
- package/dist/types/index.d.mts +16 -0
- package/dist/types/index.d.ts +16 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/index.mjs +2 -0
- package/dist/types/index.mjs.map +1 -0
- package/dist/types/logger.d.mts +9 -0
- package/dist/types/logger.d.ts +9 -0
- package/dist/types/logger.js +2 -0
- package/dist/types/logger.js.map +1 -0
- package/dist/types/logger.mjs +1 -0
- package/dist/types/logger.mjs.map +1 -0
- package/dist/types/media.d.mts +31 -0
- package/dist/types/media.d.ts +31 -0
- package/dist/types/media.js +2 -0
- package/dist/types/media.js.map +1 -0
- package/dist/types/media.mjs +1 -0
- package/dist/types/media.mjs.map +1 -0
- package/dist/types/messages.d.mts +322 -0
- package/dist/types/messages.d.ts +322 -0
- package/dist/types/messages.js +2 -0
- package/dist/types/messages.js.map +1 -0
- package/dist/types/messages.mjs +1 -0
- package/dist/types/messages.mjs.map +1 -0
- package/dist/types/phoneNumber.d.mts +82 -0
- package/dist/types/phoneNumber.d.ts +82 -0
- package/dist/types/phoneNumber.js +2 -0
- package/dist/types/phoneNumber.js.map +1 -0
- package/dist/types/phoneNumber.mjs +1 -0
- package/dist/types/phoneNumber.mjs.map +1 -0
- package/dist/types/qrCode.d.mts +27 -0
- package/dist/types/qrCode.d.ts +27 -0
- package/dist/types/qrCode.js +2 -0
- package/dist/types/qrCode.js.map +1 -0
- package/dist/types/qrCode.mjs +1 -0
- package/dist/types/qrCode.mjs.map +1 -0
- package/dist/types/registration.d.mts +14 -0
- package/dist/types/registration.d.ts +14 -0
- package/dist/types/registration.js +2 -0
- package/dist/types/registration.js.map +1 -0
- package/dist/types/registration.mjs +1 -0
- package/dist/types/registration.mjs.map +1 -0
- package/dist/types/request.d.mts +47 -0
- package/dist/types/request.d.ts +47 -0
- package/dist/types/request.js +2 -0
- package/dist/types/request.js.map +1 -0
- package/dist/types/request.mjs +1 -0
- package/dist/types/request.mjs.map +1 -0
- package/dist/types/template.d.mts +106 -0
- package/dist/types/template.d.ts +106 -0
- package/dist/types/template.js +2 -0
- package/dist/types/template.js.map +1 -0
- package/dist/types/template.mjs +1 -0
- package/dist/types/template.mjs.map +1 -0
- package/dist/types/twoStepVerification.d.mts +11 -0
- package/dist/types/twoStepVerification.d.ts +11 -0
- package/dist/types/twoStepVerification.js +2 -0
- package/dist/types/twoStepVerification.js.map +1 -0
- package/dist/types/twoStepVerification.mjs +1 -0
- package/dist/types/twoStepVerification.mjs.map +1 -0
- package/dist/types/waba.d.mts +19 -0
- package/dist/types/waba.d.ts +19 -0
- package/dist/types/waba.js +2 -0
- package/dist/types/waba.js.map +1 -0
- package/dist/types/waba.mjs +1 -0
- package/dist/types/waba.mjs.map +1 -0
- package/dist/types/whatsapp.d.mts +31 -0
- package/dist/types/whatsapp.d.ts +31 -0
- package/dist/types/whatsapp.js +2 -0
- package/dist/types/whatsapp.js.map +1 -0
- package/dist/types/whatsapp.mjs +1 -0
- package/dist/types/whatsapp.mjs.map +1 -0
- package/dist/utils/generateXHub256Sig.d.mts +3 -0
- package/dist/utils/generateXHub256Sig.d.ts +3 -0
- package/dist/utils/generateXHub256Sig.js +2 -0
- package/dist/utils/generateXHub256Sig.js.map +1 -0
- package/dist/utils/generateXHub256Sig.mjs +2 -0
- package/dist/utils/generateXHub256Sig.mjs.map +1 -0
- package/dist/utils/importConfig.d.mts +7 -0
- package/dist/utils/importConfig.d.ts +7 -0
- package/dist/utils/importConfig.js +2 -0
- package/dist/utils/importConfig.js.map +1 -0
- package/dist/utils/importConfig.mjs +2 -0
- package/dist/utils/importConfig.mjs.map +1 -0
- package/dist/utils/index.d.mts +5 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/index.mjs +2 -0
- package/dist/utils/index.mjs.map +1 -0
- package/dist/utils/isMetaError.d.mts +21 -0
- package/dist/utils/isMetaError.d.ts +21 -0
- package/dist/utils/isMetaError.js +2 -0
- package/dist/utils/isMetaError.js.map +1 -0
- package/dist/utils/isMetaError.mjs +2 -0
- package/dist/utils/isMetaError.mjs.map +1 -0
- package/dist/utils/logger.d.mts +13 -0
- package/dist/utils/logger.d.ts +13 -0
- package/dist/utils/logger.js +2 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/logger.mjs +2 -0
- package/dist/utils/logger.mjs.map +1 -0
- package/dist/utils/objectToQueryString.d.mts +3 -0
- package/dist/utils/objectToQueryString.d.ts +3 -0
- package/dist/utils/objectToQueryString.js +2 -0
- package/dist/utils/objectToQueryString.js.map +1 -0
- package/dist/utils/objectToQueryString.mjs +2 -0
- package/dist/utils/objectToQueryString.mjs.map +1 -0
- package/dist/whatsapp.d.mts +54 -0
- package/dist/whatsapp.d.ts +54 -0
- package/dist/whatsapp.js +2 -0
- package/dist/whatsapp.js.map +1 -0
- package/dist/whatsapp.mjs +2 -0
- package/dist/whatsapp.mjs.map +1 -0
- package/package.json +51 -7
- package/src/api/base.ts +19 -0
- package/src/api/encryption.ts +34 -0
- package/src/api/flow.ts +253 -0
- package/src/api/index.ts +24 -0
- package/src/api/media.ts +52 -0
- package/src/api/messages.ts +160 -0
- package/src/api/phoneNumber.ts +59 -0
- package/src/api/qrCode.ts +64 -0
- package/src/api/registration.ts +38 -0
- package/src/api/template.ts +70 -0
- package/src/api/twoStepVerification.ts +24 -0
- package/src/api/waba.ts +55 -0
- package/src/httpsClient.ts +83 -0
- package/src/index.ts +3 -0
- package/src/request.ts +104 -0
- package/src/types/base.ts +5 -0
- package/src/types/config.ts +68 -0
- package/src/types/encryption.ts +11 -0
- package/src/types/enums.ts +563 -0
- package/src/types/flow.ts +274 -0
- package/src/types/httpsClient.ts +28 -0
- package/src/types/index.ts +16 -0
- package/src/types/logger.ts +7 -0
- package/src/types/media.ts +31 -0
- package/src/types/messages.ts +453 -0
- package/src/types/phoneNumber.ts +111 -0
- package/src/types/qrCode.ts +30 -0
- package/src/types/registration.ts +17 -0
- package/src/types/request.ts +66 -0
- package/src/types/template.ts +134 -0
- package/src/types/twoStepVerification.ts +9 -0
- package/src/types/waba.ts +18 -0
- package/src/types/whatsapp.ts +31 -0
- package/src/utils/.gitkeep +0 -0
- package/src/utils/generateXHub256Sig.ts +5 -0
- package/src/utils/importConfig.ts +55 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/isMetaError.ts +44 -0
- package/src/utils/logger.ts +46 -0
- package/src/utils/objectToQueryString.ts +16 -0
- package/src/whatsapp.ts +96 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { HttpMethodsEnum, WabaConfigEnum } from '../types/enums';
|
|
2
|
+
import type { WabaConfigType } from '../types/config';
|
|
3
|
+
import type { RequesterClass, RequesterResponseInterface, ResponseSuccess } from '../types/request';
|
|
4
|
+
import BaseAPI from './base';
|
|
5
|
+
import type { EncryptionClass, EncryptionPublicKeyResponse } from '../types/encryption';
|
|
6
|
+
|
|
7
|
+
export default class EncryptionAPI extends BaseAPI implements EncryptionClass {
|
|
8
|
+
private readonly endpoint = 'whatsapp_business_encryption';
|
|
9
|
+
|
|
10
|
+
constructor(config: WabaConfigType, client: RequesterClass) {
|
|
11
|
+
super(config, client);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async getEncryptionPublicKey(): Promise<RequesterResponseInterface<EncryptionPublicKeyResponse>> {
|
|
15
|
+
return this.client.sendRequest(
|
|
16
|
+
HttpMethodsEnum.Get,
|
|
17
|
+
`${this.config[WabaConfigEnum.PhoneNumberId]}/${this.endpoint}`,
|
|
18
|
+
this.config[WabaConfigEnum.RequestTimeout],
|
|
19
|
+
null,
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async setEncryptionPublicKey(businessPublicKey: string): Promise<RequesterResponseInterface<ResponseSuccess>> {
|
|
24
|
+
const formData = new FormData();
|
|
25
|
+
formData.append('business_public_key', businessPublicKey);
|
|
26
|
+
|
|
27
|
+
return this.client.sendRequest(
|
|
28
|
+
HttpMethodsEnum.Post,
|
|
29
|
+
`${this.config[WabaConfigEnum.PhoneNumberId]}/${this.endpoint}`,
|
|
30
|
+
this.config[WabaConfigEnum.RequestTimeout],
|
|
31
|
+
formData,
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
}
|
package/src/api/flow.ts
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import BaseAPI from './base';
|
|
2
|
+
import { WabaConfigType } from '../types/config';
|
|
3
|
+
import { HttpMethodsEnum, WabaConfigEnum } from '../types/enums';
|
|
4
|
+
import { RequesterClass, RequesterResponseInterface, ResponseSuccess } from '../types/request';
|
|
5
|
+
import {
|
|
6
|
+
FlowClass,
|
|
7
|
+
FlowsListResponse,
|
|
8
|
+
FlowCategoryEnum,
|
|
9
|
+
Flow,
|
|
10
|
+
FlowPreviewResponse,
|
|
11
|
+
FlowAssetsResponse,
|
|
12
|
+
FlowValidationError,
|
|
13
|
+
FlowMigrationResponse,
|
|
14
|
+
} from '../types/flow';
|
|
15
|
+
import Logger from '../utils/logger';
|
|
16
|
+
|
|
17
|
+
const LIB_NAME = 'FlowAPI';
|
|
18
|
+
const LOG_LOCAL = false;
|
|
19
|
+
const LOGGER = new Logger(LIB_NAME, process.env.DEBUG === 'true' || LOG_LOCAL);
|
|
20
|
+
|
|
21
|
+
export default class FlowAPI extends BaseAPI implements FlowClass {
|
|
22
|
+
constructor(config: WabaConfigType, client: RequesterClass) {
|
|
23
|
+
super(config, client);
|
|
24
|
+
LOGGER.log('FlowAPI initialized');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* List Flows
|
|
29
|
+
*
|
|
30
|
+
* @param wabaId - The WABA ID
|
|
31
|
+
* @returns Promise with the list of flows
|
|
32
|
+
*/
|
|
33
|
+
async listFlows(wabaId: string): Promise<RequesterResponseInterface<FlowsListResponse>> {
|
|
34
|
+
return this.client.sendRequest(
|
|
35
|
+
HttpMethodsEnum.Get,
|
|
36
|
+
`/${wabaId}/flows`,
|
|
37
|
+
this.config[WabaConfigEnum.RequestTimeout],
|
|
38
|
+
null,
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Create Flow
|
|
44
|
+
*
|
|
45
|
+
* @param wabaId - The WABA ID
|
|
46
|
+
* @param data - The flow data including name, categories, endpoint_uri, and optional clone_flow_id
|
|
47
|
+
* @returns Promise with the created flow ID
|
|
48
|
+
*/
|
|
49
|
+
async createFlow(
|
|
50
|
+
wabaId: string,
|
|
51
|
+
data: {
|
|
52
|
+
name: string;
|
|
53
|
+
categories?: FlowCategoryEnum[];
|
|
54
|
+
endpoint_uri?: string;
|
|
55
|
+
clone_flow_id?: string;
|
|
56
|
+
flow_json?: string;
|
|
57
|
+
publish?: boolean;
|
|
58
|
+
},
|
|
59
|
+
): Promise<
|
|
60
|
+
RequesterResponseInterface<{ id: string; success: boolean; validation_errors?: FlowValidationError[] }>
|
|
61
|
+
> {
|
|
62
|
+
const formData = new FormData();
|
|
63
|
+
|
|
64
|
+
if (data.name) formData.append('name', data.name);
|
|
65
|
+
if (data.categories) formData.append('categories', JSON.stringify(data.categories));
|
|
66
|
+
if (data.endpoint_uri) formData.append('endpoint_uri', data.endpoint_uri);
|
|
67
|
+
if (data.clone_flow_id) formData.append('clone_flow_id', data.clone_flow_id);
|
|
68
|
+
if (data.flow_json) formData.append('flow_json', data.flow_json);
|
|
69
|
+
if (data.publish !== undefined) formData.append('publish', String(data.publish));
|
|
70
|
+
|
|
71
|
+
return this.client.sendRequest(
|
|
72
|
+
HttpMethodsEnum.Post,
|
|
73
|
+
`/${wabaId}/flows`,
|
|
74
|
+
this.config[WabaConfigEnum.RequestTimeout],
|
|
75
|
+
formData,
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Get Flow
|
|
81
|
+
*
|
|
82
|
+
* @param flowId - The flow ID
|
|
83
|
+
* @param fields - Optional fields to return
|
|
84
|
+
* @param dateFormat - Optional date format
|
|
85
|
+
* @returns Promise with the flow details
|
|
86
|
+
*/
|
|
87
|
+
async getFlow(
|
|
88
|
+
flowId: string,
|
|
89
|
+
fields?: string,
|
|
90
|
+
dateFormat?: string,
|
|
91
|
+
): Promise<RequesterResponseInterface<Flow | FlowPreviewResponse>> {
|
|
92
|
+
const params = new URLSearchParams();
|
|
93
|
+
if (fields) params.append('fields', fields);
|
|
94
|
+
if (dateFormat) params.append('date_format', dateFormat);
|
|
95
|
+
|
|
96
|
+
const queryString = params.toString() ? `?${params.toString()}` : '';
|
|
97
|
+
return this.client.sendRequest(
|
|
98
|
+
HttpMethodsEnum.Get,
|
|
99
|
+
`/${flowId}${queryString}`,
|
|
100
|
+
this.config[WabaConfigEnum.RequestTimeout],
|
|
101
|
+
null,
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Update Flow Metadata
|
|
107
|
+
*
|
|
108
|
+
* @param flowId - The flow ID
|
|
109
|
+
* @param data - The flow metadata to update
|
|
110
|
+
* @returns Promise with the success status
|
|
111
|
+
*/
|
|
112
|
+
async updateFlowMetadata(
|
|
113
|
+
flowId: string,
|
|
114
|
+
data: {
|
|
115
|
+
name?: string;
|
|
116
|
+
categories?: FlowCategoryEnum[];
|
|
117
|
+
endpoint_uri?: string;
|
|
118
|
+
application_id?: string;
|
|
119
|
+
},
|
|
120
|
+
): Promise<RequesterResponseInterface<ResponseSuccess>> {
|
|
121
|
+
const formData = new FormData();
|
|
122
|
+
|
|
123
|
+
if (data.name) formData.append('name', data.name);
|
|
124
|
+
if (data.categories) formData.append('categories', JSON.stringify(data.categories));
|
|
125
|
+
if (data.endpoint_uri) formData.append('endpoint_uri', data.endpoint_uri);
|
|
126
|
+
if (data.application_id) formData.append('application_id', data.application_id);
|
|
127
|
+
|
|
128
|
+
return this.client.sendRequest(
|
|
129
|
+
HttpMethodsEnum.Post,
|
|
130
|
+
`/${flowId}`,
|
|
131
|
+
this.config[WabaConfigEnum.RequestTimeout],
|
|
132
|
+
formData,
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Delete Flow
|
|
138
|
+
*
|
|
139
|
+
* @param flowId - The flow ID
|
|
140
|
+
* @returns Promise with the success status
|
|
141
|
+
*/
|
|
142
|
+
async deleteFlow(flowId: string): Promise<RequesterResponseInterface<ResponseSuccess>> {
|
|
143
|
+
return this.client.sendRequest(
|
|
144
|
+
HttpMethodsEnum.Delete,
|
|
145
|
+
`/${flowId}`,
|
|
146
|
+
this.config[WabaConfigEnum.RequestTimeout],
|
|
147
|
+
null,
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* List Assets (Get Flow JSON URL)
|
|
153
|
+
*
|
|
154
|
+
* @param flowId - The flow ID
|
|
155
|
+
* @returns Promise with the list of assets
|
|
156
|
+
*/
|
|
157
|
+
async listAssets(flowId: string): Promise<RequesterResponseInterface<FlowAssetsResponse>> {
|
|
158
|
+
return this.client.sendRequest(
|
|
159
|
+
HttpMethodsEnum.Get,
|
|
160
|
+
`/${flowId}/assets`,
|
|
161
|
+
this.config[WabaConfigEnum.RequestTimeout],
|
|
162
|
+
null,
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Update Flow JSON
|
|
168
|
+
*
|
|
169
|
+
* @param flowId - The flow ID
|
|
170
|
+
* @param data - The asset data including asset_type, file, and name
|
|
171
|
+
* @returns Promise with the success status and validation errors
|
|
172
|
+
*/
|
|
173
|
+
async updateFlowJson(
|
|
174
|
+
flowId: string,
|
|
175
|
+
data: {
|
|
176
|
+
asset_type: 'FLOW_JSON';
|
|
177
|
+
file: Blob;
|
|
178
|
+
name: string;
|
|
179
|
+
},
|
|
180
|
+
): Promise<RequesterResponseInterface<{ success: boolean; validation_errors?: FlowValidationError[] }>> {
|
|
181
|
+
const formData = new FormData();
|
|
182
|
+
|
|
183
|
+
formData.append('asset_type', data.asset_type);
|
|
184
|
+
formData.append('file', data.file);
|
|
185
|
+
formData.append('name', data.name);
|
|
186
|
+
|
|
187
|
+
return this.client.sendRequest(
|
|
188
|
+
HttpMethodsEnum.Post,
|
|
189
|
+
`/${flowId}/assets`,
|
|
190
|
+
this.config[WabaConfigEnum.RequestTimeout],
|
|
191
|
+
formData,
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Publish Flow
|
|
197
|
+
*
|
|
198
|
+
* @param flowId - The flow ID
|
|
199
|
+
* @returns Promise with the success status
|
|
200
|
+
*/
|
|
201
|
+
async publishFlow(flowId: string): Promise<RequesterResponseInterface<ResponseSuccess>> {
|
|
202
|
+
return this.client.sendRequest(
|
|
203
|
+
HttpMethodsEnum.Post,
|
|
204
|
+
`/${flowId}/publish`,
|
|
205
|
+
this.config[WabaConfigEnum.RequestTimeout],
|
|
206
|
+
JSON.stringify({}),
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Deprecate Flow
|
|
212
|
+
*
|
|
213
|
+
* @param flowId - The flow ID
|
|
214
|
+
* @returns Promise with the success status
|
|
215
|
+
*/
|
|
216
|
+
async deprecateFlow(flowId: string): Promise<RequesterResponseInterface<ResponseSuccess>> {
|
|
217
|
+
return this.client.sendRequest(
|
|
218
|
+
HttpMethodsEnum.Post,
|
|
219
|
+
`/${flowId}/deprecate`,
|
|
220
|
+
this.config[WabaConfigEnum.RequestTimeout],
|
|
221
|
+
JSON.stringify({}),
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Migrate Flows
|
|
227
|
+
*
|
|
228
|
+
* @param wabaId - The destination WABA ID
|
|
229
|
+
* @param data - The migration data including source_waba_id and optional source_flow_names
|
|
230
|
+
* @returns Promise with migration results
|
|
231
|
+
*/
|
|
232
|
+
async migrateFlows(
|
|
233
|
+
wabaId: string,
|
|
234
|
+
data: {
|
|
235
|
+
source_waba_id: string;
|
|
236
|
+
source_flow_names?: string[];
|
|
237
|
+
},
|
|
238
|
+
): Promise<RequesterResponseInterface<FlowMigrationResponse>> {
|
|
239
|
+
const formData = new FormData();
|
|
240
|
+
|
|
241
|
+
formData.append('source_waba_id', data.source_waba_id);
|
|
242
|
+
if (data.source_flow_names) {
|
|
243
|
+
formData.append('source_flow_names', JSON.stringify(data.source_flow_names));
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
return this.client.sendRequest(
|
|
247
|
+
HttpMethodsEnum.Post,
|
|
248
|
+
`/${wabaId}/migrate_flows`,
|
|
249
|
+
this.config[WabaConfigEnum.RequestTimeout],
|
|
250
|
+
formData,
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
}
|
package/src/api/index.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import MessagesAPI from './messages';
|
|
2
|
+
import BaseAPI from './base';
|
|
3
|
+
import PhoneNumberAPI from './phoneNumber';
|
|
4
|
+
import TemplateAPI from './template';
|
|
5
|
+
import RegistrationAPI from './registration';
|
|
6
|
+
import TwoStepVerificationAPI from './twoStepVerification';
|
|
7
|
+
import QrCodeAPI from './qrCode';
|
|
8
|
+
import EncryptionAPI from './encryption';
|
|
9
|
+
import WabaAPI from './waba';
|
|
10
|
+
import MediaAPI from './media';
|
|
11
|
+
import FlowAPI from './flow';
|
|
12
|
+
export {
|
|
13
|
+
MessagesAPI,
|
|
14
|
+
BaseAPI,
|
|
15
|
+
PhoneNumberAPI,
|
|
16
|
+
TemplateAPI,
|
|
17
|
+
RegistrationAPI,
|
|
18
|
+
TwoStepVerificationAPI,
|
|
19
|
+
QrCodeAPI,
|
|
20
|
+
EncryptionAPI,
|
|
21
|
+
WabaAPI,
|
|
22
|
+
MediaAPI,
|
|
23
|
+
FlowAPI,
|
|
24
|
+
};
|
package/src/api/media.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { HttpMethodsEnum, WabaConfigEnum } from '../types/enums';
|
|
2
|
+
import type { RequesterClass, RequesterResponseInterface, ResponseSuccess } from '../types/request';
|
|
3
|
+
import type { WabaConfigType } from '../types/config';
|
|
4
|
+
import type { MediaClass, MediaResponse, MediasResponse, UploadMediaResponse } from '../types/media';
|
|
5
|
+
import BaseAPI from './base';
|
|
6
|
+
|
|
7
|
+
export default class MediaAPI extends BaseAPI implements MediaClass {
|
|
8
|
+
private readonly endpoint = 'media';
|
|
9
|
+
|
|
10
|
+
constructor(config: WabaConfigType, client: RequesterClass) {
|
|
11
|
+
super(config, client);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async getMediaById(mediaId: string): Promise<RequesterResponseInterface<MediaResponse>> {
|
|
15
|
+
return this.client.sendRequest(
|
|
16
|
+
HttpMethodsEnum.Get,
|
|
17
|
+
`${mediaId}`,
|
|
18
|
+
this.config[WabaConfigEnum.RequestTimeout],
|
|
19
|
+
null,
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async uploadMedia(
|
|
24
|
+
file: File,
|
|
25
|
+
messagingProduct: string = 'whatsapp',
|
|
26
|
+
): Promise<RequesterResponseInterface<UploadMediaResponse>> {
|
|
27
|
+
const formData = new FormData();
|
|
28
|
+
formData.append('file', file);
|
|
29
|
+
formData.append('messaging_product', messagingProduct);
|
|
30
|
+
formData.append('type', file.type);
|
|
31
|
+
|
|
32
|
+
return this.client.sendRequest(
|
|
33
|
+
HttpMethodsEnum.Post,
|
|
34
|
+
`${this.config[WabaConfigEnum.PhoneNumberId]}/${this.endpoint}`,
|
|
35
|
+
this.config[WabaConfigEnum.RequestTimeout],
|
|
36
|
+
formData,
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async deleteMedia(mediaId: string): Promise<RequesterResponseInterface<ResponseSuccess>> {
|
|
41
|
+
return this.client.sendRequest(
|
|
42
|
+
HttpMethodsEnum.Delete,
|
|
43
|
+
`${mediaId}`,
|
|
44
|
+
this.config[WabaConfigEnum.RequestTimeout],
|
|
45
|
+
null,
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async downloadMedia(mediaUrl: string): Promise<RequesterResponseInterface<Blob>> {
|
|
50
|
+
return this.client.sendRequest(HttpMethodsEnum.Get, mediaUrl, this.config[WabaConfigEnum.RequestTimeout], null);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import type { WabaConfigType } from '../types/config';
|
|
2
|
+
import { ComponentTypesEnum, HttpMethodsEnum, MessageTypesEnum, WabaConfigEnum } from '../types/enums';
|
|
3
|
+
|
|
4
|
+
import * as m from '../types/messages';
|
|
5
|
+
import type { RequesterClass, RequesterResponseInterface } from '../types/request';
|
|
6
|
+
import BaseAPI from './base';
|
|
7
|
+
|
|
8
|
+
export default class MessagesApi extends BaseAPI implements m.MessagesClass {
|
|
9
|
+
private readonly commonMethod = HttpMethodsEnum.Post;
|
|
10
|
+
private readonly commonEndpoint = 'messages';
|
|
11
|
+
|
|
12
|
+
constructor(config: WabaConfigType, client: RequesterClass) {
|
|
13
|
+
super(config, client);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
bodyBuilder<T extends MessageTypesEnum, C extends ComponentTypesEnum>(
|
|
17
|
+
type: T,
|
|
18
|
+
payload:
|
|
19
|
+
| m.AudioMediaObject
|
|
20
|
+
| [m.ContactObject]
|
|
21
|
+
| m.DocumentMediaObject
|
|
22
|
+
| m.ImageMediaObject
|
|
23
|
+
| m.InteractiveObject
|
|
24
|
+
| m.LocationObject
|
|
25
|
+
| m.MessageTemplateObject<C>
|
|
26
|
+
| m.StickerMediaObject
|
|
27
|
+
| m.TextObject
|
|
28
|
+
| m.VideoMediaObject,
|
|
29
|
+
toNumber: string,
|
|
30
|
+
replyMessageId?: string,
|
|
31
|
+
) {
|
|
32
|
+
const body: m.MessageRequestBody<T> = {
|
|
33
|
+
messaging_product: 'whatsapp',
|
|
34
|
+
recipient_type: 'individual',
|
|
35
|
+
to: toNumber,
|
|
36
|
+
type: type,
|
|
37
|
+
[type]: payload,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
if (replyMessageId) body['context'] = { message_id: replyMessageId };
|
|
41
|
+
|
|
42
|
+
return body;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
private send(body: BodyInit | null): Promise<RequesterResponseInterface<m.MessagesResponse>> {
|
|
46
|
+
return this.client.sendRequest(
|
|
47
|
+
this.commonMethod,
|
|
48
|
+
`${this.config[WabaConfigEnum.PhoneNumberId]}/${this.commonEndpoint}`,
|
|
49
|
+
this.config[WabaConfigEnum.RequestTimeout],
|
|
50
|
+
body,
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async audio(
|
|
55
|
+
body: m.AudioMediaObject,
|
|
56
|
+
recipient: number,
|
|
57
|
+
replyMessageId?: string,
|
|
58
|
+
): Promise<RequesterResponseInterface<m.MessagesResponse>> {
|
|
59
|
+
return this.send(
|
|
60
|
+
JSON.stringify(this.bodyBuilder(MessageTypesEnum.Audio, body, recipient.toString(), replyMessageId)),
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async contacts(
|
|
65
|
+
body: [m.ContactObject],
|
|
66
|
+
recipient: number,
|
|
67
|
+
replyMessageId?: string,
|
|
68
|
+
): Promise<RequesterResponseInterface<m.MessagesResponse>> {
|
|
69
|
+
return this.send(
|
|
70
|
+
JSON.stringify(this.bodyBuilder(MessageTypesEnum.Contacts, body, recipient.toString(), replyMessageId)),
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async document(
|
|
75
|
+
body: m.DocumentMediaObject,
|
|
76
|
+
recipient: number,
|
|
77
|
+
replyMessageId?: string,
|
|
78
|
+
): Promise<RequesterResponseInterface<m.MessagesResponse>> {
|
|
79
|
+
return this.send(
|
|
80
|
+
JSON.stringify(this.bodyBuilder(MessageTypesEnum.Document, body, recipient.toString(), replyMessageId)),
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async image(
|
|
85
|
+
body: m.ImageMediaObject,
|
|
86
|
+
recipient: number,
|
|
87
|
+
replyMessageId?: string,
|
|
88
|
+
): Promise<RequesterResponseInterface<m.MessagesResponse>> {
|
|
89
|
+
return this.send(
|
|
90
|
+
JSON.stringify(this.bodyBuilder(MessageTypesEnum.Image, body, recipient.toString(), replyMessageId)),
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async interactive(
|
|
95
|
+
body: m.InteractiveObject,
|
|
96
|
+
recipient: number,
|
|
97
|
+
replyMessageId?: string,
|
|
98
|
+
): Promise<RequesterResponseInterface<m.MessagesResponse>> {
|
|
99
|
+
return this.send(
|
|
100
|
+
JSON.stringify(this.bodyBuilder(MessageTypesEnum.Interactive, body, recipient.toString(), replyMessageId)),
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async location(
|
|
105
|
+
body: m.LocationObject,
|
|
106
|
+
recipient: number,
|
|
107
|
+
replyMessageId?: string,
|
|
108
|
+
): Promise<RequesterResponseInterface<m.MessagesResponse>> {
|
|
109
|
+
return this.send(
|
|
110
|
+
JSON.stringify(this.bodyBuilder(MessageTypesEnum.Location, body, recipient.toString(), replyMessageId)),
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async sticker(
|
|
115
|
+
body: m.StickerMediaObject,
|
|
116
|
+
recipient: number,
|
|
117
|
+
replyMessageId?: string,
|
|
118
|
+
): Promise<RequesterResponseInterface<m.MessagesResponse>> {
|
|
119
|
+
return this.send(
|
|
120
|
+
JSON.stringify(this.bodyBuilder(MessageTypesEnum.Sticker, body, recipient.toString(), replyMessageId)),
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
async template(
|
|
125
|
+
body: m.MessageTemplateObject<ComponentTypesEnum>,
|
|
126
|
+
recipient: number,
|
|
127
|
+
replyMessageId?: string,
|
|
128
|
+
): Promise<RequesterResponseInterface<m.MessagesResponse>> {
|
|
129
|
+
return this.send(
|
|
130
|
+
JSON.stringify(this.bodyBuilder(MessageTypesEnum.Template, body, recipient.toString(), replyMessageId)),
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
async text(
|
|
135
|
+
body: m.TextObject,
|
|
136
|
+
recipient: number,
|
|
137
|
+
replyMessageId?: string,
|
|
138
|
+
): Promise<RequesterResponseInterface<m.MessagesResponse>> {
|
|
139
|
+
return this.send(
|
|
140
|
+
JSON.stringify(this.bodyBuilder(MessageTypesEnum.Text, body, recipient.toString(), replyMessageId)),
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
async video(
|
|
145
|
+
body: m.VideoMediaObject,
|
|
146
|
+
recipient: number,
|
|
147
|
+
replyMessageId?: string,
|
|
148
|
+
): Promise<RequesterResponseInterface<m.MessagesResponse>> {
|
|
149
|
+
return this.send(
|
|
150
|
+
JSON.stringify(this.bodyBuilder(MessageTypesEnum.Video, body, recipient.toString(), replyMessageId)),
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
async status(body: m.StatusObject): Promise<RequesterResponseInterface<m.MessagesResponse>> {
|
|
155
|
+
const mp: m.GeneralMessageBody = { messaging_product: 'whatsapp' };
|
|
156
|
+
const bodyToSend: m.StatusRequestBody = Object.assign(mp, body);
|
|
157
|
+
|
|
158
|
+
return this.send(JSON.stringify(bodyToSend));
|
|
159
|
+
}
|
|
160
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PhoneNumberClass,
|
|
3
|
+
PhoneNumberResponse,
|
|
4
|
+
PhoneNumbersResponse,
|
|
5
|
+
RequestVerificationCodeRequest,
|
|
6
|
+
VerifyCodeRequest,
|
|
7
|
+
} from 'src/types/phoneNumber';
|
|
8
|
+
import { objectToQueryString } from 'src/utils/objectToQueryString';
|
|
9
|
+
import type { WabaConfigType } from '../types/config';
|
|
10
|
+
import { HttpMethodsEnum, WabaConfigEnum } from '../types/enums';
|
|
11
|
+
import type { RequesterClass, RequesterResponseInterface, ResponseSuccess } from '../types/request';
|
|
12
|
+
import BaseAPI from './base';
|
|
13
|
+
|
|
14
|
+
export default class PhoneNumberApi extends BaseAPI implements PhoneNumberClass {
|
|
15
|
+
private readonly endpoint = 'phone_numbers';
|
|
16
|
+
|
|
17
|
+
constructor(config: WabaConfigType, client: RequesterClass) {
|
|
18
|
+
super(config, client);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async getPhoneNumberById(fields?: string): Promise<RequesterResponseInterface<PhoneNumberResponse>> {
|
|
22
|
+
const queryParams = fields ? objectToQueryString({ fields }) : '';
|
|
23
|
+
return this.client.sendRequest(
|
|
24
|
+
HttpMethodsEnum.Get,
|
|
25
|
+
`${this.config[WabaConfigEnum.PhoneNumberId]}${queryParams}`,
|
|
26
|
+
this.config[WabaConfigEnum.RequestTimeout],
|
|
27
|
+
null,
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async getPhoneNumbers(): Promise<RequesterResponseInterface<PhoneNumbersResponse>> {
|
|
32
|
+
return this.client.sendRequest(
|
|
33
|
+
HttpMethodsEnum.Get,
|
|
34
|
+
`${this.config[WabaConfigEnum.BusinessAcctId]}/${this.endpoint}`,
|
|
35
|
+
this.config[WabaConfigEnum.RequestTimeout],
|
|
36
|
+
null,
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async requestVerificationCode(
|
|
41
|
+
requestVerificationCodeRequest: RequestVerificationCodeRequest,
|
|
42
|
+
): Promise<RequesterResponseInterface<ResponseSuccess>> {
|
|
43
|
+
return this.client.sendRequest(
|
|
44
|
+
HttpMethodsEnum.Post,
|
|
45
|
+
`${this.config[WabaConfigEnum.PhoneNumberId]}/request_code`,
|
|
46
|
+
this.config[WabaConfigEnum.RequestTimeout],
|
|
47
|
+
JSON.stringify(requestVerificationCodeRequest),
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async verifyCode(verifyCodeRequest: VerifyCodeRequest): Promise<RequesterResponseInterface<ResponseSuccess>> {
|
|
52
|
+
return this.client.sendRequest(
|
|
53
|
+
HttpMethodsEnum.Post,
|
|
54
|
+
`${this.config[WabaConfigEnum.PhoneNumberId]}/verify_code`,
|
|
55
|
+
this.config[WabaConfigEnum.RequestTimeout],
|
|
56
|
+
JSON.stringify(verifyCodeRequest),
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { HttpMethodsEnum, WabaConfigEnum } from '../types/enums';
|
|
2
|
+
import type { WabaConfigType } from '../types/config';
|
|
3
|
+
import type { RequesterClass, RequesterResponseInterface, ResponseSuccess } from '../types/request';
|
|
4
|
+
import BaseAPI from './base';
|
|
5
|
+
import {
|
|
6
|
+
CreateQrCodeRequest,
|
|
7
|
+
QrCodeClass,
|
|
8
|
+
QrCodeResponse,
|
|
9
|
+
QrCodesResponse,
|
|
10
|
+
UpdateQrCodeRequest,
|
|
11
|
+
} from '../types/qrCode';
|
|
12
|
+
|
|
13
|
+
export default class QrCodeAPI extends BaseAPI implements QrCodeClass {
|
|
14
|
+
private readonly endpoint = 'message_qrdls';
|
|
15
|
+
|
|
16
|
+
constructor(config: WabaConfigType, client: RequesterClass) {
|
|
17
|
+
super(config, client);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async createQrCode(request: CreateQrCodeRequest): Promise<RequesterResponseInterface<QrCodeResponse>> {
|
|
21
|
+
return this.client.sendRequest(
|
|
22
|
+
HttpMethodsEnum.Post,
|
|
23
|
+
`${this.config[WabaConfigEnum.PhoneNumberId]}/${this.endpoint}`,
|
|
24
|
+
this.config[WabaConfigEnum.RequestTimeout],
|
|
25
|
+
JSON.stringify(request),
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async getQrCodes(): Promise<RequesterResponseInterface<QrCodesResponse>> {
|
|
30
|
+
return this.client.sendRequest(
|
|
31
|
+
HttpMethodsEnum.Get,
|
|
32
|
+
`${this.config[WabaConfigEnum.PhoneNumberId]}/${this.endpoint}`,
|
|
33
|
+
this.config[WabaConfigEnum.RequestTimeout],
|
|
34
|
+
null,
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async getQrCode(qrCodeId: string): Promise<RequesterResponseInterface<QrCodeResponse>> {
|
|
39
|
+
return this.client.sendRequest(
|
|
40
|
+
HttpMethodsEnum.Get,
|
|
41
|
+
`${this.config[WabaConfigEnum.PhoneNumberId]}/${this.endpoint}/${qrCodeId}`,
|
|
42
|
+
this.config[WabaConfigEnum.RequestTimeout],
|
|
43
|
+
null,
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async updateQrCode(request: UpdateQrCodeRequest): Promise<RequesterResponseInterface<QrCodeResponse>> {
|
|
48
|
+
return this.client.sendRequest(
|
|
49
|
+
HttpMethodsEnum.Post,
|
|
50
|
+
`${this.config[WabaConfigEnum.PhoneNumberId]}/${this.endpoint}`,
|
|
51
|
+
this.config[WabaConfigEnum.RequestTimeout],
|
|
52
|
+
JSON.stringify(request),
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async deleteQrCode(qrCodeId: string): Promise<RequesterResponseInterface<ResponseSuccess>> {
|
|
57
|
+
return this.client.sendRequest(
|
|
58
|
+
HttpMethodsEnum.Delete,
|
|
59
|
+
`${this.config[WabaConfigEnum.PhoneNumberId]}/${this.endpoint}/${qrCodeId}`,
|
|
60
|
+
this.config[WabaConfigEnum.RequestTimeout],
|
|
61
|
+
null,
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { RegistrationClass } from '../types/registration';
|
|
2
|
+
import type { WabaConfigType } from '../types/config';
|
|
3
|
+
import { HttpMethodsEnum, WabaConfigEnum, DataLocalizationRegionEnum } from '../types/enums';
|
|
4
|
+
import type { RequesterClass, RequesterResponseInterface, ResponseSuccess } from '../types/request';
|
|
5
|
+
import BaseAPI from './base';
|
|
6
|
+
|
|
7
|
+
export default class RegistrationAPI extends BaseAPI implements RegistrationClass {
|
|
8
|
+
constructor(config: WabaConfigType, client: RequesterClass) {
|
|
9
|
+
super(config, client);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async register(
|
|
13
|
+
pin: string,
|
|
14
|
+
dataLocalizationRegion?: DataLocalizationRegionEnum,
|
|
15
|
+
): Promise<RequesterResponseInterface<ResponseSuccess>> {
|
|
16
|
+
const body = {
|
|
17
|
+
messaging_product: 'whatsapp',
|
|
18
|
+
pin,
|
|
19
|
+
...(dataLocalizationRegion && { data_localization_region: dataLocalizationRegion }),
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
return this.client.sendRequest(
|
|
23
|
+
HttpMethodsEnum.Post,
|
|
24
|
+
`${this.config[WabaConfigEnum.PhoneNumberId]}/register`,
|
|
25
|
+
this.config[WabaConfigEnum.RequestTimeout],
|
|
26
|
+
JSON.stringify(body),
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async deregister(): Promise<RequesterResponseInterface<ResponseSuccess>> {
|
|
31
|
+
return this.client.sendRequest(
|
|
32
|
+
HttpMethodsEnum.Post,
|
|
33
|
+
`${this.config[WabaConfigEnum.PhoneNumberId]}/deregister`,
|
|
34
|
+
this.config[WabaConfigEnum.RequestTimeout],
|
|
35
|
+
null,
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
}
|