1
1
import { Readable } from "stream" ;
2
2
import HTTPClient from "./http" ;
3
3
import * as Types from "./types" ;
4
- import { AxiosResponse } from "axios" ;
4
+ import { AxiosResponse , AxiosRequestConfig } from "axios" ;
5
5
6
6
import { ensureJSON , toArray } from "./utils" ;
7
7
@@ -27,6 +27,7 @@ export default class Client {
27
27
Authorization : "Bearer " + this . config . channelAccessToken ,
28
28
} ,
29
29
responseParser : this . parseHTTPResponse . bind ( this ) ,
30
+ ...config . httpConfig ,
30
31
} ) ;
31
32
}
32
33
@@ -78,6 +79,22 @@ export default class Client {
78
79
} ) ;
79
80
}
80
81
82
+ public async narrowcast (
83
+ messages : Types . Message | Types . Message [ ] ,
84
+ recipient ?: Types . ReceieptObject ,
85
+ filter ?: { demographic : Types . DemographicFilterObject } ,
86
+ limit ?: { max : number } ,
87
+ notificationDisabled : boolean = false ,
88
+ ) : Promise < Types . MessageAPIResponseBase > {
89
+ return this . http . post ( `${ MESSAGING_API_PREFIX } /message/narrowcast` , {
90
+ messages : toArray ( messages ) ,
91
+ recipient,
92
+ filter,
93
+ limit,
94
+ notificationDisabled,
95
+ } ) ;
96
+ }
97
+
81
98
public async broadcast (
82
99
messages : Types . Message | Types . Message [ ] ,
83
100
notificationDisabled : boolean = false ,
@@ -303,6 +320,15 @@ export default class Client {
303
320
return ensureJSON ( res ) ;
304
321
}
305
322
323
+ public async getNarrowcastProgress (
324
+ requestId : string ,
325
+ ) : Promise < Types . NarrowcastProgressResponse > {
326
+ const res = await this . http . get < Types . NarrowcastProgressResponse > (
327
+ `${ MESSAGING_API_PREFIX } /message/progress/narrowcast?requestId=${ requestId } ` ,
328
+ ) ;
329
+ return ensureJSON ( res ) ;
330
+ }
331
+
306
332
public async getTargetLimitForAdditionalMessages ( ) : Promise <
307
333
Types . TargetLimitForAdditionalMessages
308
334
> {
@@ -363,6 +389,146 @@ export default class Client {
363
389
) ;
364
390
return ensureJSON ( res ) ;
365
391
}
392
+
393
+ public async createUploadAudienceGroup ( uploadAudienceGroup : {
394
+ description : string ;
395
+ isIfaAudience : boolean ;
396
+ audiences : { id : string } [ ] ;
397
+ uploadDescription ?: string ;
398
+ } ) {
399
+ const res = await this . http . post < {
400
+ audienceGroupId : number ;
401
+ type : string ;
402
+ description : string ;
403
+ created : number ;
404
+ } > ( `${ MESSAGING_API_PREFIX } /audienceGroup/upload` , {
405
+ ...uploadAudienceGroup ,
406
+ } ) ;
407
+ return ensureJSON ( res ) ;
408
+ }
409
+
410
+ public async updateUploadAudienceGroup (
411
+ uploadAudienceGroup : {
412
+ audienceGroupId : number ;
413
+ description ?: string ;
414
+ uploadDescription ?: string ;
415
+ audiences : { id : string } [ ] ;
416
+ } ,
417
+ // for set request timeout
418
+ httpConfig ?: Partial < AxiosRequestConfig > ,
419
+ ) {
420
+ const res = await this . http . put < { } > (
421
+ `${ MESSAGING_API_PREFIX } /audienceGroup/upload` ,
422
+ {
423
+ ...uploadAudienceGroup ,
424
+ } ,
425
+ httpConfig ,
426
+ ) ;
427
+ return ensureJSON ( res ) ;
428
+ }
429
+
430
+ public async createClickAudienceGroup ( clickAudienceGroup : {
431
+ description : string ;
432
+ requestId : string ;
433
+ clickUrl ?: string ;
434
+ } ) {
435
+ const res = await this . http . post <
436
+ {
437
+ audienceGroupId : number ;
438
+ type : string ;
439
+ created : number ;
440
+ } & typeof clickAudienceGroup
441
+ > ( `${ MESSAGING_API_PREFIX } /audienceGroup/click` , {
442
+ ...clickAudienceGroup ,
443
+ } ) ;
444
+ return ensureJSON ( res ) ;
445
+ }
446
+
447
+ public async createImpAudienceGroup ( impAudienceGroup : {
448
+ requestId : string ;
449
+ description : string ;
450
+ } ) {
451
+ const res = await this . http . post <
452
+ {
453
+ audienceGroupId : number ;
454
+ type : string ;
455
+ created : number ;
456
+ } & typeof impAudienceGroup
457
+ > ( `${ MESSAGING_API_PREFIX } /audienceGroup/imp` , {
458
+ ...impAudienceGroup ,
459
+ } ) ;
460
+ return ensureJSON ( res ) ;
461
+ }
462
+
463
+ public async setDescriptionAudienceGroup (
464
+ description : string ,
465
+ audienceGroupId : string ,
466
+ ) {
467
+ const res = await this . http . put < { } > (
468
+ `${ MESSAGING_API_PREFIX } /audienceGroup/${ audienceGroupId } /updateDescription` ,
469
+ {
470
+ description,
471
+ } ,
472
+ ) ;
473
+ return ensureJSON ( res ) ;
474
+ }
475
+
476
+ public async deleteAudienceGroup ( audienceGroupId : string ) {
477
+ const res = await this . http . delete < { } > (
478
+ `${ MESSAGING_API_PREFIX } /audienceGroup/${ audienceGroupId } ` ,
479
+ ) ;
480
+ return ensureJSON ( res ) ;
481
+ }
482
+
483
+ public async getAudienceGroup ( audienceGroupId : string ) {
484
+ const res = await this . http . get < Types . AudienceGroup > (
485
+ `${ MESSAGING_API_PREFIX } /audienceGroup/${ audienceGroupId } ` ,
486
+ ) ;
487
+ return ensureJSON ( res ) ;
488
+ }
489
+
490
+ public async getAudienceGroups (
491
+ page : number ,
492
+ description ?: string ,
493
+ status ?: Types . AudienceGroupStatus ,
494
+ size ?: number ,
495
+ createRoute ?: Types . AudienceGroupCreateRoute ,
496
+ includesExternalPublicGroups ?: boolean ,
497
+ ) {
498
+ const res = await this . http . get < {
499
+ audienceGroups : Types . AudienceGroups ;
500
+ hasNextPage : boolean ;
501
+ totalCount : number ;
502
+ readWriteAudienceGroupTotalCount : number ;
503
+ page : number ;
504
+ size : number ;
505
+ } > ( `${ MESSAGING_API_PREFIX } /audienceGroup/list` , {
506
+ page,
507
+ description,
508
+ status,
509
+ size,
510
+ createRoute,
511
+ includesExternalPublicGroups,
512
+ } ) ;
513
+ return ensureJSON ( res ) ;
514
+ }
515
+
516
+ public async getAudienceGroupAuthorityLevel ( ) {
517
+ const res = await this . http . get < {
518
+ authorityLevel : Types . AudienceGroupAuthorityLevel ;
519
+ } > ( `${ MESSAGING_API_PREFIX } /audienceGroup/authorityLevel` ) ;
520
+ return ensureJSON ( res ) ;
521
+ }
522
+
523
+ public async changeAudienceGroupAuthorityLevel (
524
+ authorityLevel : Types . AudienceGroupAuthorityLevel ,
525
+ ) {
526
+ const res = await this . http . put < { } > (
527
+ `${ MESSAGING_API_PREFIX } /audienceGroup/authorityLevel` ,
528
+ { authorityLevel } ,
529
+ ) ;
530
+ return ensureJSON ( res ) ;
531
+ }
366
532
}
367
533
368
534
export class OAuth {
0 commit comments