@ikatec/digisac-api-sdk 4.7.0 → 4.8.0
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/apis/campaigns/CampaignsApi.cjs +122 -55
- package/dist/apis/campaigns/CampaignsApi.cjs.map +1 -1
- package/dist/apis/campaigns/CampaignsApi.d.ts +86 -24
- package/dist/apis/campaigns/CampaignsApi.d.ts.map +1 -1
- package/dist/apis/campaigns/CampaignsApi.mjs +120 -55
- package/dist/apis/campaigns/CampaignsApi.mjs.map +1 -1
- package/dist/apis/campaigns/types.d.ts +153 -14
- package/dist/apis/campaigns/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/apis/campaigns/CampaignsApi.test.ts +177 -44
- package/src/apis/campaigns/CampaignsApi.ts +167 -45
- package/src/apis/campaigns/types.ts +165 -14
- package/src/apis/payloads.test-d.ts +44 -0
- package/src/apis/queryFormat.test.ts +25 -0
|
@@ -1,66 +1,133 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_chunk = require('../../_chunks/chunk-Dk0Otj32.cjs');
|
|
2
3
|
const require_core_BaseCrudApi = require('../../core/BaseCrudApi.cjs');
|
|
3
4
|
require('../../core/index.cjs');
|
|
5
|
+
let qs = require("qs");
|
|
6
|
+
qs = require_chunk.__toESM(qs);
|
|
4
7
|
|
|
5
8
|
//#region src/apis/campaigns/CampaignsApi.ts
|
|
9
|
+
/**
|
|
10
|
+
* Campaigns (mass sending). Every `/campaigns` route requires the campaigns feature in the plan of
|
|
11
|
+
* the account.
|
|
12
|
+
* `getMany` takes the `where` of a `ListQuery` and the flat filters of the Campaigns screen (see
|
|
13
|
+
* {@link CampaignListQuery}); `getById` of an unknown id resolves `null`. `deleteById` answers the
|
|
14
|
+
* text `'OK'`. `getMany({ paginate: false })` answers 400 `FILTER_PARAM_INVALID` with the default
|
|
15
|
+
* `'json'` query format (the route only takes `paginate` as a string): use `withQueryFormat('qs')`.
|
|
16
|
+
*/
|
|
6
17
|
var CampaignsApi = class extends require_core_BaseCrudApi.BaseCrudApi {
|
|
7
18
|
constructor(client) {
|
|
8
19
|
super(client, "/campaigns");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return this.client.post(`${this.basePath}/${id}/
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return this.client.
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return this.client.
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
|
|
51
|
-
return this.client.
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Starts sending the campaign: answers it as `processing` (an `import_error` campaign goes back
|
|
23
|
+
* to `importing_contacts`). It becomes `done` once every contact is fired.
|
|
24
|
+
* @permissions campaigns.view
|
|
25
|
+
*/
|
|
26
|
+
sendById(id, headers) {
|
|
27
|
+
return this.client.post(`${this.basePath}/${id}/send`, void 0, headers);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Sets the campaign as `paused` and answers `true`. An unknown id answers 500.
|
|
31
|
+
* @permissions campaigns.view
|
|
32
|
+
*/
|
|
33
|
+
pauseById(id, headers) {
|
|
34
|
+
return this.client.post(`${this.basePath}/${id}/pause`, void 0, headers);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Sets the campaign back to `processing` and answers `true`. An unknown id answers 500.
|
|
38
|
+
* @permissions campaigns.view
|
|
39
|
+
*/
|
|
40
|
+
resumeById(id, headers) {
|
|
41
|
+
return this.client.post(`${this.basePath}/${id}/resume`, void 0, headers);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Fires again the messages that failed: sets them as pending and the campaign as `processing`.
|
|
45
|
+
* Answers the text `'OK'` (also when nothing failed, and then the status does not change); an
|
|
46
|
+
* unknown id answers `false` (status 200).
|
|
47
|
+
* @permissions campaigns.view
|
|
48
|
+
*/
|
|
49
|
+
retryById(id, headers) {
|
|
50
|
+
return this.client.post(`${this.basePath}/${id}/retry`, void 0, headers);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Creates a copy of the campaign (`ready`, same title, messages and tags), answered without the
|
|
54
|
+
* messages. An unknown id answers 500.
|
|
55
|
+
* @permissions campaigns.view
|
|
56
|
+
*/
|
|
57
|
+
duplicateById(id, headers) {
|
|
58
|
+
return this.client.post(`${this.basePath}/${id}/duplicate`, void 0, headers);
|
|
59
|
+
}
|
|
60
|
+
/** Returns the send, delivery and interaction statistics of the campaign. */
|
|
61
|
+
getStatsById(id, headers) {
|
|
62
|
+
return this.client.get(`${this.basePath}/${id}/stats`, headers);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Returns the events of the campaign (created, scheduled, started, finished and the last
|
|
66
|
+
* interruption), the most recent first.
|
|
67
|
+
*/
|
|
68
|
+
getTimeline(id, headers) {
|
|
69
|
+
return this.client.get(`${this.basePath}/${id}/timeline`, headers);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Returns a page of the contacts of the campaign with their sending status (15 per page by
|
|
73
|
+
* default). An unknown id answers an empty page.
|
|
74
|
+
*/
|
|
75
|
+
getContacts(id, query, headers) {
|
|
76
|
+
return this.client.get(`${this.basePath}/${id}/contacts${this.toQueryString(query)}`, headers);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Sets the min/max interval between the sends (whole numbers, `0` or more) and answers `true`.
|
|
80
|
+
* An unknown id answers 500.
|
|
81
|
+
* @permissions campaigns.view
|
|
82
|
+
*/
|
|
83
|
+
setIntervalById(id, data, headers) {
|
|
84
|
+
return this.client.post(`${this.basePath}/${id}/interval`, data, headers);
|
|
85
|
+
}
|
|
86
|
+
/** Returns the number of contacts targeted by the campaign. */
|
|
87
|
+
getContactCount(id, headers) {
|
|
88
|
+
return this.client.get(`${this.basePath}/${id}/contactCount`, headers);
|
|
89
|
+
}
|
|
90
|
+
/** Counts the `ready` campaigns of a connection. An unknown id counts 0. */
|
|
91
|
+
countReadyByService(serviceId, headers) {
|
|
92
|
+
return this.client.get(`${this.basePath}/count-ready/${serviceId}`, headers);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Sets the auto-pause mode of the campaigns of the account (`settings.campaign`). Answers the
|
|
96
|
+
* text `'OK'`, or `false` when the account was not updated.
|
|
97
|
+
*/
|
|
98
|
+
setAutoPauseMode(data, headers) {
|
|
99
|
+
return this.client.put(`${this.basePath}/autoPauseMode`, data, headers);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Exports the contacts of the campaign and their sending result as CSV (13 columns in the
|
|
103
|
+
* language of the user; `,`, or `;` with `type: 'semiColon'`), streamed without a Content-Type.
|
|
104
|
+
*/
|
|
105
|
+
exportCampaignResult(data, headers) {
|
|
106
|
+
return this.client.post(`${this.basePath}/export/csv`, data, headers);
|
|
107
|
+
}
|
|
108
|
+
/** Exports the CSV (`;`) to fill in the contacts of a campaign of the given HSM template. */
|
|
109
|
+
exportTemplateCsv(data, headers) {
|
|
110
|
+
return this.client.post(`${this.basePath}/exportTemplate`, data, headers);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Exports the rows of the import file that were not imported (invalid number, unknown or
|
|
114
|
+
* ambiguous username) as CSV: line, name, number, username and reason.
|
|
115
|
+
*/
|
|
116
|
+
exportImportErrors(id, query, headers) {
|
|
117
|
+
const queryString = query?.delimiter ? `?${qs.default.stringify({ delimiter: query.delimiter })}` : "";
|
|
118
|
+
return this.client.get(`${this.basePath}/${id}/import-errors${queryString}`, headers);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Deletes the campaigns of the given ids and answers `true` (unknown ids are skipped). No id, or
|
|
122
|
+
* an id that is not a UUID, answers 400 `{ error: 'Invalid ids', code: 'INVALID_IDS' }`.
|
|
123
|
+
* @permissions campaigns.view OR campaigns.destroy
|
|
124
|
+
*/
|
|
125
|
+
deleteMany(ids, headers) {
|
|
126
|
+
return this.client.request("DELETE", `${this.basePath}/delete-many`, { ids }, headers);
|
|
127
|
+
}
|
|
128
|
+
/** Returns the HSM message usage and limit of an account. */
|
|
129
|
+
getHsmLimit(accountId, headers) {
|
|
130
|
+
return this.client.get(`/whatsapp-business-templates/${accountId}/hsmLimit`, headers);
|
|
64
131
|
}
|
|
65
132
|
};
|
|
66
133
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CampaignsApi.cjs","names":["BaseCrudApi"],"sources":["../../../src/apis/campaigns/CampaignsApi.ts"],"sourcesContent":["import type { ApiClient } from '../../core'\nimport { BaseCrudApi } from '../../core'\nimport type {\n AutoPauseModePayload,\n Campaign,\n CampaignStats,\n CreateCampaignPayload,\n ExportCampaignResultPayload,\n ExportTemplateCsvPayload,\n HsmLimit,\n SetIntervalPayload,\n UpdateCampaignPayload,\n} from './types'\n\nexport class CampaignsApi extends BaseCrudApi<\n Campaign,\n CreateCampaignPayload,\n UpdateCampaignPayload\n> {\n constructor(client: ApiClient) {\n super(client, '/campaigns')\n\n
|
|
1
|
+
{"version":3,"file":"CampaignsApi.cjs","names":["BaseCrudApi"],"sources":["../../../src/apis/campaigns/CampaignsApi.ts"],"sourcesContent":["import qs from 'qs'\nimport type { ApiClient } from '../../core'\nimport { BaseCrudApi } from '../../core'\nimport type {\n AutoPauseModePayload,\n Campaign,\n CampaignContactsPage,\n CampaignContactsQuery,\n CampaignListQuery,\n CampaignStats,\n CampaignTimelineEvent,\n CreateCampaignPayload,\n ExportCampaignImportErrorsQuery,\n ExportCampaignResultPayload,\n ExportTemplateCsvPayload,\n HsmLimit,\n SetIntervalPayload,\n UpdateCampaignPayload,\n} from './types'\n\n/**\n * Campaigns (mass sending). Every `/campaigns` route requires the campaigns feature in the plan of\n * the account.\n * `getMany` takes the `where` of a `ListQuery` and the flat filters of the Campaigns screen (see\n * {@link CampaignListQuery}); `getById` of an unknown id resolves `null`. `deleteById` answers the\n * text `'OK'`. `getMany({ paginate: false })` answers 400 `FILTER_PARAM_INVALID` with the default\n * `'json'` query format (the route only takes `paginate` as a string): use `withQueryFormat('qs')`.\n */\nexport class CampaignsApi extends BaseCrudApi<\n Campaign,\n CreateCampaignPayload,\n UpdateCampaignPayload,\n CampaignListQuery,\n 'OK'\n> {\n constructor(client: ApiClient) {\n super(client, '/campaigns')\n }\n\n /**\n * Starts sending the campaign: answers it as `processing` (an `import_error` campaign goes back\n * to `importing_contacts`). It becomes `done` once every contact is fired.\n * @permissions campaigns.view\n */\n sendById(id: string, headers?: Record<string, string>): Promise<Campaign> {\n return this.client.post<Campaign>(`${this.basePath}/${id}/send`, undefined, headers)\n }\n\n /**\n * Sets the campaign as `paused` and answers `true`. An unknown id answers 500.\n * @permissions campaigns.view\n */\n pauseById(id: string, headers?: Record<string, string>): Promise<boolean> {\n return this.client.post<boolean>(`${this.basePath}/${id}/pause`, undefined, headers)\n }\n\n /**\n * Sets the campaign back to `processing` and answers `true`. An unknown id answers 500.\n * @permissions campaigns.view\n */\n resumeById(id: string, headers?: Record<string, string>): Promise<boolean> {\n return this.client.post<boolean>(`${this.basePath}/${id}/resume`, undefined, headers)\n }\n\n /**\n * Fires again the messages that failed: sets them as pending and the campaign as `processing`.\n * Answers the text `'OK'` (also when nothing failed, and then the status does not change); an\n * unknown id answers `false` (status 200).\n * @permissions campaigns.view\n */\n retryById(id: string, headers?: Record<string, string>): Promise<'OK' | false> {\n return this.client.post<'OK' | false>(`${this.basePath}/${id}/retry`, undefined, headers)\n }\n\n /**\n * Creates a copy of the campaign (`ready`, same title, messages and tags), answered without the\n * messages. An unknown id answers 500.\n * @permissions campaigns.view\n */\n duplicateById(id: string, headers?: Record<string, string>): Promise<Campaign> {\n return this.client.post<Campaign>(`${this.basePath}/${id}/duplicate`, undefined, headers)\n }\n\n /** Returns the send, delivery and interaction statistics of the campaign. */\n getStatsById(id: string, headers?: Record<string, string>): Promise<CampaignStats> {\n return this.client.get<CampaignStats>(`${this.basePath}/${id}/stats`, headers)\n }\n\n /**\n * Returns the events of the campaign (created, scheduled, started, finished and the last\n * interruption), the most recent first.\n */\n getTimeline(id: string, headers?: Record<string, string>): Promise<CampaignTimelineEvent[]> {\n return this.client.get<CampaignTimelineEvent[]>(`${this.basePath}/${id}/timeline`, headers)\n }\n\n /**\n * Returns a page of the contacts of the campaign with their sending status (15 per page by\n * default). An unknown id answers an empty page.\n */\n getContacts(\n id: string,\n query?: CampaignContactsQuery,\n headers?: Record<string, string>,\n ): Promise<CampaignContactsPage> {\n return this.client.get<CampaignContactsPage>(\n `${this.basePath}/${id}/contacts${this.toQueryString(query)}`,\n headers,\n )\n }\n\n /**\n * Sets the min/max interval between the sends (whole numbers, `0` or more) and answers `true`.\n * An unknown id answers 500.\n * @permissions campaigns.view\n */\n setIntervalById(\n id: string,\n data: SetIntervalPayload,\n headers?: Record<string, string>,\n ): Promise<boolean> {\n return this.client.post<boolean, SetIntervalPayload>(\n `${this.basePath}/${id}/interval`,\n data,\n headers,\n )\n }\n\n /** Returns the number of contacts targeted by the campaign. */\n getContactCount(id: string, headers?: Record<string, string>): Promise<number> {\n return this.client.get<number>(`${this.basePath}/${id}/contactCount`, headers)\n }\n\n /** Counts the `ready` campaigns of a connection. An unknown id counts 0. */\n countReadyByService(serviceId: string, headers?: Record<string, string>): Promise<number> {\n return this.client.get<number>(`${this.basePath}/count-ready/${serviceId}`, headers)\n }\n\n /**\n * Sets the auto-pause mode of the campaigns of the account (`settings.campaign`). Answers the\n * text `'OK'`, or `false` when the account was not updated.\n */\n setAutoPauseMode(\n data: AutoPauseModePayload,\n headers?: Record<string, string>,\n ): Promise<'OK' | false> {\n return this.client.put<'OK' | false, AutoPauseModePayload>(\n `${this.basePath}/autoPauseMode`,\n data,\n headers,\n )\n }\n\n /**\n * Exports the contacts of the campaign and their sending result as CSV (13 columns in the\n * language of the user; `,`, or `;` with `type: 'semiColon'`), streamed without a Content-Type.\n */\n exportCampaignResult(\n data: ExportCampaignResultPayload,\n headers?: Record<string, string>,\n ): Promise<string> {\n return this.client.post<string, ExportCampaignResultPayload>(\n `${this.basePath}/export/csv`,\n data,\n headers,\n )\n }\n\n /** Exports the CSV (`;`) to fill in the contacts of a campaign of the given HSM template. */\n exportTemplateCsv(\n data: ExportTemplateCsvPayload,\n headers?: Record<string, string>,\n ): Promise<string> {\n return this.client.post<string, ExportTemplateCsvPayload>(\n `${this.basePath}/exportTemplate`,\n data,\n headers,\n )\n }\n\n /**\n * Exports the rows of the import file that were not imported (invalid number, unknown or\n * ambiguous username) as CSV: line, name, number, username and reason.\n */\n exportImportErrors(\n id: string,\n query?: ExportCampaignImportErrorsQuery,\n headers?: Record<string, string>,\n ): Promise<string> {\n const queryString = query?.delimiter ? `?${qs.stringify({ delimiter: query.delimiter })}` : ''\n return this.client.get<string>(`${this.basePath}/${id}/import-errors${queryString}`, headers)\n }\n\n /**\n * Deletes the campaigns of the given ids and answers `true` (unknown ids are skipped). No id, or\n * an id that is not a UUID, answers 400 `{ error: 'Invalid ids', code: 'INVALID_IDS' }`.\n * @permissions campaigns.view OR campaigns.destroy\n */\n deleteMany(ids: string[], headers?: Record<string, string>): Promise<true> {\n return this.client.request<true, { ids: string[] }>(\n 'DELETE',\n `${this.basePath}/delete-many`,\n { ids },\n headers,\n )\n }\n\n /** Returns the HSM message usage and limit of an account. */\n getHsmLimit(accountId: string, headers?: Record<string, string>): Promise<HsmLimit> {\n return this.client.get<HsmLimit>(`/whatsapp-business-templates/${accountId}/hsmLimit`, headers)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA4BA,IAAa,eAAb,cAAkCA,qCAMhC;CACA,YAAY,QAAmB;AAC7B,QAAM,QAAQ,aAAa;;;;;;;CAQ7B,SAAS,IAAY,SAAqD;AACxE,SAAO,KAAK,OAAO,KAAe,GAAG,KAAK,SAAS,GAAG,GAAG,QAAQ,QAAW,QAAQ;;;;;;CAOtF,UAAU,IAAY,SAAoD;AACxE,SAAO,KAAK,OAAO,KAAc,GAAG,KAAK,SAAS,GAAG,GAAG,SAAS,QAAW,QAAQ;;;;;;CAOtF,WAAW,IAAY,SAAoD;AACzE,SAAO,KAAK,OAAO,KAAc,GAAG,KAAK,SAAS,GAAG,GAAG,UAAU,QAAW,QAAQ;;;;;;;;CASvF,UAAU,IAAY,SAAyD;AAC7E,SAAO,KAAK,OAAO,KAAmB,GAAG,KAAK,SAAS,GAAG,GAAG,SAAS,QAAW,QAAQ;;;;;;;CAQ3F,cAAc,IAAY,SAAqD;AAC7E,SAAO,KAAK,OAAO,KAAe,GAAG,KAAK,SAAS,GAAG,GAAG,aAAa,QAAW,QAAQ;;;CAI3F,aAAa,IAAY,SAA0D;AACjF,SAAO,KAAK,OAAO,IAAmB,GAAG,KAAK,SAAS,GAAG,GAAG,SAAS,QAAQ;;;;;;CAOhF,YAAY,IAAY,SAAoE;AAC1F,SAAO,KAAK,OAAO,IAA6B,GAAG,KAAK,SAAS,GAAG,GAAG,YAAY,QAAQ;;;;;;CAO7F,YACE,IACA,OACA,SAC+B;AAC/B,SAAO,KAAK,OAAO,IACjB,GAAG,KAAK,SAAS,GAAG,GAAG,WAAW,KAAK,cAAc,MAAM,IAC3D,QACD;;;;;;;CAQH,gBACE,IACA,MACA,SACkB;AAClB,SAAO,KAAK,OAAO,KACjB,GAAG,KAAK,SAAS,GAAG,GAAG,YACvB,MACA,QACD;;;CAIH,gBAAgB,IAAY,SAAmD;AAC7E,SAAO,KAAK,OAAO,IAAY,GAAG,KAAK,SAAS,GAAG,GAAG,gBAAgB,QAAQ;;;CAIhF,oBAAoB,WAAmB,SAAmD;AACxF,SAAO,KAAK,OAAO,IAAY,GAAG,KAAK,SAAS,eAAe,aAAa,QAAQ;;;;;;CAOtF,iBACE,MACA,SACuB;AACvB,SAAO,KAAK,OAAO,IACjB,GAAG,KAAK,SAAS,iBACjB,MACA,QACD;;;;;;CAOH,qBACE,MACA,SACiB;AACjB,SAAO,KAAK,OAAO,KACjB,GAAG,KAAK,SAAS,cACjB,MACA,QACD;;;CAIH,kBACE,MACA,SACiB;AACjB,SAAO,KAAK,OAAO,KACjB,GAAG,KAAK,SAAS,kBACjB,MACA,QACD;;;;;;CAOH,mBACE,IACA,OACA,SACiB;EACjB,MAAM,cAAc,OAAO,YAAY,IAAI,WAAG,UAAU,EAAE,WAAW,MAAM,WAAW,CAAC,KAAK;AAC5F,SAAO,KAAK,OAAO,IAAY,GAAG,KAAK,SAAS,GAAG,GAAG,gBAAgB,eAAe,QAAQ;;;;;;;CAQ/F,WAAW,KAAe,SAAiD;AACzE,SAAO,KAAK,OAAO,QACjB,UACA,GAAG,KAAK,SAAS,eACjB,EAAE,KAAK,EACP,QACD;;;CAIH,YAAY,WAAmB,SAAqD;AAClF,SAAO,KAAK,OAAO,IAAc,gCAAgC,UAAU,YAAY,QAAQ"}
|
|
@@ -1,29 +1,91 @@
|
|
|
1
1
|
import type { ApiClient } from '../../core';
|
|
2
2
|
import { BaseCrudApi } from '../../core';
|
|
3
|
-
import type { AutoPauseModePayload, Campaign, CampaignStats, CreateCampaignPayload, ExportCampaignResultPayload, ExportTemplateCsvPayload, HsmLimit, SetIntervalPayload, UpdateCampaignPayload } from './types';
|
|
4
|
-
|
|
3
|
+
import type { AutoPauseModePayload, Campaign, CampaignContactsPage, CampaignContactsQuery, CampaignListQuery, CampaignStats, CampaignTimelineEvent, CreateCampaignPayload, ExportCampaignImportErrorsQuery, ExportCampaignResultPayload, ExportTemplateCsvPayload, HsmLimit, SetIntervalPayload, UpdateCampaignPayload } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* Campaigns (mass sending). Every `/campaigns` route requires the campaigns feature in the plan of
|
|
6
|
+
* the account.
|
|
7
|
+
* `getMany` takes the `where` of a `ListQuery` and the flat filters of the Campaigns screen (see
|
|
8
|
+
* {@link CampaignListQuery}); `getById` of an unknown id resolves `null`. `deleteById` answers the
|
|
9
|
+
* text `'OK'`. `getMany({ paginate: false })` answers 400 `FILTER_PARAM_INVALID` with the default
|
|
10
|
+
* `'json'` query format (the route only takes `paginate` as a string): use `withQueryFormat('qs')`.
|
|
11
|
+
*/
|
|
12
|
+
export declare class CampaignsApi extends BaseCrudApi<Campaign, CreateCampaignPayload, UpdateCampaignPayload, CampaignListQuery, 'OK'> {
|
|
5
13
|
constructor(client: ApiClient);
|
|
6
|
-
/**
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Starts sending the campaign: answers it as `processing` (an `import_error` campaign goes back
|
|
16
|
+
* to `importing_contacts`). It becomes `done` once every contact is fired.
|
|
17
|
+
* @permissions campaigns.view
|
|
18
|
+
*/
|
|
19
|
+
sendById(id: string, headers?: Record<string, string>): Promise<Campaign>;
|
|
20
|
+
/**
|
|
21
|
+
* Sets the campaign as `paused` and answers `true`. An unknown id answers 500.
|
|
22
|
+
* @permissions campaigns.view
|
|
23
|
+
*/
|
|
24
|
+
pauseById(id: string, headers?: Record<string, string>): Promise<boolean>;
|
|
25
|
+
/**
|
|
26
|
+
* Sets the campaign back to `processing` and answers `true`. An unknown id answers 500.
|
|
27
|
+
* @permissions campaigns.view
|
|
28
|
+
*/
|
|
29
|
+
resumeById(id: string, headers?: Record<string, string>): Promise<boolean>;
|
|
30
|
+
/**
|
|
31
|
+
* Fires again the messages that failed: sets them as pending and the campaign as `processing`.
|
|
32
|
+
* Answers the text `'OK'` (also when nothing failed, and then the status does not change); an
|
|
33
|
+
* unknown id answers `false` (status 200).
|
|
34
|
+
* @permissions campaigns.view
|
|
35
|
+
*/
|
|
36
|
+
retryById(id: string, headers?: Record<string, string>): Promise<'OK' | false>;
|
|
37
|
+
/**
|
|
38
|
+
* Creates a copy of the campaign (`ready`, same title, messages and tags), answered without the
|
|
39
|
+
* messages. An unknown id answers 500.
|
|
40
|
+
* @permissions campaigns.view
|
|
41
|
+
*/
|
|
42
|
+
duplicateById(id: string, headers?: Record<string, string>): Promise<Campaign>;
|
|
43
|
+
/** Returns the send, delivery and interaction statistics of the campaign. */
|
|
44
|
+
getStatsById(id: string, headers?: Record<string, string>): Promise<CampaignStats>;
|
|
45
|
+
/**
|
|
46
|
+
* Returns the events of the campaign (created, scheduled, started, finished and the last
|
|
47
|
+
* interruption), the most recent first.
|
|
48
|
+
*/
|
|
49
|
+
getTimeline(id: string, headers?: Record<string, string>): Promise<CampaignTimelineEvent[]>;
|
|
50
|
+
/**
|
|
51
|
+
* Returns a page of the contacts of the campaign with their sending status (15 per page by
|
|
52
|
+
* default). An unknown id answers an empty page.
|
|
53
|
+
*/
|
|
54
|
+
getContacts(id: string, query?: CampaignContactsQuery, headers?: Record<string, string>): Promise<CampaignContactsPage>;
|
|
55
|
+
/**
|
|
56
|
+
* Sets the min/max interval between the sends (whole numbers, `0` or more) and answers `true`.
|
|
57
|
+
* An unknown id answers 500.
|
|
58
|
+
* @permissions campaigns.view
|
|
59
|
+
*/
|
|
60
|
+
setIntervalById(id: string, data: SetIntervalPayload, headers?: Record<string, string>): Promise<boolean>;
|
|
61
|
+
/** Returns the number of contacts targeted by the campaign. */
|
|
62
|
+
getContactCount(id: string, headers?: Record<string, string>): Promise<number>;
|
|
63
|
+
/** Counts the `ready` campaigns of a connection. An unknown id counts 0. */
|
|
64
|
+
countReadyByService(serviceId: string, headers?: Record<string, string>): Promise<number>;
|
|
65
|
+
/**
|
|
66
|
+
* Sets the auto-pause mode of the campaigns of the account (`settings.campaign`). Answers the
|
|
67
|
+
* text `'OK'`, or `false` when the account was not updated.
|
|
68
|
+
*/
|
|
69
|
+
setAutoPauseMode(data: AutoPauseModePayload, headers?: Record<string, string>): Promise<'OK' | false>;
|
|
70
|
+
/**
|
|
71
|
+
* Exports the contacts of the campaign and their sending result as CSV (13 columns in the
|
|
72
|
+
* language of the user; `,`, or `;` with `type: 'semiColon'`), streamed without a Content-Type.
|
|
73
|
+
*/
|
|
74
|
+
exportCampaignResult(data: ExportCampaignResultPayload, headers?: Record<string, string>): Promise<string>;
|
|
75
|
+
/** Exports the CSV (`;`) to fill in the contacts of a campaign of the given HSM template. */
|
|
76
|
+
exportTemplateCsv(data: ExportTemplateCsvPayload, headers?: Record<string, string>): Promise<string>;
|
|
77
|
+
/**
|
|
78
|
+
* Exports the rows of the import file that were not imported (invalid number, unknown or
|
|
79
|
+
* ambiguous username) as CSV: line, name, number, username and reason.
|
|
80
|
+
*/
|
|
81
|
+
exportImportErrors(id: string, query?: ExportCampaignImportErrorsQuery, headers?: Record<string, string>): Promise<string>;
|
|
82
|
+
/**
|
|
83
|
+
* Deletes the campaigns of the given ids and answers `true` (unknown ids are skipped). No id, or
|
|
84
|
+
* an id that is not a UUID, answers 400 `{ error: 'Invalid ids', code: 'INVALID_IDS' }`.
|
|
85
|
+
* @permissions campaigns.view OR campaigns.destroy
|
|
86
|
+
*/
|
|
87
|
+
deleteMany(ids: string[], headers?: Record<string, string>): Promise<true>;
|
|
88
|
+
/** Returns the HSM message usage and limit of an account. */
|
|
89
|
+
getHsmLimit(accountId: string, headers?: Record<string, string>): Promise<HsmLimit>;
|
|
28
90
|
}
|
|
29
91
|
//# sourceMappingURL=CampaignsApi.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CampaignsApi.d.ts","sourceRoot":"","sources":["../../../src/apis/campaigns/CampaignsApi.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CampaignsApi.d.ts","sourceRoot":"","sources":["../../../src/apis/campaigns/CampaignsApi.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,65 +1,130 @@
|
|
|
1
1
|
import { BaseCrudApi } from "../../core/BaseCrudApi.mjs";
|
|
2
2
|
import "../../core/index.mjs";
|
|
3
|
+
import qs from "qs";
|
|
3
4
|
|
|
4
5
|
//#region src/apis/campaigns/CampaignsApi.ts
|
|
6
|
+
/**
|
|
7
|
+
* Campaigns (mass sending). Every `/campaigns` route requires the campaigns feature in the plan of
|
|
8
|
+
* the account.
|
|
9
|
+
* `getMany` takes the `where` of a `ListQuery` and the flat filters of the Campaigns screen (see
|
|
10
|
+
* {@link CampaignListQuery}); `getById` of an unknown id resolves `null`. `deleteById` answers the
|
|
11
|
+
* text `'OK'`. `getMany({ paginate: false })` answers 400 `FILTER_PARAM_INVALID` with the default
|
|
12
|
+
* `'json'` query format (the route only takes `paginate` as a string): use `withQueryFormat('qs')`.
|
|
13
|
+
*/
|
|
5
14
|
var CampaignsApi = class extends BaseCrudApi {
|
|
6
15
|
constructor(client) {
|
|
7
16
|
super(client, "/campaigns");
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return this.client.post(`${this.basePath}/${id}/
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return this.client.
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return this.client.
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
|
|
50
|
-
return this.client.
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Starts sending the campaign: answers it as `processing` (an `import_error` campaign goes back
|
|
20
|
+
* to `importing_contacts`). It becomes `done` once every contact is fired.
|
|
21
|
+
* @permissions campaigns.view
|
|
22
|
+
*/
|
|
23
|
+
sendById(id, headers) {
|
|
24
|
+
return this.client.post(`${this.basePath}/${id}/send`, void 0, headers);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Sets the campaign as `paused` and answers `true`. An unknown id answers 500.
|
|
28
|
+
* @permissions campaigns.view
|
|
29
|
+
*/
|
|
30
|
+
pauseById(id, headers) {
|
|
31
|
+
return this.client.post(`${this.basePath}/${id}/pause`, void 0, headers);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Sets the campaign back to `processing` and answers `true`. An unknown id answers 500.
|
|
35
|
+
* @permissions campaigns.view
|
|
36
|
+
*/
|
|
37
|
+
resumeById(id, headers) {
|
|
38
|
+
return this.client.post(`${this.basePath}/${id}/resume`, void 0, headers);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Fires again the messages that failed: sets them as pending and the campaign as `processing`.
|
|
42
|
+
* Answers the text `'OK'` (also when nothing failed, and then the status does not change); an
|
|
43
|
+
* unknown id answers `false` (status 200).
|
|
44
|
+
* @permissions campaigns.view
|
|
45
|
+
*/
|
|
46
|
+
retryById(id, headers) {
|
|
47
|
+
return this.client.post(`${this.basePath}/${id}/retry`, void 0, headers);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Creates a copy of the campaign (`ready`, same title, messages and tags), answered without the
|
|
51
|
+
* messages. An unknown id answers 500.
|
|
52
|
+
* @permissions campaigns.view
|
|
53
|
+
*/
|
|
54
|
+
duplicateById(id, headers) {
|
|
55
|
+
return this.client.post(`${this.basePath}/${id}/duplicate`, void 0, headers);
|
|
56
|
+
}
|
|
57
|
+
/** Returns the send, delivery and interaction statistics of the campaign. */
|
|
58
|
+
getStatsById(id, headers) {
|
|
59
|
+
return this.client.get(`${this.basePath}/${id}/stats`, headers);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Returns the events of the campaign (created, scheduled, started, finished and the last
|
|
63
|
+
* interruption), the most recent first.
|
|
64
|
+
*/
|
|
65
|
+
getTimeline(id, headers) {
|
|
66
|
+
return this.client.get(`${this.basePath}/${id}/timeline`, headers);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Returns a page of the contacts of the campaign with their sending status (15 per page by
|
|
70
|
+
* default). An unknown id answers an empty page.
|
|
71
|
+
*/
|
|
72
|
+
getContacts(id, query, headers) {
|
|
73
|
+
return this.client.get(`${this.basePath}/${id}/contacts${this.toQueryString(query)}`, headers);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Sets the min/max interval between the sends (whole numbers, `0` or more) and answers `true`.
|
|
77
|
+
* An unknown id answers 500.
|
|
78
|
+
* @permissions campaigns.view
|
|
79
|
+
*/
|
|
80
|
+
setIntervalById(id, data, headers) {
|
|
81
|
+
return this.client.post(`${this.basePath}/${id}/interval`, data, headers);
|
|
82
|
+
}
|
|
83
|
+
/** Returns the number of contacts targeted by the campaign. */
|
|
84
|
+
getContactCount(id, headers) {
|
|
85
|
+
return this.client.get(`${this.basePath}/${id}/contactCount`, headers);
|
|
86
|
+
}
|
|
87
|
+
/** Counts the `ready` campaigns of a connection. An unknown id counts 0. */
|
|
88
|
+
countReadyByService(serviceId, headers) {
|
|
89
|
+
return this.client.get(`${this.basePath}/count-ready/${serviceId}`, headers);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Sets the auto-pause mode of the campaigns of the account (`settings.campaign`). Answers the
|
|
93
|
+
* text `'OK'`, or `false` when the account was not updated.
|
|
94
|
+
*/
|
|
95
|
+
setAutoPauseMode(data, headers) {
|
|
96
|
+
return this.client.put(`${this.basePath}/autoPauseMode`, data, headers);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Exports the contacts of the campaign and their sending result as CSV (13 columns in the
|
|
100
|
+
* language of the user; `,`, or `;` with `type: 'semiColon'`), streamed without a Content-Type.
|
|
101
|
+
*/
|
|
102
|
+
exportCampaignResult(data, headers) {
|
|
103
|
+
return this.client.post(`${this.basePath}/export/csv`, data, headers);
|
|
104
|
+
}
|
|
105
|
+
/** Exports the CSV (`;`) to fill in the contacts of a campaign of the given HSM template. */
|
|
106
|
+
exportTemplateCsv(data, headers) {
|
|
107
|
+
return this.client.post(`${this.basePath}/exportTemplate`, data, headers);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Exports the rows of the import file that were not imported (invalid number, unknown or
|
|
111
|
+
* ambiguous username) as CSV: line, name, number, username and reason.
|
|
112
|
+
*/
|
|
113
|
+
exportImportErrors(id, query, headers) {
|
|
114
|
+
const queryString = query?.delimiter ? `?${qs.stringify({ delimiter: query.delimiter })}` : "";
|
|
115
|
+
return this.client.get(`${this.basePath}/${id}/import-errors${queryString}`, headers);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Deletes the campaigns of the given ids and answers `true` (unknown ids are skipped). No id, or
|
|
119
|
+
* an id that is not a UUID, answers 400 `{ error: 'Invalid ids', code: 'INVALID_IDS' }`.
|
|
120
|
+
* @permissions campaigns.view OR campaigns.destroy
|
|
121
|
+
*/
|
|
122
|
+
deleteMany(ids, headers) {
|
|
123
|
+
return this.client.request("DELETE", `${this.basePath}/delete-many`, { ids }, headers);
|
|
124
|
+
}
|
|
125
|
+
/** Returns the HSM message usage and limit of an account. */
|
|
126
|
+
getHsmLimit(accountId, headers) {
|
|
127
|
+
return this.client.get(`/whatsapp-business-templates/${accountId}/hsmLimit`, headers);
|
|
63
128
|
}
|
|
64
129
|
};
|
|
65
130
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CampaignsApi.mjs","names":[],"sources":["../../../src/apis/campaigns/CampaignsApi.ts"],"sourcesContent":["import type { ApiClient } from '../../core'\nimport { BaseCrudApi } from '../../core'\nimport type {\n AutoPauseModePayload,\n Campaign,\n CampaignStats,\n CreateCampaignPayload,\n ExportCampaignResultPayload,\n ExportTemplateCsvPayload,\n HsmLimit,\n SetIntervalPayload,\n UpdateCampaignPayload,\n} from './types'\n\nexport class CampaignsApi extends BaseCrudApi<\n Campaign,\n CreateCampaignPayload,\n UpdateCampaignPayload\n> {\n constructor(client: ApiClient) {\n super(client, '/campaigns')\n\n
|
|
1
|
+
{"version":3,"file":"CampaignsApi.mjs","names":[],"sources":["../../../src/apis/campaigns/CampaignsApi.ts"],"sourcesContent":["import qs from 'qs'\nimport type { ApiClient } from '../../core'\nimport { BaseCrudApi } from '../../core'\nimport type {\n AutoPauseModePayload,\n Campaign,\n CampaignContactsPage,\n CampaignContactsQuery,\n CampaignListQuery,\n CampaignStats,\n CampaignTimelineEvent,\n CreateCampaignPayload,\n ExportCampaignImportErrorsQuery,\n ExportCampaignResultPayload,\n ExportTemplateCsvPayload,\n HsmLimit,\n SetIntervalPayload,\n UpdateCampaignPayload,\n} from './types'\n\n/**\n * Campaigns (mass sending). Every `/campaigns` route requires the campaigns feature in the plan of\n * the account.\n * `getMany` takes the `where` of a `ListQuery` and the flat filters of the Campaigns screen (see\n * {@link CampaignListQuery}); `getById` of an unknown id resolves `null`. `deleteById` answers the\n * text `'OK'`. `getMany({ paginate: false })` answers 400 `FILTER_PARAM_INVALID` with the default\n * `'json'` query format (the route only takes `paginate` as a string): use `withQueryFormat('qs')`.\n */\nexport class CampaignsApi extends BaseCrudApi<\n Campaign,\n CreateCampaignPayload,\n UpdateCampaignPayload,\n CampaignListQuery,\n 'OK'\n> {\n constructor(client: ApiClient) {\n super(client, '/campaigns')\n }\n\n /**\n * Starts sending the campaign: answers it as `processing` (an `import_error` campaign goes back\n * to `importing_contacts`). It becomes `done` once every contact is fired.\n * @permissions campaigns.view\n */\n sendById(id: string, headers?: Record<string, string>): Promise<Campaign> {\n return this.client.post<Campaign>(`${this.basePath}/${id}/send`, undefined, headers)\n }\n\n /**\n * Sets the campaign as `paused` and answers `true`. An unknown id answers 500.\n * @permissions campaigns.view\n */\n pauseById(id: string, headers?: Record<string, string>): Promise<boolean> {\n return this.client.post<boolean>(`${this.basePath}/${id}/pause`, undefined, headers)\n }\n\n /**\n * Sets the campaign back to `processing` and answers `true`. An unknown id answers 500.\n * @permissions campaigns.view\n */\n resumeById(id: string, headers?: Record<string, string>): Promise<boolean> {\n return this.client.post<boolean>(`${this.basePath}/${id}/resume`, undefined, headers)\n }\n\n /**\n * Fires again the messages that failed: sets them as pending and the campaign as `processing`.\n * Answers the text `'OK'` (also when nothing failed, and then the status does not change); an\n * unknown id answers `false` (status 200).\n * @permissions campaigns.view\n */\n retryById(id: string, headers?: Record<string, string>): Promise<'OK' | false> {\n return this.client.post<'OK' | false>(`${this.basePath}/${id}/retry`, undefined, headers)\n }\n\n /**\n * Creates a copy of the campaign (`ready`, same title, messages and tags), answered without the\n * messages. An unknown id answers 500.\n * @permissions campaigns.view\n */\n duplicateById(id: string, headers?: Record<string, string>): Promise<Campaign> {\n return this.client.post<Campaign>(`${this.basePath}/${id}/duplicate`, undefined, headers)\n }\n\n /** Returns the send, delivery and interaction statistics of the campaign. */\n getStatsById(id: string, headers?: Record<string, string>): Promise<CampaignStats> {\n return this.client.get<CampaignStats>(`${this.basePath}/${id}/stats`, headers)\n }\n\n /**\n * Returns the events of the campaign (created, scheduled, started, finished and the last\n * interruption), the most recent first.\n */\n getTimeline(id: string, headers?: Record<string, string>): Promise<CampaignTimelineEvent[]> {\n return this.client.get<CampaignTimelineEvent[]>(`${this.basePath}/${id}/timeline`, headers)\n }\n\n /**\n * Returns a page of the contacts of the campaign with their sending status (15 per page by\n * default). An unknown id answers an empty page.\n */\n getContacts(\n id: string,\n query?: CampaignContactsQuery,\n headers?: Record<string, string>,\n ): Promise<CampaignContactsPage> {\n return this.client.get<CampaignContactsPage>(\n `${this.basePath}/${id}/contacts${this.toQueryString(query)}`,\n headers,\n )\n }\n\n /**\n * Sets the min/max interval between the sends (whole numbers, `0` or more) and answers `true`.\n * An unknown id answers 500.\n * @permissions campaigns.view\n */\n setIntervalById(\n id: string,\n data: SetIntervalPayload,\n headers?: Record<string, string>,\n ): Promise<boolean> {\n return this.client.post<boolean, SetIntervalPayload>(\n `${this.basePath}/${id}/interval`,\n data,\n headers,\n )\n }\n\n /** Returns the number of contacts targeted by the campaign. */\n getContactCount(id: string, headers?: Record<string, string>): Promise<number> {\n return this.client.get<number>(`${this.basePath}/${id}/contactCount`, headers)\n }\n\n /** Counts the `ready` campaigns of a connection. An unknown id counts 0. */\n countReadyByService(serviceId: string, headers?: Record<string, string>): Promise<number> {\n return this.client.get<number>(`${this.basePath}/count-ready/${serviceId}`, headers)\n }\n\n /**\n * Sets the auto-pause mode of the campaigns of the account (`settings.campaign`). Answers the\n * text `'OK'`, or `false` when the account was not updated.\n */\n setAutoPauseMode(\n data: AutoPauseModePayload,\n headers?: Record<string, string>,\n ): Promise<'OK' | false> {\n return this.client.put<'OK' | false, AutoPauseModePayload>(\n `${this.basePath}/autoPauseMode`,\n data,\n headers,\n )\n }\n\n /**\n * Exports the contacts of the campaign and their sending result as CSV (13 columns in the\n * language of the user; `,`, or `;` with `type: 'semiColon'`), streamed without a Content-Type.\n */\n exportCampaignResult(\n data: ExportCampaignResultPayload,\n headers?: Record<string, string>,\n ): Promise<string> {\n return this.client.post<string, ExportCampaignResultPayload>(\n `${this.basePath}/export/csv`,\n data,\n headers,\n )\n }\n\n /** Exports the CSV (`;`) to fill in the contacts of a campaign of the given HSM template. */\n exportTemplateCsv(\n data: ExportTemplateCsvPayload,\n headers?: Record<string, string>,\n ): Promise<string> {\n return this.client.post<string, ExportTemplateCsvPayload>(\n `${this.basePath}/exportTemplate`,\n data,\n headers,\n )\n }\n\n /**\n * Exports the rows of the import file that were not imported (invalid number, unknown or\n * ambiguous username) as CSV: line, name, number, username and reason.\n */\n exportImportErrors(\n id: string,\n query?: ExportCampaignImportErrorsQuery,\n headers?: Record<string, string>,\n ): Promise<string> {\n const queryString = query?.delimiter ? `?${qs.stringify({ delimiter: query.delimiter })}` : ''\n return this.client.get<string>(`${this.basePath}/${id}/import-errors${queryString}`, headers)\n }\n\n /**\n * Deletes the campaigns of the given ids and answers `true` (unknown ids are skipped). No id, or\n * an id that is not a UUID, answers 400 `{ error: 'Invalid ids', code: 'INVALID_IDS' }`.\n * @permissions campaigns.view OR campaigns.destroy\n */\n deleteMany(ids: string[], headers?: Record<string, string>): Promise<true> {\n return this.client.request<true, { ids: string[] }>(\n 'DELETE',\n `${this.basePath}/delete-many`,\n { ids },\n headers,\n )\n }\n\n /** Returns the HSM message usage and limit of an account. */\n getHsmLimit(accountId: string, headers?: Record<string, string>): Promise<HsmLimit> {\n return this.client.get<HsmLimit>(`/whatsapp-business-templates/${accountId}/hsmLimit`, headers)\n }\n}\n"],"mappings":";;;;;;;;;;;;;AA4BA,IAAa,eAAb,cAAkC,YAMhC;CACA,YAAY,QAAmB;AAC7B,QAAM,QAAQ,aAAa;;;;;;;CAQ7B,SAAS,IAAY,SAAqD;AACxE,SAAO,KAAK,OAAO,KAAe,GAAG,KAAK,SAAS,GAAG,GAAG,QAAQ,QAAW,QAAQ;;;;;;CAOtF,UAAU,IAAY,SAAoD;AACxE,SAAO,KAAK,OAAO,KAAc,GAAG,KAAK,SAAS,GAAG,GAAG,SAAS,QAAW,QAAQ;;;;;;CAOtF,WAAW,IAAY,SAAoD;AACzE,SAAO,KAAK,OAAO,KAAc,GAAG,KAAK,SAAS,GAAG,GAAG,UAAU,QAAW,QAAQ;;;;;;;;CASvF,UAAU,IAAY,SAAyD;AAC7E,SAAO,KAAK,OAAO,KAAmB,GAAG,KAAK,SAAS,GAAG,GAAG,SAAS,QAAW,QAAQ;;;;;;;CAQ3F,cAAc,IAAY,SAAqD;AAC7E,SAAO,KAAK,OAAO,KAAe,GAAG,KAAK,SAAS,GAAG,GAAG,aAAa,QAAW,QAAQ;;;CAI3F,aAAa,IAAY,SAA0D;AACjF,SAAO,KAAK,OAAO,IAAmB,GAAG,KAAK,SAAS,GAAG,GAAG,SAAS,QAAQ;;;;;;CAOhF,YAAY,IAAY,SAAoE;AAC1F,SAAO,KAAK,OAAO,IAA6B,GAAG,KAAK,SAAS,GAAG,GAAG,YAAY,QAAQ;;;;;;CAO7F,YACE,IACA,OACA,SAC+B;AAC/B,SAAO,KAAK,OAAO,IACjB,GAAG,KAAK,SAAS,GAAG,GAAG,WAAW,KAAK,cAAc,MAAM,IAC3D,QACD;;;;;;;CAQH,gBACE,IACA,MACA,SACkB;AAClB,SAAO,KAAK,OAAO,KACjB,GAAG,KAAK,SAAS,GAAG,GAAG,YACvB,MACA,QACD;;;CAIH,gBAAgB,IAAY,SAAmD;AAC7E,SAAO,KAAK,OAAO,IAAY,GAAG,KAAK,SAAS,GAAG,GAAG,gBAAgB,QAAQ;;;CAIhF,oBAAoB,WAAmB,SAAmD;AACxF,SAAO,KAAK,OAAO,IAAY,GAAG,KAAK,SAAS,eAAe,aAAa,QAAQ;;;;;;CAOtF,iBACE,MACA,SACuB;AACvB,SAAO,KAAK,OAAO,IACjB,GAAG,KAAK,SAAS,iBACjB,MACA,QACD;;;;;;CAOH,qBACE,MACA,SACiB;AACjB,SAAO,KAAK,OAAO,KACjB,GAAG,KAAK,SAAS,cACjB,MACA,QACD;;;CAIH,kBACE,MACA,SACiB;AACjB,SAAO,KAAK,OAAO,KACjB,GAAG,KAAK,SAAS,kBACjB,MACA,QACD;;;;;;CAOH,mBACE,IACA,OACA,SACiB;EACjB,MAAM,cAAc,OAAO,YAAY,IAAI,GAAG,UAAU,EAAE,WAAW,MAAM,WAAW,CAAC,KAAK;AAC5F,SAAO,KAAK,OAAO,IAAY,GAAG,KAAK,SAAS,GAAG,GAAG,gBAAgB,eAAe,QAAQ;;;;;;;CAQ/F,WAAW,KAAe,SAAiD;AACzE,SAAO,KAAK,OAAO,QACjB,UACA,GAAG,KAAK,SAAS,eACjB,EAAE,KAAK,EACP,QACD;;;CAIH,YAAY,WAAmB,SAAqD;AAClF,SAAO,KAAK,OAAO,IAAc,gCAAgC,UAAU,YAAY,QAAQ"}
|