@@ -3430,7 +3430,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
3430
3430
/**
3431
3431
* Creates a poll
3432
3432
* @param params PollData The poll that will be created
3433
- * @returns {APIResponse & PollResponse } The poll
3433
+ * @returns {APIResponse & CreatePollAPIResponse } The poll
3434
3434
*/
3435
3435
async createPoll ( poll : PollData ) {
3436
3436
return await this . post < APIResponse & CreatePollAPIResponse > ( this . baseURL + `/polls` , poll ) ;
@@ -3439,9 +3439,9 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
3439
3439
/**
3440
3440
* Retrieves a poll
3441
3441
* @param id string The poll id
3442
- * @returns {APIResponse & PollResponse } The poll
3442
+ * @returns {APIResponse & GetPollAPIResponse } The poll
3443
3443
*/
3444
- async getPoll ( id : string , userId ?: string ) {
3444
+ async getPoll ( id : string , userId ?: string ) : Promise < APIResponse & GetPollAPIResponse > {
3445
3445
return await this . get < APIResponse & GetPollAPIResponse > ( this . baseURL + `/polls/${ id } ` , {
3446
3446
...( userId ? { user_id : userId } : { } ) ,
3447
3447
} ) ;
@@ -3457,13 +3457,16 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
3457
3457
}
3458
3458
3459
3459
/**
3460
- * Partically updates a poll
3460
+ * Partially updates a poll
3461
3461
* @param id string The poll id
3462
3462
* @param {PartialPollUpdate<StreamChatGenerics> } partialPollObject which should contain id and any of "set" or "unset" params;
3463
3463
* example: {id: "44f26af5-f2be-4fa7-9dac-71cf893781de", set:{field: value}, unset:["field2"]}
3464
- * @returns {APIResponse & PollResponse } The poll
3464
+ * @returns {APIResponse & UpdatePollAPIResponse } The poll
3465
3465
*/
3466
- async partialUpdatePoll ( id : string , partialPollObject : PartialPollUpdate ) {
3466
+ async partialUpdatePoll (
3467
+ id : string ,
3468
+ partialPollObject : PartialPollUpdate ,
3469
+ ) : Promise < APIResponse & UpdatePollAPIResponse > {
3467
3470
return await this . patch < APIResponse & UpdatePollAPIResponse > ( this . baseURL + `/polls/${ id } ` , partialPollObject ) ;
3468
3471
}
3469
3472
@@ -3479,6 +3482,19 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
3479
3482
} ) ;
3480
3483
}
3481
3484
3485
+ /**
3486
+ * Close a poll
3487
+ * @param id string The poll id
3488
+ * @returns {APIResponse & UpdatePollAPIResponse } The poll
3489
+ */
3490
+ async closePoll ( id : string ) : Promise < APIResponse & UpdatePollAPIResponse > {
3491
+ return this . partialUpdatePoll ( id , {
3492
+ set : {
3493
+ is_closed : true ,
3494
+ }
3495
+ } ) ;
3496
+ }
3497
+
3482
3498
/**
3483
3499
* Creates a poll option
3484
3500
* @param pollId string The poll id
@@ -3525,10 +3541,11 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
3525
3541
}
3526
3542
3527
3543
/**
3528
- * Cast or cancel one or more votes on a poll
3544
+ * Cast vote on a poll
3545
+ * @param messageId string The message id
3529
3546
* @param pollId string The poll id
3530
- * @param votes PollVoteData[] The votes that will be casted (or canceled in case of an empty array)
3531
- * @returns {APIResponse & PollVotesAPIResponse } The poll votes
3547
+ * @param vote PollVoteData The vote that will be casted
3548
+ * @returns {APIResponse & CastVoteAPIResponse } The poll vote
3532
3549
*/
3533
3550
async castPollVote ( messageId : string , pollId : string , vote : PollVoteData , options = { } ) {
3534
3551
return await this . post < APIResponse & CastVoteAPIResponse > (
@@ -3537,6 +3554,18 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
3537
3554
) ;
3538
3555
}
3539
3556
3557
+ /**
3558
+ * Add a poll answer
3559
+ * @param messageId string The message id
3560
+ * @param pollId string The poll id
3561
+ * @param answerText string The answer text
3562
+ */
3563
+ async addPollAnswer ( messageId : string , pollId : string , answerText : string ) {
3564
+ return this . castPollVote ( messageId , pollId , {
3565
+ answer_text : answerText
3566
+ } ) ;
3567
+ }
3568
+
3540
3569
async removePollVote ( messageId : string , pollId : string , voteId : string ) {
3541
3570
return await this . delete < APIResponse & { vote : PollVote } > (
3542
3571
this . baseURL + `/messages/${ messageId } /polls/${ pollId } /vote/${ voteId } ` ,
0 commit comments