diff --git a/packages/client/src/types/media/input-media.ts b/packages/client/src/types/media/input-media.ts index 1ea9abdd..87b3e56a 100644 --- a/packages/client/src/types/media/input-media.ts +++ b/packages/client/src/types/media/input-media.ts @@ -5,12 +5,7 @@ import { InputFileLike } from '../files' import { Venue } from './venue' import { FormattedString } from '../parser' -interface BaseInputMedia { - /** - * File to be sent - */ - file: InputFileLike - +interface CaptionMixin { /** * Caption of the media */ @@ -21,6 +16,13 @@ interface BaseInputMedia { * If passed, parse mode is ignored */ entities?: tl.TypeMessageEntity[] +} + +interface FileMixin { + /** + * File to be sent + */ + file: InputFileLike /** * Override file name for the file. @@ -58,14 +60,14 @@ interface BaseInputMedia { * newly uploaded photos with `auto` will be * uploaded as a document */ -export interface InputMediaAuto extends BaseInputMedia { +export interface InputMediaAuto extends FileMixin, CaptionMixin { type: 'auto' } /** * An audio file or voice message to be sent */ -export interface InputMediaAudio extends BaseInputMedia { +export interface InputMediaAudio extends FileMixin, CaptionMixin { type: 'audio' /** @@ -104,7 +106,7 @@ export interface InputMediaAudio extends BaseInputMedia { /** * Voice message to be sent */ -export interface InputMediaVoice extends BaseInputMedia { +export interface InputMediaVoice extends FileMixin, CaptionMixin { type: 'voice' /** @@ -129,7 +131,7 @@ export interface InputMediaVoice extends BaseInputMedia { /** * A generic file to be sent */ -export interface InputMediaDocument extends BaseInputMedia { +export interface InputMediaDocument extends FileMixin, CaptionMixin { type: 'document' /** @@ -147,19 +149,16 @@ export interface InputMediaDocument extends BaseInputMedia { /** * A photo to be sent */ -export interface InputMediaPhoto extends BaseInputMedia { +export interface InputMediaPhoto extends FileMixin, CaptionMixin { type: 'photo' } /** * A sticker to be sent */ -export interface InputMediaSticker extends BaseInputMedia { +export interface InputMediaSticker extends FileMixin, CaptionMixin { type: 'sticker' - caption?: never - entities?: never - /** * Whether this sticker is animated? * @@ -184,7 +183,7 @@ export interface InputMediaSticker extends BaseInputMedia { /** * A video to be sent */ -export interface InputMediaVideo extends BaseInputMedia { +export interface InputMediaVideo extends FileMixin, CaptionMixin { type: 'video' /** @@ -244,7 +243,7 @@ export interface InputMediaVideo extends BaseInputMedia { /** * A geolocation to be sent */ -export interface InputMediaGeo { +export interface InputMediaGeo extends CaptionMixin { type: 'geo' /** @@ -301,7 +300,7 @@ export interface InputMediaGeoLive extends Omit { * Note that dice result value is generated randomly on the server, * you can't influence it in any way! */ -export interface InputMediaDice { +export interface InputMediaDice extends CaptionMixin { type: 'dice' /** @@ -313,7 +312,7 @@ export interface InputMediaDice { /** * A venue to be sent */ -export interface InputMediaVenue { +export interface InputMediaVenue extends CaptionMixin { type: 'venue' /** @@ -345,7 +344,7 @@ export interface InputMediaVenue { /** * A contact to be sent */ -export interface InputMediaContact { +export interface InputMediaContact extends CaptionMixin { type: 'contact' /** @@ -373,7 +372,7 @@ export interface InputMediaContact { /** * A game to be sent */ -export interface InputMediaGame { +export interface InputMediaGame extends CaptionMixin { type: 'game' /** @@ -385,7 +384,7 @@ export interface InputMediaGame { /** * An invoice to be sent (see https://core.telegram.org/bots/payments) */ -export interface InputMediaInvoice { +export interface InputMediaInvoice extends CaptionMixin { type: 'invoice' /** @@ -440,8 +439,12 @@ export interface InputMediaInvoice { /** * A simple poll to be sent + * + * > **Note**: when using user account, + * > the poll can't be sent to PMs, only to channels/groups, + * > otherwise there will be `MEDIA_INVALID` error. */ -export interface InputMediaPoll { +export interface InputMediaPoll extends CaptionMixin { type: 'poll' /** @@ -532,23 +535,6 @@ export interface InputMediaQuiz extends Omit { solutionEntities?: tl.TypeMessageEntity[] } -/** - * Input media that can have a caption. - * - * Note that meta-fields (like `duration`) are only - * applicable if `file` is {@link UploadFileLike}, - * otherwise they are ignored. - * - * A subset of {@link InputMediaLike} - */ -export type InputMediaWithCaption = - | InputMediaAudio - | InputMediaVoice - | InputMediaDocument - | InputMediaPhoto - | InputMediaVideo - | InputMediaAuto - /** * Input media that can be sent somewhere. * @@ -559,7 +545,12 @@ export type InputMediaWithCaption = * @link InputMedia */ export type InputMediaLike = - | InputMediaWithCaption + | InputMediaAudio + | InputMediaVoice + | InputMediaDocument + | InputMediaPhoto + | InputMediaVideo + | InputMediaAuto | InputMediaSticker | InputMediaVenue | InputMediaGeo @@ -752,12 +743,12 @@ export namespace InputMedia { * as static members of {@link Dice}. * * @param emoji Emoji representing the dice + * @param params Additional parameters */ - export function dice(emoji: string): InputMediaDice { - return { - type: 'dice', - emoji, - } + export function dice(emoji: string, params: CaptionMixin): InputMediaDice { + const ret = params as tl.Mutable + ret.type = 'dice' + return ret } /** diff --git a/packages/client/src/types/messages/draft-message.ts b/packages/client/src/types/messages/draft-message.ts index e08dfd1a..482cb2c9 100644 --- a/packages/client/src/types/messages/draft-message.ts +++ b/packages/client/src/types/messages/draft-message.ts @@ -5,8 +5,7 @@ import { MessageEntity } from './message-entity' import { Message } from './message' import { InputPeerLike } from '../peers' import { makeInspectable } from '../utils' -import { InputMediaWithCaption } from '../media' - +import { InputMediaLike } from '../media' /** * A draft message @@ -94,17 +93,14 @@ export class DraftMessage { * @link TelegramClient.sendMedia */ sendWithMedia( - media: InputMediaWithCaption, + media: InputMediaLike, params?: Parameters[2] ): Promise { - if (!media.caption) { - media.caption = this.raw.message - media.entities = this.raw.entities - } - return this.client.sendMedia(this._chatId, media, { clearDraft: true, replyTo: this.raw.replyToMsgId, + caption: this.raw.message, + entities: this.raw.entities, ...(params || {}), }) }