-
Notifications
You must be signed in to change notification settings - Fork 395
/
manageAudienceClient.ts
465 lines (438 loc) · 18.4 KB
/
manageAudienceClient.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
/**
* LINE Messaging API
* This document describes LINE Messaging API.
*
* The version of the OpenAPI document: 0.0.1
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
/* tslint:disable:no-unused-locals */
import { AddAudienceToAudienceGroupRequest } from "../model/addAudienceToAudienceGroupRequest.js";
import { AudienceGroupCreateRoute } from "../model/audienceGroupCreateRoute.js";
import { AudienceGroupStatus } from "../model/audienceGroupStatus.js";
import { CreateAudienceGroupRequest } from "../model/createAudienceGroupRequest.js";
import { CreateAudienceGroupResponse } from "../model/createAudienceGroupResponse.js";
import { CreateClickBasedAudienceGroupRequest } from "../model/createClickBasedAudienceGroupRequest.js";
import { CreateClickBasedAudienceGroupResponse } from "../model/createClickBasedAudienceGroupResponse.js";
import { CreateImpBasedAudienceGroupRequest } from "../model/createImpBasedAudienceGroupRequest.js";
import { CreateImpBasedAudienceGroupResponse } from "../model/createImpBasedAudienceGroupResponse.js";
import { ErrorResponse } from "../model/errorResponse.js";
import { GetAudienceDataResponse } from "../model/getAudienceDataResponse.js";
import { GetAudienceGroupAuthorityLevelResponse } from "../model/getAudienceGroupAuthorityLevelResponse.js";
import { GetAudienceGroupsResponse } from "../model/getAudienceGroupsResponse.js";
import { UpdateAudienceGroupAuthorityLevelRequest } from "../model/updateAudienceGroupAuthorityLevelRequest.js";
import { UpdateAudienceGroupDescriptionRequest } from "../model/updateAudienceGroupDescriptionRequest.js";
import * as Types from "../../types.js";
import { ensureJSON } from "../../utils.js";
import { Readable } from "node:stream";
import HTTPFetchClient, {
convertResponseToReadable,
} from "../../http-fetch.js";
// ===============================================
// This file is autogenerated - Please do not edit
// ===============================================
interface httpClientConfig {
baseURL?: string;
channelAccessToken: string;
// TODO support defaultHeaders?
}
export class ManageAudienceClient {
private httpClient: HTTPFetchClient;
constructor(config: httpClientConfig) {
const baseURL = config.baseURL || "https://api.line.me";
this.httpClient = new HTTPFetchClient({
defaultHeaders: {
Authorization: "Bearer " + config.channelAccessToken,
},
baseURL: baseURL,
});
}
private async parseHTTPResponse(response: Response) {
const { LINE_REQUEST_ID_HTTP_HEADER_NAME } = Types;
let resBody: Record<string, any> = {
...(await response.json()),
};
if (response.headers.get(LINE_REQUEST_ID_HTTP_HEADER_NAME)) {
resBody[LINE_REQUEST_ID_HTTP_HEADER_NAME] = response.headers.get(
LINE_REQUEST_ID_HTTP_HEADER_NAME,
);
}
return resBody;
}
/**
* Activate audience
* @param audienceGroupId The audience ID.
*
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#activate-audience-group"> Documentation</a>
*/
public async activateAudienceGroup(
audienceGroupId: number,
): Promise<Types.MessageAPIResponseBase> {
return (await this.activateAudienceGroupWithHttpInfo(audienceGroupId)).body;
}
/**
* Activate audience.
* This method includes HttpInfo object to return additional information.
* @param audienceGroupId The audience ID.
*
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#activate-audience-group"> Documentation</a>
*/
public async activateAudienceGroupWithHttpInfo(
audienceGroupId: number,
): Promise<Types.ApiResponseType<Types.MessageAPIResponseBase>> {
const res = await this.httpClient.put(
"/v2/bot/audienceGroup/{audienceGroupId}/activate".replace(
"{audienceGroupId}",
String(audienceGroupId),
),
);
return { httpResponse: res, body: await res.json() };
}
/**
* Add user IDs or Identifiers for Advertisers (IFAs) to an audience for uploading user IDs (by JSON)
* @param addAudienceToAudienceGroupRequest
*
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#update-upload-audience-group"> Documentation</a>
*/
public async addAudienceToAudienceGroup(
addAudienceToAudienceGroupRequest: AddAudienceToAudienceGroupRequest,
): Promise<Types.MessageAPIResponseBase> {
return (
await this.addAudienceToAudienceGroupWithHttpInfo(
addAudienceToAudienceGroupRequest,
)
).body;
}
/**
* Add user IDs or Identifiers for Advertisers (IFAs) to an audience for uploading user IDs (by JSON).
* This method includes HttpInfo object to return additional information.
* @param addAudienceToAudienceGroupRequest
*
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#update-upload-audience-group"> Documentation</a>
*/
public async addAudienceToAudienceGroupWithHttpInfo(
addAudienceToAudienceGroupRequest: AddAudienceToAudienceGroupRequest,
): Promise<Types.ApiResponseType<Types.MessageAPIResponseBase>> {
const params = addAudienceToAudienceGroupRequest;
const res = await this.httpClient.put(
"/v2/bot/audienceGroup/upload",
params,
);
return { httpResponse: res, body: await res.json() };
}
/**
* Create audience for uploading user IDs (by JSON)
* @param createAudienceGroupRequest
*
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#create-upload-audience-group"> Documentation</a>
*/
public async createAudienceGroup(
createAudienceGroupRequest: CreateAudienceGroupRequest,
): Promise<CreateAudienceGroupResponse> {
return (
await this.createAudienceGroupWithHttpInfo(createAudienceGroupRequest)
).body;
}
/**
* Create audience for uploading user IDs (by JSON).
* This method includes HttpInfo object to return additional information.
* @param createAudienceGroupRequest
*
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#create-upload-audience-group"> Documentation</a>
*/
public async createAudienceGroupWithHttpInfo(
createAudienceGroupRequest: CreateAudienceGroupRequest,
): Promise<Types.ApiResponseType<CreateAudienceGroupResponse>> {
const params = createAudienceGroupRequest;
const res = await this.httpClient.post(
"/v2/bot/audienceGroup/upload",
params,
);
return { httpResponse: res, body: await res.json() };
}
/**
* Create audience for click-based retargeting
* @param createClickBasedAudienceGroupRequest
*
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#create-click-audience-group"> Documentation</a>
*/
public async createClickBasedAudienceGroup(
createClickBasedAudienceGroupRequest: CreateClickBasedAudienceGroupRequest,
): Promise<CreateClickBasedAudienceGroupResponse> {
return (
await this.createClickBasedAudienceGroupWithHttpInfo(
createClickBasedAudienceGroupRequest,
)
).body;
}
/**
* Create audience for click-based retargeting.
* This method includes HttpInfo object to return additional information.
* @param createClickBasedAudienceGroupRequest
*
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#create-click-audience-group"> Documentation</a>
*/
public async createClickBasedAudienceGroupWithHttpInfo(
createClickBasedAudienceGroupRequest: CreateClickBasedAudienceGroupRequest,
): Promise<Types.ApiResponseType<CreateClickBasedAudienceGroupResponse>> {
const params = createClickBasedAudienceGroupRequest;
const res = await this.httpClient.post(
"/v2/bot/audienceGroup/click",
params,
);
return { httpResponse: res, body: await res.json() };
}
/**
* Create audience for impression-based retargeting
* @param createImpBasedAudienceGroupRequest
*
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#create-imp-audience-group"> Documentation</a>
*/
public async createImpBasedAudienceGroup(
createImpBasedAudienceGroupRequest: CreateImpBasedAudienceGroupRequest,
): Promise<CreateImpBasedAudienceGroupResponse> {
return (
await this.createImpBasedAudienceGroupWithHttpInfo(
createImpBasedAudienceGroupRequest,
)
).body;
}
/**
* Create audience for impression-based retargeting.
* This method includes HttpInfo object to return additional information.
* @param createImpBasedAudienceGroupRequest
*
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#create-imp-audience-group"> Documentation</a>
*/
public async createImpBasedAudienceGroupWithHttpInfo(
createImpBasedAudienceGroupRequest: CreateImpBasedAudienceGroupRequest,
): Promise<Types.ApiResponseType<CreateImpBasedAudienceGroupResponse>> {
const params = createImpBasedAudienceGroupRequest;
const res = await this.httpClient.post("/v2/bot/audienceGroup/imp", params);
return { httpResponse: res, body: await res.json() };
}
/**
* Delete audience
* @param audienceGroupId The audience ID.
*
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#delete-audience-group"> Documentation</a>
*/
public async deleteAudienceGroup(
audienceGroupId: number,
): Promise<Types.MessageAPIResponseBase> {
return (await this.deleteAudienceGroupWithHttpInfo(audienceGroupId)).body;
}
/**
* Delete audience.
* This method includes HttpInfo object to return additional information.
* @param audienceGroupId The audience ID.
*
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#delete-audience-group"> Documentation</a>
*/
public async deleteAudienceGroupWithHttpInfo(
audienceGroupId: number,
): Promise<Types.ApiResponseType<Types.MessageAPIResponseBase>> {
const res = await this.httpClient.delete(
"/v2/bot/audienceGroup/{audienceGroupId}".replace(
"{audienceGroupId}",
String(audienceGroupId),
),
);
return { httpResponse: res, body: await res.json() };
}
/**
* Gets audience data.
* @param audienceGroupId The audience ID.
*
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#get-audience-group"> Documentation</a>
*/
public async getAudienceData(
audienceGroupId: number,
): Promise<GetAudienceDataResponse> {
return (await this.getAudienceDataWithHttpInfo(audienceGroupId)).body;
}
/**
* Gets audience data..
* This method includes HttpInfo object to return additional information.
* @param audienceGroupId The audience ID.
*
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#get-audience-group"> Documentation</a>
*/
public async getAudienceDataWithHttpInfo(
audienceGroupId: number,
): Promise<Types.ApiResponseType<GetAudienceDataResponse>> {
const res = await this.httpClient.get(
"/v2/bot/audienceGroup/{audienceGroupId}".replace(
"{audienceGroupId}",
String(audienceGroupId),
),
);
return { httpResponse: res, body: await res.json() };
}
/**
* Get the authority level of the audience
*
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#get-authority-level"> Documentation</a>
*/
public async getAudienceGroupAuthorityLevel(): Promise<GetAudienceGroupAuthorityLevelResponse> {
return (await this.getAudienceGroupAuthorityLevelWithHttpInfo()).body;
}
/**
* Get the authority level of the audience.
* This method includes HttpInfo object to return additional information.
*
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#get-authority-level"> Documentation</a>
*/
public async getAudienceGroupAuthorityLevelWithHttpInfo(): Promise<
Types.ApiResponseType<GetAudienceGroupAuthorityLevelResponse>
> {
const res = await this.httpClient.get(
"/v2/bot/audienceGroup/authorityLevel",
);
return { httpResponse: res, body: await res.json() };
}
/**
* Gets data for more than one audience.
* @param page The page to return when getting (paginated) results. Must be 1 or higher.
* @param description The name of the audience(s) to return. You can search for partial matches. This is case-insensitive, meaning AUDIENCE and audience are considered identical. If omitted, the name of the audience(s) will not be used as a search criterion.
* @param status The status of the audience(s) to return. If omitted, the status of the audience(s) will not be used as a search criterion.
* @param size The number of audiences per page. Default: 20 Max: 40
* @param includesExternalPublicGroups true (default): Get public audiences created in all channels linked to the same bot. false: Get audiences created in the same channel.
* @param createRoute How the audience was created. If omitted, all audiences are included. `OA_MANAGER`: Return only audiences created with LINE Official Account Manager (opens new window). `MESSAGING_API`: Return only audiences created with Messaging API.
*
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#get-audience-groups"> Documentation</a>
*/
public async getAudienceGroups(
page: number,
description?: string,
status?: AudienceGroupStatus,
size?: number,
includesExternalPublicGroups?: boolean,
createRoute?: AudienceGroupCreateRoute,
): Promise<GetAudienceGroupsResponse> {
return (
await this.getAudienceGroupsWithHttpInfo(
page,
description,
status,
size,
includesExternalPublicGroups,
createRoute,
)
).body;
}
/**
* Gets data for more than one audience..
* This method includes HttpInfo object to return additional information.
* @param page The page to return when getting (paginated) results. Must be 1 or higher.
* @param description The name of the audience(s) to return. You can search for partial matches. This is case-insensitive, meaning AUDIENCE and audience are considered identical. If omitted, the name of the audience(s) will not be used as a search criterion.
* @param status The status of the audience(s) to return. If omitted, the status of the audience(s) will not be used as a search criterion.
* @param size The number of audiences per page. Default: 20 Max: 40
* @param includesExternalPublicGroups true (default): Get public audiences created in all channels linked to the same bot. false: Get audiences created in the same channel.
* @param createRoute How the audience was created. If omitted, all audiences are included. `OA_MANAGER`: Return only audiences created with LINE Official Account Manager (opens new window). `MESSAGING_API`: Return only audiences created with Messaging API.
*
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#get-audience-groups"> Documentation</a>
*/
public async getAudienceGroupsWithHttpInfo(
page: number,
description?: string,
status?: AudienceGroupStatus,
size?: number,
includesExternalPublicGroups?: boolean,
createRoute?: AudienceGroupCreateRoute,
): Promise<Types.ApiResponseType<GetAudienceGroupsResponse>> {
const queryParams = {
page: page,
description: description,
status: status,
size: size,
includesExternalPublicGroups: includesExternalPublicGroups,
createRoute: createRoute,
};
Object.keys(queryParams).forEach((key: keyof typeof queryParams) => {
if (queryParams[key] === undefined) {
delete queryParams[key];
}
});
const res = await this.httpClient.get(
"/v2/bot/audienceGroup/list",
queryParams,
);
return { httpResponse: res, body: await res.json() };
}
/**
* Change the authority level of the audience
* @param updateAudienceGroupAuthorityLevelRequest
*
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#change-authority-level"> Documentation</a>
*/
public async updateAudienceGroupAuthorityLevel(
updateAudienceGroupAuthorityLevelRequest: UpdateAudienceGroupAuthorityLevelRequest,
): Promise<Types.MessageAPIResponseBase> {
return (
await this.updateAudienceGroupAuthorityLevelWithHttpInfo(
updateAudienceGroupAuthorityLevelRequest,
)
).body;
}
/**
* Change the authority level of the audience.
* This method includes HttpInfo object to return additional information.
* @param updateAudienceGroupAuthorityLevelRequest
*
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#change-authority-level"> Documentation</a>
*/
public async updateAudienceGroupAuthorityLevelWithHttpInfo(
updateAudienceGroupAuthorityLevelRequest: UpdateAudienceGroupAuthorityLevelRequest,
): Promise<Types.ApiResponseType<Types.MessageAPIResponseBase>> {
const params = updateAudienceGroupAuthorityLevelRequest;
const res = await this.httpClient.put(
"/v2/bot/audienceGroup/authorityLevel",
params,
);
return { httpResponse: res, body: await res.json() };
}
/**
* Renames an existing audience.
* @param audienceGroupId The audience ID.
* @param updateAudienceGroupDescriptionRequest
*
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#set-description-audience-group"> Documentation</a>
*/
public async updateAudienceGroupDescription(
audienceGroupId: number,
updateAudienceGroupDescriptionRequest: UpdateAudienceGroupDescriptionRequest,
): Promise<Types.MessageAPIResponseBase> {
return (
await this.updateAudienceGroupDescriptionWithHttpInfo(
audienceGroupId,
updateAudienceGroupDescriptionRequest,
)
).body;
}
/**
* Renames an existing audience..
* This method includes HttpInfo object to return additional information.
* @param audienceGroupId The audience ID.
* @param updateAudienceGroupDescriptionRequest
*
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#set-description-audience-group"> Documentation</a>
*/
public async updateAudienceGroupDescriptionWithHttpInfo(
audienceGroupId: number,
updateAudienceGroupDescriptionRequest: UpdateAudienceGroupDescriptionRequest,
): Promise<Types.ApiResponseType<Types.MessageAPIResponseBase>> {
const params = updateAudienceGroupDescriptionRequest;
const res = await this.httpClient.put(
"/v2/bot/audienceGroup/{audienceGroupId}/updateDescription".replace(
"{audienceGroupId}",
String(audienceGroupId),
),
params,
);
return { httpResponse: res, body: await res.json() };
}
}