diff --git a/packages/client/src/types/bots/input/input-inline-message.ts b/packages/client/src/types/bots/input/input-inline-message.ts index 8ad9967f..50230747 100644 --- a/packages/client/src/types/bots/input/input-inline-message.ts +++ b/packages/client/src/types/bots/input/input-inline-message.ts @@ -5,7 +5,6 @@ import { InputMediaGeo, InputMediaGeoLive, InputMediaVenue, - Venue, } from '../../media' /** @@ -111,73 +110,99 @@ export type InputInlineMessage = | InputInlineMessageGame export namespace BotInlineMessage { + /** + * Create a text inline message + * + * @param text Message text + * @param params + */ export function text( text: string, - params?: Omit + params: Omit = {} ): InputInlineMessageText { - return { - type: 'text', - text, - ...(params || {}), - } + const ret = params as tl.Mutable + ret.type = 'text' + ret.text = text + return ret } + /** + * Create an inline message containing + * media from the result + */ export function media( - params?: Omit + params: Omit = {} ): InputInlineMessageMedia { - return { - type: 'media', - ...(params || {}), - } + const ret = params as tl.Mutable + ret.type = 'media' + return ret } + /** + * Create an inline message containing a geolocation + * + * @param latitude Latitude of the location + * @param longitude Longitude of the location + * @param params Additional parameters + */ export function geo( latitude: number, longitude: number, - params?: Omit + params: Omit = {} ): InputInlineMessageGeo { - return { - type: 'geo', - latitude, - longitude, - ...(params || {}), - } + const ret = params as tl.Mutable + ret.type = 'geo' + ret.latitude = latitude + ret.longitude = longitude + return ret } + /** + * Create an inline message containing a live geolocation + * + * @param latitude Latitude of the current location + * @param longitude Longitude of the current location + * @param params Additional parameters + */ export function geoLive( latitude: number, longitude: number, - params?: Omit< + params: Omit< InputInlineMessageGeoLive, 'type' | 'latitude' | 'longitude' - > + > = {} ): InputInlineMessageGeoLive { - return { - type: 'geo_live', - latitude, - longitude, - ...(params || {}), - } + const ret = params as tl.Mutable + ret.type = 'geo_live' + ret.latitude = latitude + ret.longitude = longitude + return ret } + /** + * Create an inline message containing a venue + */ export function venue( params: Omit ): InputInlineMessageVenue { - return { - type: 'venue', - ...params, - } + const ret = params as tl.Mutable + ret.type = 'venue' + return ret } + /** + * Create an inline message containing a game + * from the inline result + */ export function game( params: Omit ): InputInlineMessageGame { - return { - type: 'game', - ...params, - } + const ret = params as tl.Mutable + ret.type = 'game' + return ret } + /** @internal */ export async function _convertToTl( client: TelegramClient, obj: InputInlineMessage, diff --git a/packages/client/src/types/bots/input/input-inline-result.ts b/packages/client/src/types/bots/input/input-inline-result.ts index 31f9e0e1..10229fb0 100644 --- a/packages/client/src/types/bots/input/input-inline-result.ts +++ b/packages/client/src/types/bots/input/input-inline-result.ts @@ -1,5 +1,5 @@ import { tl } from '@mtcute/tl' -import { BotInlineMessage, InputInlineMessage } from './input-inline-message' +import { BotInlineMessage, InputInlineMessage, InputInlineMessageGame } from './input-inline-message' import { TelegramClient } from '../../../client' import { fileIdToInputDocument, fileIdToInputPhoto } from '@mtcute/file-id' import { extractFileName } from '../../../utils/file-utils' @@ -480,82 +480,123 @@ export type InputInlineResult = | InputInlineResultContact export namespace BotInline { + /** + * Create an inline result containing an article + * + * @param id Inline result ID + * @param params Article + */ export function article( id: string, params: Omit ): InputInlineResultArticle { - return { - id, - type: 'article', - ...params, - } + const ret = params as tl.Mutable + ret.id = id + ret.type = 'article' + return ret } + /** + * Create an inline result containing a GIF + * + * @param id Inline result ID + * @param media GIF animation + * @param params Additional parameters + */ export function gif( id: string, media: string | tl.RawInputWebDocument | tl.RawInputDocument, - params: Omit + params: Omit = {} ): InputInlineResultGif { - return { - id, - media, - type: 'gif', - ...params, - } + const ret = params as tl.Mutable + ret.id = id + ret.type = 'gif' + ret.media = media + return ret } + /** + * Create an inline result containing a video + * + * @param id Inline result ID + * @param media Video + * @param params Additional parameters + */ export function video( id: string, media: string | tl.RawInputWebDocument | tl.RawInputDocument, params: Omit ): InputInlineResultVideo { - return { - id, - type: 'video', - media, - ...params, - } + const ret = params as tl.Mutable + ret.id = id + ret.type = 'video' + ret.media = media + return ret } + /** + * Create an inline result containing an audio file + * + * @param id Inline result ID + * @param media Audio file + * @param params Additional parameters + */ export function audio( id: string, media: string | tl.RawInputWebDocument | tl.RawInputDocument, params: Omit ): InputInlineResultAudio { - return { - id, - type: 'audio', - media, - ...params, - } + const ret = params as tl.Mutable + ret.id = id + ret.type = 'audio' + ret.media = media + return ret } + /** + * Create an inline result containing a voice note + * + * @param id Inline result ID + * @param media Voice note + * @param params Additional parameters + */ export function voice( id: string, media: string | tl.RawInputWebDocument | tl.RawInputDocument, params: Omit ): InputInlineResultVoice { - return { - id, - type: 'voice', - media, - ...params, - } + const ret = params as tl.Mutable + ret.id = id + ret.type = 'voice' + ret.media = media + return ret } + /** + * Create an inline result containing a photo + * + * @param id Inline result ID + * @param media Photo + * @param params Additional parameters + */ export function photo( id: string, media: string | tl.RawInputWebDocument | tl.RawInputPhoto, - params?: Omit + params: Omit = {} ): InputInlineResultPhoto { - return { - id, - type: 'photo', - media, - ...(params || {}), - } + const ret = params as tl.Mutable + ret.id = id + ret.type = 'photo' + ret.media = media + return ret } + /** + * Create an inline result containing a sticker + * + * @param id Inline result ID + * @param media Sticker + */ export function sticker( id: string, media: string | tl.RawInputDocument @@ -567,67 +608,100 @@ export namespace BotInline { } } + /** + * Create an inline result containing a document + * (only PDF and ZIP are supported) + * + * @param id Inline result ID + * @param media Document + * @param params Additional parameters + */ export function file( id: string, media: string | tl.RawInputWebDocument | tl.RawInputDocument, params: Omit ): InputInlineResultFile { - return { - id, - type: 'file', - media, - ...params, - } + const ret = params as tl.Mutable + ret.id = id + ret.type = 'file' + ret.media = media + return ret } + /** + * Create an inline result containing a geolocation + * + * @param id Inline result ID + * @param latitude Latitude of the location + * @param longitude Longitude of the location + * @param params Additional parameters + */ export function geo( + id: string, latitude: number, longitude: number, params: Omit ): InputInlineResultGeo { - return { - type: 'geo', - latitude, - longitude, - ...params, - } + const ret = params as tl.Mutable + ret.id = id + ret.type = 'geo' + ret.latitude = latitude + ret.longitude = longitude + return ret } + /** + * Create an inline result containing a venue + * + * @param id Inline result ID + * @param params Venue parameters + */ export function venue( id: string, params: Omit ): InputInlineResultVenue { - return { - id, - type: 'venue', - ...params, - } + const ret = params as tl.Mutable + ret.id = id + ret.type = 'venue' + return ret } + /** + * Create an inline result containing a contact + * + * @param id Inline result ID + * @param params Contact parameters + */ export function contact( id: string, params: Omit ): InputInlineResultContact { - return { - id, - type: 'contact', - ...params, - } + const ret = params as tl.Mutable + ret.id = id + ret.type = 'contact' + return ret } + /** + * Create an inline result containing a game + * + * @param id Inline result ID + * @param shortName Short name of the game + * @param params Additional parameters + */ export function game( id: string, shortName: string, - params?: Omit + params: Omit = {} ): InputInlineResultGame { - return { - id, - type: 'game', - shortName, - ...(params || {}) - } + const ret = params as tl.Mutable + ret.id = id + ret.type = 'game' + ret.shortName = shortName + return ret } + /** @internal */ export async function _convertToTl( client: TelegramClient, obj: InputInlineResult, diff --git a/packages/client/src/types/bots/keyboards.ts b/packages/client/src/types/bots/keyboards.ts index 82595753..1beb982d 100644 --- a/packages/client/src/types/bots/keyboards.ts +++ b/packages/client/src/types/bots/keyboards.ts @@ -81,11 +81,10 @@ export namespace BotKeyboard { buttons: tl.TypeKeyboardButton[][], params: Omit = {} ): ReplyKeyboardMarkup { - return { - type: 'reply', - buttons, - ...params, - } + const ret = params as tl.Mutable + ret.type = 'reply' + ret.buttons = buttons + return ret } /** @@ -109,10 +108,9 @@ export namespace BotKeyboard { export function forceReply( params: Omit = {} ): ReplyKeyboardForceReply { - return { - type: 'force_reply', - ...params, - } + const ret = params as tl.Mutable + ret.type = 'force_reply' + return ret } /** diff --git a/packages/client/src/types/media/input-media.ts b/packages/client/src/types/media/input-media.ts index 575ea7de..4003dd4b 100644 --- a/packages/client/src/types/media/input-media.ts +++ b/packages/client/src/types/media/input-media.ts @@ -2,6 +2,7 @@ import { InputFileLike } from '../files' import { tl } from '@mtcute/tl' import { Venue } from './venue' import { MaybeArray } from '@mtcute/core' +import { InputInlineResultGame } from '../bots' interface BaseInputMedia { /** @@ -574,145 +575,166 @@ export namespace InputMedia { /** * Create an animation to be sent + * + * @param file Animation + * @param params Additional parameters */ export function animation( file: InputFileLike, - params?: OmitTypeAndFile + params: OmitTypeAndFile = {} ): InputMediaVideo { - return { - type: 'video', - file, - isAnimated: true, - ...(params || {}), - } + const ret = params as tl.Mutable + ret.type = 'video' + ret.file = file + ret.isAnimated = true + return ret } /** * Create an audio to be sent + * + * @param file Audio file + * @param params Additional parameters */ export function audio( file: InputFileLike, - params?: OmitTypeAndFile + params: OmitTypeAndFile = {} ): InputMediaAudio { - return { - type: 'audio', - file, - ...(params || {}), - } + const ret = params as tl.Mutable + ret.type = 'audio' + ret.file = file + return ret } /** * Create an document to be sent + * + * @param file Document + * @param params Additional parameters */ export function document( file: InputFileLike, - params?: OmitTypeAndFile + params: OmitTypeAndFile = {} ): InputMediaDocument { - return { - type: 'document', - file, - ...(params || {}), - } + const ret = params as tl.Mutable + ret.type = 'document' + ret.file = file + return ret } /** * Create an photo to be sent + * + * @param file Photo + * @param params Additional parameters */ export function photo( file: InputFileLike, - params?: OmitTypeAndFile + params: OmitTypeAndFile = {} ): InputMediaPhoto { - return { - type: 'photo', - file, - ...(params || {}), - } + const ret = params as tl.Mutable + ret.type = 'photo' + ret.file = file + return ret } /** * Create an video to be sent + * + * @param file Video + * @param params Additional parameters */ export function video( file: InputFileLike, - params?: OmitTypeAndFile + params: OmitTypeAndFile = {} ): InputMediaVideo { - return { - type: 'video', - file, - ...(params || {}), - } + const ret = params as tl.Mutable + ret.type = 'video' + ret.file = file + return ret } /** - * Create a voice message to be sent + * Create a voice note to be sent + * + * @param file Voice note + * @param params Additional parameters */ export function voice( file: InputFileLike, - params?: OmitTypeAndFile + params: OmitTypeAndFile = {} ): InputMediaVoice { - return { - type: 'voice', - file, - ...(params || {}), - } + const ret = params as tl.Mutable + ret.type = 'voice' + ret.file = file + return ret } /** * Create a sticker to be sent + * + * @param file Sticker + * @param params Additional parameters */ export function sticker( file: InputFileLike, - params?: OmitTypeAndFile + params: OmitTypeAndFile = {} ): InputMediaSticker { - return { - type: 'sticker', - file, - ...(params || {}), - } + const ret = params as tl.Mutable + ret.type = 'sticker' + ret.file = file + return ret } /** * Create a venue to be sent + * + * @param params Venue parameters */ export function venue( params: OmitTypeAndFile ): InputMediaVenue { - return { - type: 'venue', - ...params, - } + const ret = params as tl.Mutable + ret.type = 'venue' + return ret } /** * Create a geolocation to be sent + * + * @param latitude Latitude of the location + * @param longitude Longitude of the location + * @param params Additional parameters */ export function geo( latitude: number, longitude: number, - params?: OmitTypeAndFile + params: OmitTypeAndFile = {} ): InputMediaGeo { - return { - type: 'geo', - latitude, - longitude, - ...(params || {}), - } + const ret = params as tl.Mutable + ret.type = 'geo' + ret.latitude = latitude + ret.longitude = longitude + return ret } /** * Create a live geolocation to be sent + * + * @param latitude Latitude of the current location + * @param longitude Longitude of the current location + * @param params Additional parameters */ export function geoLive( latitude: number, longitude: number, - params?: OmitTypeAndFile + params: OmitTypeAndFile = {} ): InputMediaGeoLive { - return { - type: 'geo_live', - latitude, - longitude, - ...(params || {}), - } + const ret = params as tl.Mutable + ret.type = 'geo_live' + ret.latitude = latitude + ret.longitude = longitude + return ret } /** @@ -720,6 +742,8 @@ export namespace InputMedia { * * For convenience, known dice emojis are available * as static members of {@link Dice}. + * + * @param emoji Emoji representing the dice */ export function dice(emoji: string): InputMediaDice { return { @@ -730,18 +754,21 @@ export namespace InputMedia { /** * Create a contact to be sent + * + * @param params Contact parameters */ export function contact( params: OmitTypeAndFile ): InputMediaContact { - return { - type: 'contact', - ...params, - } + const ret = params as tl.Mutable + ret.type = 'contact' + return ret } /** * Create a game to be sent + * + * @param game Game short name or TL object representing one */ export function game(game: string | tl.TypeInputGame): InputMediaGame { return { @@ -752,38 +779,41 @@ export namespace InputMedia { /** * Create an invoice to be sent + * + * @param params Invoice parameters */ export function invoice( params: OmitTypeAndFile ): InputMediaInvoice { - return { - type: 'invoice', - ...params, - } + const ret = params as tl.Mutable + ret.type = 'invoice' + return ret } /** * Create a poll to be sent + * + * @param params Poll parameters */ export function poll( params: OmitTypeAndFile ): InputMediaPoll { - return { - type: 'poll', - ...params, - } + const ret = params as tl.Mutable + ret.type = 'poll' + return ret } /** * Create a quiz to be sent + * + * @param params Quiz parameters */ export function quiz( params: OmitTypeAndFile ): InputMediaQuiz { - return { - type: 'quiz', - ...params, - } + const ret = params as tl.Mutable + ret.type = 'quiz' + return ret } /** @@ -793,15 +823,17 @@ export namespace InputMedia { * Photo type is only inferred for reused files, * newly uploaded photos with `auto` will be * uploaded as a document + * + * @param file The media file + * @param params Additional parameters */ export function auto( file: InputFileLike, - params?: OmitTypeAndFile + params: OmitTypeAndFile = {} ): InputMediaAuto { - return { - type: 'auto', - file, - ...(params || {}), - } + const ret = params as tl.Mutable + ret.type = 'auto' + ret.file = file + return ret } }