feat(client): sendLocation method
This commit is contained in:
parent
0f2744b997
commit
97cbfd4840
3 changed files with 118 additions and 4 deletions
|
@ -28,6 +28,7 @@ import { _parseEntities } from './methods/messages/parse-entities'
|
|||
import { searchGlobal } from './methods/messages/search-global'
|
||||
import { searchMessages } from './methods/messages/search-messages'
|
||||
import { sendDice } from './methods/messages/send-dice'
|
||||
import { sendLocation } from './methods/messages/send-location'
|
||||
import { sendMedia } from './methods/messages/send-media'
|
||||
import { sendPhoto } from './methods/messages/send-photo'
|
||||
import { sendText } from './methods/messages/send-text'
|
||||
|
@ -744,9 +745,12 @@ export class TelegramClient extends BaseTelegramClient {
|
|||
/**
|
||||
* Send an animated dice with a random value.
|
||||
*
|
||||
* For convenience, supported dice emojis are available
|
||||
* For convenience, known dice emojis are available
|
||||
* as static members of {@link Dice}.
|
||||
*
|
||||
* Note that dice result value is generated randomly on the server,
|
||||
* you can't influence it in any way!
|
||||
*
|
||||
* @param chatId ID of the chat, its username, phone or `"me"` or `"self"`
|
||||
* @param emoji Emoji representing a dice
|
||||
* @param params Additional sending parameters
|
||||
|
@ -781,6 +785,44 @@ export class TelegramClient extends BaseTelegramClient {
|
|||
): Promise<Message> {
|
||||
return sendDice.apply(this, arguments)
|
||||
}
|
||||
/**
|
||||
* Send a static geo location.
|
||||
*
|
||||
* @param chatId ID of the chat, its username, phone or `"me"` or `"self"`
|
||||
* @param latitude Latitude of the location
|
||||
* @param longitude Longitude of the location
|
||||
* @param params Additional sending parameters
|
||||
*/
|
||||
sendLocation(
|
||||
chatId: InputPeerLike,
|
||||
latitude: number,
|
||||
longitude: number,
|
||||
params?: {
|
||||
/**
|
||||
* Message to reply to. Either a message object or message ID.
|
||||
*/
|
||||
replyTo?: number | Message
|
||||
|
||||
/**
|
||||
* Whether to send this message silently.
|
||||
*/
|
||||
silent?: boolean
|
||||
|
||||
/**
|
||||
* If set, the message will be scheduled to this date.
|
||||
* When passing a number, a UNIX time in ms is expected.
|
||||
*/
|
||||
schedule?: Date | number
|
||||
|
||||
/**
|
||||
* For bots: inline or reply markup or an instruction
|
||||
* to hide a reply keyboard or to force a reply.
|
||||
*/
|
||||
replyMarkup?: ReplyMarkup
|
||||
}
|
||||
): Promise<Message> {
|
||||
return sendLocation.apply(this, arguments)
|
||||
}
|
||||
/**
|
||||
* Send a single media.
|
||||
*
|
||||
|
|
|
@ -44,7 +44,6 @@ export async function sendDice(
|
|||
* to hide a reply keyboard or to force a reply.
|
||||
*/
|
||||
replyMarkup?: ReplyMarkup
|
||||
|
||||
}
|
||||
): Promise<Message> {
|
||||
if (!params) params = {}
|
||||
|
@ -57,7 +56,7 @@ export async function sendDice(
|
|||
peer,
|
||||
media: {
|
||||
_: 'inputMediaDice',
|
||||
emoticon: emoji
|
||||
emoticon: emoji,
|
||||
},
|
||||
silent: params.silent,
|
||||
replyToMsgId: params.replyTo
|
||||
|
@ -68,7 +67,7 @@ export async function sendDice(
|
|||
randomId: randomUlong(),
|
||||
scheduleDate: normalizeDate(params.schedule),
|
||||
replyMarkup,
|
||||
message: ''
|
||||
message: '',
|
||||
})
|
||||
|
||||
return this._findMessageInUpdate(res)
|
||||
|
|
73
packages/client/src/methods/messages/send-location.ts
Normal file
73
packages/client/src/methods/messages/send-location.ts
Normal file
|
@ -0,0 +1,73 @@
|
|||
import { BotKeyboard, InputPeerLike, Message, ReplyMarkup } from '../../types'
|
||||
import { TelegramClient } from '../../client'
|
||||
import { normalizeToInputPeer } from '../../utils/peer-utils'
|
||||
import { normalizeDate, randomUlong } from '../../utils/misc-utils'
|
||||
|
||||
/**
|
||||
* Send a static geo location.
|
||||
*
|
||||
* @param chatId ID of the chat, its username, phone or `"me"` or `"self"`
|
||||
* @param latitude Latitude of the location
|
||||
* @param longitude Longitude of the location
|
||||
* @param params Additional sending parameters
|
||||
* @internal
|
||||
*/
|
||||
export async function sendLocation(
|
||||
this: TelegramClient,
|
||||
chatId: InputPeerLike,
|
||||
latitude: number,
|
||||
longitude: number,
|
||||
params?: {
|
||||
/**
|
||||
* Message to reply to. Either a message object or message ID.
|
||||
*/
|
||||
replyTo?: number | Message
|
||||
|
||||
/**
|
||||
* Whether to send this message silently.
|
||||
*/
|
||||
silent?: boolean
|
||||
|
||||
/**
|
||||
* If set, the message will be scheduled to this date.
|
||||
* When passing a number, a UNIX time in ms is expected.
|
||||
*/
|
||||
schedule?: Date | number
|
||||
|
||||
/**
|
||||
* For bots: inline or reply markup or an instruction
|
||||
* to hide a reply keyboard or to force a reply.
|
||||
*/
|
||||
replyMarkup?: ReplyMarkup
|
||||
}
|
||||
): Promise<Message> {
|
||||
if (!params) params = {}
|
||||
|
||||
const peer = normalizeToInputPeer(await this.resolvePeer(chatId))
|
||||
const replyMarkup = BotKeyboard._convertToTl(params.replyMarkup)
|
||||
|
||||
const res = await this.call({
|
||||
_: 'messages.sendMedia',
|
||||
peer,
|
||||
media: {
|
||||
_: 'inputMediaGeoPoint',
|
||||
geoPoint: {
|
||||
_: 'inputGeoPoint',
|
||||
lat: latitude,
|
||||
long: longitude
|
||||
}
|
||||
},
|
||||
silent: params.silent,
|
||||
replyToMsgId: params.replyTo
|
||||
? typeof params.replyTo === 'number'
|
||||
? params.replyTo
|
||||
: params.replyTo.id
|
||||
: undefined,
|
||||
randomId: randomUlong(),
|
||||
scheduleDate: normalizeDate(params.schedule),
|
||||
replyMarkup,
|
||||
message: '',
|
||||
})
|
||||
|
||||
return this._findMessageInUpdate(res)
|
||||
}
|
Loading…
Reference in a new issue