fix(client): inline mode related improvements
This commit is contained in:
parent
596362bb89
commit
80e889d95f
2 changed files with 50 additions and 48 deletions
|
@ -153,44 +153,26 @@ export namespace BotInlineMessage {
|
||||||
/**
|
/**
|
||||||
* Create an inline message containing a geolocation
|
* Create an inline message containing a geolocation
|
||||||
*
|
*
|
||||||
* @param latitude Latitude of the location
|
|
||||||
* @param longitude Longitude of the location
|
|
||||||
* @param params Additional parameters
|
* @param params Additional parameters
|
||||||
*/
|
*/
|
||||||
export function geo(
|
export function geo(
|
||||||
latitude: number,
|
params: Omit<InputInlineMessageGeo, 'type'>
|
||||||
longitude: number,
|
|
||||||
params: Omit<
|
|
||||||
InputInlineMessageGeo,
|
|
||||||
'type' | 'latitude' | 'longitude'
|
|
||||||
> = {}
|
|
||||||
): InputInlineMessageGeo {
|
): InputInlineMessageGeo {
|
||||||
const ret = params as tl.Mutable<InputInlineMessageGeo>
|
const ret = params as tl.Mutable<InputInlineMessageGeo>
|
||||||
ret.type = 'geo'
|
ret.type = 'geo'
|
||||||
ret.latitude = latitude
|
|
||||||
ret.longitude = longitude
|
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an inline message containing a live geolocation
|
* 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
|
* @param params Additional parameters
|
||||||
*/
|
*/
|
||||||
export function geoLive(
|
export function geoLive(
|
||||||
latitude: number,
|
params: Omit<InputInlineMessageGeoLive, 'type'>
|
||||||
longitude: number,
|
|
||||||
params: Omit<
|
|
||||||
InputInlineMessageGeoLive,
|
|
||||||
'type' | 'latitude' | 'longitude'
|
|
||||||
> = {}
|
|
||||||
): InputInlineMessageGeoLive {
|
): InputInlineMessageGeoLive {
|
||||||
const ret = params as tl.Mutable<InputInlineMessageGeoLive>
|
const ret = params as tl.Mutable<InputInlineMessageGeoLive>
|
||||||
ret.type = 'geo_live'
|
ret.type = 'geo_live'
|
||||||
ret.latitude = latitude
|
|
||||||
ret.longitude = longitude
|
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -101,6 +101,11 @@ export interface InputInlineResultGif extends BaseInputInlineResult {
|
||||||
*/
|
*/
|
||||||
title?: string
|
title?: string
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Title of the result
|
||||||
|
*/
|
||||||
|
description?: string
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Animation thumbnail URL. Defaults to `media`,
|
* Animation thumbnail URL. Defaults to `media`,
|
||||||
* only applicable in case `media` is a URL
|
* only applicable in case `media` is a URL
|
||||||
|
@ -149,8 +154,6 @@ export interface InputInlineResultVideo extends BaseInputInlineResult {
|
||||||
/**
|
/**
|
||||||
* In case `media` is a URL, whether that URL is a link
|
* In case `media` is a URL, whether that URL is a link
|
||||||
* to an embedded video player.
|
* to an embedded video player.
|
||||||
*
|
|
||||||
* In such case, thumbnail must be passed explicitly.
|
|
||||||
*/
|
*/
|
||||||
isEmbed?: boolean
|
isEmbed?: boolean
|
||||||
|
|
||||||
|
@ -168,7 +171,7 @@ export interface InputInlineResultVideo extends BaseInputInlineResult {
|
||||||
* Video thumbnail URL (must be jpeg). Defaults to `media`,
|
* Video thumbnail URL (must be jpeg). Defaults to `media`,
|
||||||
* only applicable in case `media` is a URL.
|
* only applicable in case `media` is a URL.
|
||||||
*
|
*
|
||||||
* Must be provided explicitly if this is an embed video.
|
* Must be provided explicitly if this is a video loaded by URL.
|
||||||
*/
|
*/
|
||||||
thumb?: string | tl.RawInputWebDocument
|
thumb?: string | tl.RawInputWebDocument
|
||||||
|
|
||||||
|
@ -324,7 +327,7 @@ export interface InputInlineResultFile extends BaseInputInlineResult {
|
||||||
type: 'file'
|
type: 'file'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The file itself
|
* The file itself. When using URL, only PDF and ZIP are supported.
|
||||||
*
|
*
|
||||||
* Can be a URL, a TDLib and Bot API compatible File ID,
|
* Can be a URL, a TDLib and Bot API compatible File ID,
|
||||||
* or a TL object representing either of them.
|
* or a TL object representing either of them.
|
||||||
|
@ -335,8 +338,8 @@ export interface InputInlineResultFile extends BaseInputInlineResult {
|
||||||
* MIME type of the file.
|
* MIME type of the file.
|
||||||
*
|
*
|
||||||
* Due to some Telegram limitation, you can only send
|
* Due to some Telegram limitation, you can only send
|
||||||
* PDF and ZIP files (`application/pdf` and `application/zip`
|
* PDF and ZIP files from URL
|
||||||
* MIMEs respectively).
|
* (`application/pdf` and `application/zip` MIMEs respectively).
|
||||||
*
|
*
|
||||||
* Must be provided if `media` is a URL
|
* Must be provided if `media` is a URL
|
||||||
*/
|
*/
|
||||||
|
@ -396,7 +399,9 @@ export interface InputInlineResultGeo extends BaseInputInlineResult {
|
||||||
/**
|
/**
|
||||||
* Inline result containing a venue.
|
* Inline result containing a venue.
|
||||||
*
|
*
|
||||||
* If `message` is not passed, an error is thrown.
|
* If `message` is not passed, {@link BotInlineMessage.venue} is used with
|
||||||
|
* given `latitude` and `longitude` were passed.
|
||||||
|
* If they weren't passed either, an error is thrown.
|
||||||
*/
|
*/
|
||||||
export interface InputInlineResultVenue extends BaseInputInlineResult {
|
export interface InputInlineResultVenue extends BaseInputInlineResult {
|
||||||
type: 'venue'
|
type: 'venue'
|
||||||
|
@ -411,6 +416,16 @@ export interface InputInlineResultVenue extends BaseInputInlineResult {
|
||||||
*/
|
*/
|
||||||
address: string
|
address: string
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Latitude of the geolocation
|
||||||
|
*/
|
||||||
|
latitude?: number
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Longitude of the geolocation
|
||||||
|
*/
|
||||||
|
longitude?: number
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Venue thumbnail URL (must be jpeg).
|
* Venue thumbnail URL (must be jpeg).
|
||||||
*
|
*
|
||||||
|
@ -610,7 +625,7 @@ export namespace BotInline {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an inline result containing a document
|
* Create an inline result containing a document
|
||||||
* (only PDF and ZIP are supported)
|
* (only PDF and ZIP are supported when using URL)
|
||||||
*
|
*
|
||||||
* @param id Inline result ID
|
* @param id Inline result ID
|
||||||
* @param media Document
|
* @param media Document
|
||||||
|
@ -632,21 +647,15 @@ export namespace BotInline {
|
||||||
* Create an inline result containing a geolocation
|
* Create an inline result containing a geolocation
|
||||||
*
|
*
|
||||||
* @param id Inline result ID
|
* @param id Inline result ID
|
||||||
* @param latitude Latitude of the location
|
|
||||||
* @param longitude Longitude of the location
|
|
||||||
* @param params Additional parameters
|
* @param params Additional parameters
|
||||||
*/
|
*/
|
||||||
export function geo(
|
export function geo(
|
||||||
id: string,
|
id: string,
|
||||||
latitude: number,
|
params: Omit<InputInlineResultGeo, 'type' | 'id'>
|
||||||
longitude: number,
|
|
||||||
params: Omit<InputInlineResultGeo, 'type' | 'latitude' | 'longitude'>
|
|
||||||
): InputInlineResultGeo {
|
): InputInlineResultGeo {
|
||||||
const ret = params as tl.Mutable<InputInlineResultGeo>
|
const ret = params as tl.Mutable<InputInlineResultGeo>
|
||||||
ret.id = id
|
ret.id = id
|
||||||
ret.type = 'geo'
|
ret.type = 'geo'
|
||||||
ret.latitude = latitude
|
|
||||||
ret.longitude = longitude
|
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -728,7 +737,7 @@ export namespace BotInline {
|
||||||
url: obj.thumb || fallback!,
|
url: obj.thumb || fallback!,
|
||||||
mimeType:
|
mimeType:
|
||||||
obj.type === 'gif'
|
obj.type === 'gif'
|
||||||
? obj.thumbMime ?? 'image/jpeg'
|
? obj.thumbMime ?? obj.mime ?? 'video/mp4'
|
||||||
: 'image/jpeg',
|
: 'image/jpeg',
|
||||||
attributes: [],
|
attributes: [],
|
||||||
}
|
}
|
||||||
|
@ -836,12 +845,27 @@ export namespace BotInline {
|
||||||
parseMode
|
parseMode
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
if (obj.type === 'venue')
|
if (obj.type === 'venue') {
|
||||||
throw new MtCuteArgumentError(
|
if (obj.latitude && obj.longitude) {
|
||||||
'message bust be supplied for venue inline result'
|
sendMessage = {
|
||||||
)
|
_: 'inputBotInlineMessageMediaVenue',
|
||||||
|
title: obj.title,
|
||||||
if (
|
address: obj.address,
|
||||||
|
geoPoint: {
|
||||||
|
_: 'inputGeoPoint',
|
||||||
|
lat: obj.latitude,
|
||||||
|
long: obj.longitude,
|
||||||
|
},
|
||||||
|
provider: '',
|
||||||
|
venueId: '',
|
||||||
|
venueType: ''
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new MtCuteArgumentError(
|
||||||
|
'message or location (lat&lon) bust be supplied for venue inline result'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else if (
|
||||||
obj.type === 'video' &&
|
obj.type === 'video' &&
|
||||||
obj.isEmbed &&
|
obj.isEmbed &&
|
||||||
typeof obj.media === 'string'
|
typeof obj.media === 'string'
|
||||||
|
@ -897,7 +921,7 @@ export namespace BotInline {
|
||||||
if (obj.type === 'video') mime = 'video/mp4'
|
if (obj.type === 'video') mime = 'video/mp4'
|
||||||
else if (obj.type === 'audio')
|
else if (obj.type === 'audio')
|
||||||
mime = obj.mime ?? 'audio/mpeg'
|
mime = obj.mime ?? 'audio/mpeg'
|
||||||
else if (obj.type === 'gif') mime = obj.mime ?? 'image/jpeg'
|
else if (obj.type === 'gif') mime = obj.mime ?? 'video/mp4'
|
||||||
else if (obj.type === 'voice') mime = 'audio/ogg'
|
else if (obj.type === 'voice') mime = 'audio/ogg'
|
||||||
else if (obj.type === 'file') {
|
else if (obj.type === 'file') {
|
||||||
if (!obj.mime)
|
if (!obj.mime)
|
||||||
|
@ -988,11 +1012,7 @@ export namespace BotInline {
|
||||||
description = obj.address
|
description = obj.address
|
||||||
} else if (obj.type === 'contact') {
|
} else if (obj.type === 'contact') {
|
||||||
description = obj.phone
|
description = obj.phone
|
||||||
} else if (
|
} else if (obj.type !== 'voice' && obj.type !== 'sticker') {
|
||||||
obj.type !== 'gif' &&
|
|
||||||
obj.type !== 'voice' &&
|
|
||||||
obj.type !== 'sticker'
|
|
||||||
) {
|
|
||||||
description = obj.description
|
description = obj.description
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue