feat(client): closePoll method
This commit is contained in:
parent
9df884e667
commit
8a0c9984b5
4 changed files with 83 additions and 0 deletions
|
@ -60,6 +60,7 @@ import { _normalizeFileToDocument } from './methods/files/normalize-file-to-docu
|
|||
import { _normalizeInputFile } from './methods/files/normalize-input-file'
|
||||
import { _normalizeInputMedia } from './methods/files/normalize-input-media'
|
||||
import { uploadFile } from './methods/files/upload-file'
|
||||
import { closePoll } from './methods/messages/close-poll'
|
||||
import { deleteMessages } from './methods/messages/delete-messages'
|
||||
import { editInlineMessage } from './methods/messages/edit-inline-message'
|
||||
import { editMessage } from './methods/messages/edit-message'
|
||||
|
@ -1178,6 +1179,16 @@ export interface TelegramClient extends BaseTelegramClient {
|
|||
*/
|
||||
progressCallback?: (uploaded: number, total: number) => void
|
||||
}): Promise<UploadedFile>
|
||||
/**
|
||||
* Close a poll sent by you.
|
||||
*
|
||||
* Once closed, poll can't be re-opened, and nobody
|
||||
* will be able to vote in it
|
||||
*
|
||||
* @param chatId Chat ID where this poll was found
|
||||
* @param message Message ID where this poll was found
|
||||
*/
|
||||
closePoll(chatId: InputPeerLike, message: number): Promise<Poll>
|
||||
/**
|
||||
* Delete messages, including service messages.
|
||||
*
|
||||
|
@ -2249,6 +2260,7 @@ export class TelegramClient extends BaseTelegramClient {
|
|||
protected _normalizeInputFile = _normalizeInputFile
|
||||
protected _normalizeInputMedia = _normalizeInputMedia
|
||||
uploadFile = uploadFile
|
||||
closePoll = closePoll
|
||||
deleteMessages = deleteMessages
|
||||
editInlineMessage = editInlineMessage
|
||||
editMessage = editMessage
|
||||
|
|
|
@ -178,6 +178,7 @@ export async function _normalizeInputMedia(
|
|||
_: 'inputMediaPoll',
|
||||
poll: {
|
||||
_: 'poll',
|
||||
closed: media.closed,
|
||||
id: bigInt.zero,
|
||||
publicVoters: media.public,
|
||||
multipleChoice: media.multiple,
|
||||
|
|
64
packages/client/src/methods/messages/close-poll.ts
Normal file
64
packages/client/src/methods/messages/close-poll.ts
Normal file
|
@ -0,0 +1,64 @@
|
|||
import { TelegramClient } from '../../client'
|
||||
import { InputPeerLike, MtCuteTypeAssertionError, Poll } from '../../types'
|
||||
import { tl } from '@mtcute/tl'
|
||||
import {
|
||||
createUsersChatsIndex,
|
||||
normalizeToInputPeer,
|
||||
} from '../../utils/peer-utils'
|
||||
import bigInt from 'big-integer'
|
||||
import { assertTypeIs } from '../../utils/type-assertion'
|
||||
|
||||
/**
|
||||
* Close a poll sent by you.
|
||||
*
|
||||
* Once closed, poll can't be re-opened, and nobody
|
||||
* will be able to vote in it
|
||||
*
|
||||
* @param chatId Chat ID where this poll was found
|
||||
* @param message Message ID where this poll was found
|
||||
* @internal
|
||||
*/
|
||||
export async function closePoll(
|
||||
this: TelegramClient,
|
||||
chatId: InputPeerLike,
|
||||
message: number
|
||||
): Promise<Poll> {
|
||||
const res = await this.call({
|
||||
_: 'messages.editMessage',
|
||||
peer: normalizeToInputPeer(await this.resolvePeer(chatId)),
|
||||
id: message,
|
||||
media: {
|
||||
_: 'inputMediaPoll',
|
||||
poll: {
|
||||
_: 'poll',
|
||||
id: bigInt.zero,
|
||||
closed: true,
|
||||
question: '',
|
||||
answers: [],
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
if (!(res._ === 'updates' || res._ === 'updatesCombined'))
|
||||
throw new MtCuteTypeAssertionError(
|
||||
'_findMessageInUpdate',
|
||||
'updates | updatesCombined',
|
||||
res._
|
||||
)
|
||||
|
||||
this._handleUpdate(res, true)
|
||||
|
||||
const upd = res.updates[0]
|
||||
assertTypeIs('closePoll (@ messages.editMessage)', upd, 'updateMessagePoll')
|
||||
if (!upd.poll) {
|
||||
throw new MtCuteTypeAssertionError(
|
||||
'closePoll (@ messages.editMessage)',
|
||||
'poll',
|
||||
'undefined'
|
||||
)
|
||||
}
|
||||
|
||||
const { users } = createUsersChatsIndex(res)
|
||||
|
||||
return new Poll(this, upd.poll, users, upd.results)
|
||||
}
|
|
@ -449,6 +449,12 @@ export interface InputMediaPoll {
|
|||
*/
|
||||
answers: (string | tl.TypePollAnswer)[]
|
||||
|
||||
/**
|
||||
* Whether this is poll is closed
|
||||
* (i.e. nobody can vote anymore)
|
||||
*/
|
||||
closed?: boolean
|
||||
|
||||
/**
|
||||
* Whether this is a public poll
|
||||
* (i.e. users who have voted are visible to everyone)
|
||||
|
|
Loading…
Reference in a new issue