commonMain.TelegramClient.kt Maven / Gradle / Ivy
package com.github.omarmiatello.telegram
import com.github.omarmiatello.telegram.TelegramRequest.*
import io.ktor.client.*
import io.ktor.client.call.*
import io.ktor.client.request.*
import io.ktor.http.*
import io.ktor.http.content.*
import kotlinx.serialization.KSerializer
import kotlinx.serialization.builtins.ListSerializer
import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.json.Json
class TelegramClient(apiKey: String, private val httpClient: HttpClient = HttpClient()) {
private val basePath = "https://api.telegram.org/bot$apiKey"
private val json = Json { ignoreUnknownKeys = true; prettyPrint = true; encodeDefaults = false; isLenient = true; }
private suspend fun telegramGet(path: String, response: KSerializer): TelegramResponse {
val responseString: String = httpClient.get(path).body()
return json.decodeFromString(TelegramResponse.serializer(response), responseString)
}
private suspend fun telegramPost(path: String, body: String, response: KSerializer): TelegramResponse {
val responseString: String = httpClient
.post(path) { setBody(TextContent(body, ContentType.Application.Json)) }
.body()
return json.decodeFromString(TelegramResponse.serializer(response), responseString)
}
// Getting updates
/**
* Use this method to receive incoming updates using long polling (wiki). Returns an Array of Update objects.
* Notes
1. This method will not work if an outgoing webhook is set up.
2. In order to avoid getting duplicate updates, recalculate offset after each server response.
*
*
* @property offset Identifier of the first update to be returned. Must be greater by one than the highest among the identifiers of previously received updates. By default, updates starting with the earliest unconfirmed update are returned. An update is considered confirmed as soon as getUpdates is called with an offset higher than its update_id. The negative offset can be specified to retrieve updates starting from -offset update from the end of the updates queue. All previous updates will be forgotten.
* @property limit Limits the number of updates to be retrieved. Values between 1-100 are accepted. Defaults to 100.
* @property timeout Timeout in seconds for long polling. Defaults to 0, i.e. usual short polling. Should be positive, short polling should be used for testing purposes only.
* @property allowed_updates A JSON-serialized list of the update types you want your bot to receive. For example, specify ["message", "edited_channel_post", "callback_query"]
to only receive updates of these types. See Update for a complete list of available update types. Specify an empty list to receive all update types except chat_member, message_reaction, and message_reaction_count (default). If not specified, the previous setting will be used.
Please note that this parameter doesn't affect updates created before the call to the getUpdates, so unwanted updates may be received for a short period of time.
*
* @return [List]
* */
suspend fun getUpdates(
offset: Long? = null,
limit: Long? = null,
timeout: Long? = null,
allowed_updates: List? = null,
) = telegramPost(
"$basePath/getUpdates",
GetUpdatesRequest(
offset,
limit,
timeout,
allowed_updates,
).toJsonForRequest(),
ListSerializer(Update.serializer())
)
/**
* Use this method to specify a URL and receive incoming updates via an outgoing webhook. Whenever there is an update for the bot, we will send an HTTPS POST request to the specified URL, containing a JSON-serialized Update. In case of an unsuccessful request, we will give up after a reasonable amount of attempts. Returns True on success.
If you'd like to make sure that the webhook was set by you, you can specify secret data in the parameter secret_token. If specified, the request will contain a header “X-Telegram-Bot-Api-Secret-Token” with the secret token as content.
* Notes
1. You will not be able to receive updates using getUpdates for as long as an outgoing webhook is set up.
2. To use a self-signed certificate, you need to upload your public key certificate using certificate parameter. Please upload as InputFile, sending a String will not work.
3. Ports currently supported for webhooks: 443, 80, 88, 8443.
* If you're having any trouble setting up webhooks, please check out this amazing guide to webhooks.
*
*
* @property url HTTPS URL to send updates to. Use an empty string to remove webhook integration
* @property certificate Upload your public key certificate so that the root certificate in use can be checked. See our self-signed guide for details.
* @property ip_address The fixed IP address which will be used to send webhook requests instead of the IP address resolved through DNS
* @property max_connections The maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery, 1-100. Defaults to 40. Use lower values to limit the load on your bot's server, and higher values to increase your bot's throughput.
* @property allowed_updates A JSON-serialized list of the update types you want your bot to receive. For example, specify ["message", "edited_channel_post", "callback_query"]
to only receive updates of these types. See Update for a complete list of available update types. Specify an empty list to receive all update types except chat_member, message_reaction, and message_reaction_count (default). If not specified, the previous setting will be used.
Please note that this parameter doesn't affect updates created before the call to the setWebhook, so unwanted updates may be received for a short period of time.
* @property drop_pending_updates Pass True to drop all pending updates
* @property secret_token A secret token to be sent in a header “X-Telegram-Bot-Api-Secret-Token” in every webhook request, 1-256 characters. Only characters A-Z
, a-z
, 0-9
, _
and -
are allowed. The header is useful to ensure that the request comes from a webhook set by you.
*
* @return [Boolean]
* */
suspend fun setWebhook(
url: String,
certificate: Any? = null,
ip_address: String? = null,
max_connections: Long? = null,
allowed_updates: List? = null,
drop_pending_updates: Boolean? = null,
secret_token: String? = null,
) = telegramPost(
"$basePath/setWebhook",
SetWebhookRequest(
url,
certificate,
ip_address,
max_connections,
allowed_updates,
drop_pending_updates,
secret_token,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to remove webhook integration if you decide to switch back to getUpdates. Returns True on success.
*
* @property drop_pending_updates Pass True to drop all pending updates
*
* @return [Boolean]
* */
suspend fun deleteWebhook(
drop_pending_updates: Boolean? = null,
) = telegramPost(
"$basePath/deleteWebhook",
DeleteWebhookRequest(
drop_pending_updates,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to get current webhook status. Requires no parameters. On success, returns a WebhookInfo object. If the bot is using getUpdates, will return an object with the url field empty.
*
*
* @return [WebhookInfo]
* */
suspend fun getWebhookInfo() = telegramGet("$basePath/getWebhookInfo", WebhookInfo.serializer())
// Available methods
/**
* Use this method to log out from the cloud Bot API server before launching the bot locally. You must log out the bot before running it locally, otherwise there is no guarantee that the bot will receive updates. After a successful call, you can immediately log in on a local server, but will not be able to log in back to the cloud Bot API server for 10 minutes. Returns True on success. Requires no parameters.
*
*
* @return [Boolean]
* */
suspend fun logOut() = telegramGet("$basePath/logOut", Boolean.serializer())
/**
* Use this method to close the bot instance before moving it from one local server to another. You need to delete the webhook before calling this method to ensure that the bot isn't launched again after server restart. The method will return error 429 in the first 10 minutes after the bot is launched. Returns True on success. Requires no parameters.
*
*
* @return [Boolean]
* */
suspend fun close() = telegramGet("$basePath/close", Boolean.serializer())
/**
* Use this method to send text messages. On success, the sent Message is returned.
*
* @property chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
* @property text Text of the message to be sent, 1-4096 characters after entities parsing
* @property business_connection_id Unique identifier of the business connection on behalf of which the message will be sent
* @property message_thread_id Unique identifier for the target message thread (topic) of the forum; for forum supergroups only
* @property parse_mode Mode for parsing entities in the message text. See formatting options for more details.
* @property entities A JSON-serialized list of special entities that appear in message text, which can be specified instead of parse_mode
* @property link_preview_options Link preview generation options for the message
* @property disable_notification Sends the message silently. Users will receive a notification with no sound.
* @property protect_content Protects the contents of the sent message from forwarding and saving
* @property message_effect_id Unique identifier of the message effect to be added to the message; for private chats only
* @property reply_parameters Description of the message to reply to
* @property reply_markup Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user
*
* @return [Message]
* */
suspend fun sendMessage(
chat_id: ChatId,
text: String,
business_connection_id: BusinessConnectionId? = null,
message_thread_id: MessageThreadId? = null,
parse_mode: ParseMode? = null,
entities: List? = null,
link_preview_options: LinkPreviewOptions? = null,
disable_notification: Boolean? = null,
protect_content: Boolean? = null,
message_effect_id: MessageEffectId? = null,
reply_parameters: ReplyParameters? = null,
reply_markup: KeyboardOption? = null,
) = telegramPost(
"$basePath/sendMessage",
SendMessageRequest(
chat_id,
text,
business_connection_id,
message_thread_id,
parse_mode,
entities,
link_preview_options,
disable_notification,
protect_content,
message_effect_id,
reply_parameters,
reply_markup,
).toJsonForRequest(),
Message.serializer()
)
/**
* Use this method to forward messages of any kind. Service messages and messages with protected content can't be forwarded. On success, the sent Message is returned.
*
* @property chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
* @property from_chat_id Unique identifier for the chat where the original message was sent (or channel username in the format @channelusername
)
* @property message_id Message identifier in the chat specified in from_chat_id
* @property message_thread_id Unique identifier for the target message thread (topic) of the forum; for forum supergroups only
* @property disable_notification Sends the message silently. Users will receive a notification with no sound.
* @property protect_content Protects the contents of the forwarded message from forwarding and saving
*
* @return [Message]
* */
suspend fun forwardMessage(
chat_id: ChatId,
from_chat_id: ChatId,
message_id: MessageId,
message_thread_id: MessageThreadId? = null,
disable_notification: Boolean? = null,
protect_content: Boolean? = null,
) = telegramPost(
"$basePath/forwardMessage",
ForwardMessageRequest(
chat_id,
from_chat_id,
message_id,
message_thread_id,
disable_notification,
protect_content,
).toJsonForRequest(),
Message.serializer()
)
/**
* Use this method to forward multiple messages of any kind. If some of the specified messages can't be found or forwarded, they are skipped. Service messages and messages with protected content can't be forwarded. Album grouping is kept for forwarded messages. On success, an array of MessageId of the sent messages is returned.
*
* @property chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
* @property from_chat_id Unique identifier for the chat where the original messages were sent (or channel username in the format @channelusername
)
* @property message_ids A JSON-serialized list of 1-100 identifiers of messages in the chat from_chat_id to forward. The identifiers must be specified in a strictly increasing order.
* @property message_thread_id Unique identifier for the target message thread (topic) of the forum; for forum supergroups only
* @property disable_notification Sends the messages silently. Users will receive a notification with no sound.
* @property protect_content Protects the contents of the forwarded messages from forwarding and saving
*
* @return [List]
* */
suspend fun forwardMessages(
chat_id: ChatId,
from_chat_id: ChatId,
message_ids: List,
message_thread_id: MessageThreadId? = null,
disable_notification: Boolean? = null,
protect_content: Boolean? = null,
) = telegramPost(
"$basePath/forwardMessages",
ForwardMessagesRequest(
chat_id,
from_chat_id,
message_ids,
message_thread_id,
disable_notification,
protect_content,
).toJsonForRequest(),
ListSerializer(MessageId.serializer())
)
/**
* Use this method to copy messages of any kind. Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessage, but the copied message doesn't have a link to the original message. Returns the MessageId of the sent message on success.
*
* @property chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
* @property from_chat_id Unique identifier for the chat where the original message was sent (or channel username in the format @channelusername
)
* @property message_id Message identifier in the chat specified in from_chat_id
* @property message_thread_id Unique identifier for the target message thread (topic) of the forum; for forum supergroups only
* @property caption New caption for media, 0-1024 characters after entities parsing. If not specified, the original caption is kept
* @property parse_mode Mode for parsing entities in the new caption. See formatting options for more details.
* @property caption_entities A JSON-serialized list of special entities that appear in the new caption, which can be specified instead of parse_mode
* @property show_caption_above_media Pass True, if the caption must be shown above the message media. Ignored if a new caption isn't specified.
* @property disable_notification Sends the message silently. Users will receive a notification with no sound.
* @property protect_content Protects the contents of the sent message from forwarding and saving
* @property reply_parameters Description of the message to reply to
* @property reply_markup Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user
*
* @return [MessageId]
* */
suspend fun copyMessage(
chat_id: ChatId,
from_chat_id: ChatId,
message_id: MessageId,
message_thread_id: MessageThreadId? = null,
caption: String? = null,
parse_mode: ParseMode? = null,
caption_entities: List? = null,
show_caption_above_media: Boolean? = null,
disable_notification: Boolean? = null,
protect_content: Boolean? = null,
reply_parameters: ReplyParameters? = null,
reply_markup: KeyboardOption? = null,
) = telegramPost(
"$basePath/copyMessage",
CopyMessageRequest(
chat_id,
from_chat_id,
message_id,
message_thread_id,
caption,
parse_mode,
caption_entities,
show_caption_above_media,
disable_notification,
protect_content,
reply_parameters,
reply_markup,
).toJsonForRequest(),
MessageId.serializer()
)
/**
* Use this method to copy messages of any kind. If some of the specified messages can't be found or copied, they are skipped. Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessages, but the copied messages don't have a link to the original message. Album grouping is kept for copied messages. On success, an array of MessageId of the sent messages is returned.
*
* @property chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
* @property from_chat_id Unique identifier for the chat where the original messages were sent (or channel username in the format @channelusername
)
* @property message_ids A JSON-serialized list of 1-100 identifiers of messages in the chat from_chat_id to copy. The identifiers must be specified in a strictly increasing order.
* @property message_thread_id Unique identifier for the target message thread (topic) of the forum; for forum supergroups only
* @property disable_notification Sends the messages silently. Users will receive a notification with no sound.
* @property protect_content Protects the contents of the sent messages from forwarding and saving
* @property remove_caption Pass True to copy the messages without their captions
*
* @return [List]
* */
suspend fun copyMessages(
chat_id: ChatId,
from_chat_id: ChatId,
message_ids: List,
message_thread_id: MessageThreadId? = null,
disable_notification: Boolean? = null,
protect_content: Boolean? = null,
remove_caption: Boolean? = null,
) = telegramPost(
"$basePath/copyMessages",
CopyMessagesRequest(
chat_id,
from_chat_id,
message_ids,
message_thread_id,
disable_notification,
protect_content,
remove_caption,
).toJsonForRequest(),
ListSerializer(MessageId.serializer())
)
/**
* Use this method to send photos. On success, the sent Message is returned.
*
* @property chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
* @property photo Photo to send. Pass a file_id as String to send a photo that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a photo from the Internet, or upload a new photo using multipart/form-data. The photo must be at most 10 MB in size. The photo's width and height must not exceed 10000 in total. Width and height ratio must be at most 20. More information on Sending Files »
* @property business_connection_id Unique identifier of the business connection on behalf of which the message will be sent
* @property message_thread_id Unique identifier for the target message thread (topic) of the forum; for forum supergroups only
* @property caption Photo caption (may also be used when resending photos by file_id), 0-1024 characters after entities parsing
* @property parse_mode Mode for parsing entities in the photo caption. See formatting options for more details.
* @property caption_entities A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode
* @property show_caption_above_media Pass True, if the caption must be shown above the message media
* @property has_spoiler Pass True if the photo needs to be covered with a spoiler animation
* @property disable_notification Sends the message silently. Users will receive a notification with no sound.
* @property protect_content Protects the contents of the sent message from forwarding and saving
* @property message_effect_id Unique identifier of the message effect to be added to the message; for private chats only
* @property reply_parameters Description of the message to reply to
* @property reply_markup Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user
*
* @return [Message]
* */
suspend fun sendPhoto(
chat_id: ChatId,
photo: String,
business_connection_id: BusinessConnectionId? = null,
message_thread_id: MessageThreadId? = null,
caption: String? = null,
parse_mode: ParseMode? = null,
caption_entities: List? = null,
show_caption_above_media: Boolean? = null,
has_spoiler: Boolean? = null,
disable_notification: Boolean? = null,
protect_content: Boolean? = null,
message_effect_id: MessageEffectId? = null,
reply_parameters: ReplyParameters? = null,
reply_markup: KeyboardOption? = null,
) = telegramPost(
"$basePath/sendPhoto",
SendPhotoRequest(
chat_id,
photo,
business_connection_id,
message_thread_id,
caption,
parse_mode,
caption_entities,
show_caption_above_media,
has_spoiler,
disable_notification,
protect_content,
message_effect_id,
reply_parameters,
reply_markup,
).toJsonForRequest(),
Message.serializer()
)
/**
* Use this method to send audio files, if you want Telegram clients to display them in the music player. Your audio must be in the .MP3 or .M4A format. On success, the sent Message is returned. Bots can currently send audio files of up to 50 MB in size, this limit may be changed in the future.
For sending voice messages, use the sendVoice method instead.
*
* @property chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
* @property audio Audio file to send. Pass a file_id as String to send an audio file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get an audio file from the Internet, or upload a new one using multipart/form-data. More information on Sending Files »
* @property business_connection_id Unique identifier of the business connection on behalf of which the message will be sent
* @property message_thread_id Unique identifier for the target message thread (topic) of the forum; for forum supergroups only
* @property caption Audio caption, 0-1024 characters after entities parsing
* @property parse_mode Mode for parsing entities in the audio caption. See formatting options for more details.
* @property caption_entities A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode
* @property duration Duration of the audio in seconds
* @property performer Performer
* @property title Track name
* @property thumbnail Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass “attach://<file_attach_name>” if the thumbnail was uploaded using multipart/form-data under <file_attach_name>. More information on Sending Files »
* @property disable_notification Sends the message silently. Users will receive a notification with no sound.
* @property protect_content Protects the contents of the sent message from forwarding and saving
* @property message_effect_id Unique identifier of the message effect to be added to the message; for private chats only
* @property reply_parameters Description of the message to reply to
* @property reply_markup Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user
*
* @return [Message]
* */
suspend fun sendAudio(
chat_id: ChatId,
audio: String,
business_connection_id: BusinessConnectionId? = null,
message_thread_id: MessageThreadId? = null,
caption: String? = null,
parse_mode: ParseMode? = null,
caption_entities: List? = null,
duration: Long? = null,
performer: String? = null,
title: String? = null,
thumbnail: String? = null,
disable_notification: Boolean? = null,
protect_content: Boolean? = null,
message_effect_id: MessageEffectId? = null,
reply_parameters: ReplyParameters? = null,
reply_markup: KeyboardOption? = null,
) = telegramPost(
"$basePath/sendAudio",
SendAudioRequest(
chat_id,
audio,
business_connection_id,
message_thread_id,
caption,
parse_mode,
caption_entities,
duration,
performer,
title,
thumbnail,
disable_notification,
protect_content,
message_effect_id,
reply_parameters,
reply_markup,
).toJsonForRequest(),
Message.serializer()
)
/**
* Use this method to send general files. On success, the sent Message is returned. Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future.
*
* @property chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
* @property document File to send. Pass a file_id as String to send a file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. More information on Sending Files »
* @property business_connection_id Unique identifier of the business connection on behalf of which the message will be sent
* @property message_thread_id Unique identifier for the target message thread (topic) of the forum; for forum supergroups only
* @property thumbnail Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass “attach://<file_attach_name>” if the thumbnail was uploaded using multipart/form-data under <file_attach_name>. More information on Sending Files »
* @property caption Document caption (may also be used when resending documents by file_id), 0-1024 characters after entities parsing
* @property parse_mode Mode for parsing entities in the document caption. See formatting options for more details.
* @property caption_entities A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode
* @property disable_content_type_detection Disables automatic server-side content type detection for files uploaded using multipart/form-data
* @property disable_notification Sends the message silently. Users will receive a notification with no sound.
* @property protect_content Protects the contents of the sent message from forwarding and saving
* @property message_effect_id Unique identifier of the message effect to be added to the message; for private chats only
* @property reply_parameters Description of the message to reply to
* @property reply_markup Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user
*
* @return [Message]
* */
suspend fun sendDocument(
chat_id: ChatId,
document: String,
business_connection_id: BusinessConnectionId? = null,
message_thread_id: MessageThreadId? = null,
thumbnail: String? = null,
caption: String? = null,
parse_mode: ParseMode? = null,
caption_entities: List? = null,
disable_content_type_detection: Boolean? = null,
disable_notification: Boolean? = null,
protect_content: Boolean? = null,
message_effect_id: MessageEffectId? = null,
reply_parameters: ReplyParameters? = null,
reply_markup: KeyboardOption? = null,
) = telegramPost(
"$basePath/sendDocument",
SendDocumentRequest(
chat_id,
document,
business_connection_id,
message_thread_id,
thumbnail,
caption,
parse_mode,
caption_entities,
disable_content_type_detection,
disable_notification,
protect_content,
message_effect_id,
reply_parameters,
reply_markup,
).toJsonForRequest(),
Message.serializer()
)
/**
* Use this method to send video files, Telegram clients support MPEG4 videos (other formats may be sent as Document). On success, the sent Message is returned. Bots can currently send video files of up to 50 MB in size, this limit may be changed in the future.
*
* @property chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
* @property video Video to send. Pass a file_id as String to send a video that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a video from the Internet, or upload a new video using multipart/form-data. More information on Sending Files »
* @property business_connection_id Unique identifier of the business connection on behalf of which the message will be sent
* @property message_thread_id Unique identifier for the target message thread (topic) of the forum; for forum supergroups only
* @property duration Duration of sent video in seconds
* @property width Video width
* @property height Video height
* @property thumbnail Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass “attach://<file_attach_name>” if the thumbnail was uploaded using multipart/form-data under <file_attach_name>. More information on Sending Files »
* @property caption Video caption (may also be used when resending videos by file_id), 0-1024 characters after entities parsing
* @property parse_mode Mode for parsing entities in the video caption. See formatting options for more details.
* @property caption_entities A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode
* @property show_caption_above_media Pass True, if the caption must be shown above the message media
* @property has_spoiler Pass True if the video needs to be covered with a spoiler animation
* @property supports_streaming Pass True if the uploaded video is suitable for streaming
* @property disable_notification Sends the message silently. Users will receive a notification with no sound.
* @property protect_content Protects the contents of the sent message from forwarding and saving
* @property message_effect_id Unique identifier of the message effect to be added to the message; for private chats only
* @property reply_parameters Description of the message to reply to
* @property reply_markup Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user
*
* @return [Message]
* */
suspend fun sendVideo(
chat_id: ChatId,
video: String,
business_connection_id: BusinessConnectionId? = null,
message_thread_id: MessageThreadId? = null,
duration: Long? = null,
width: Long? = null,
height: Long? = null,
thumbnail: String? = null,
caption: String? = null,
parse_mode: ParseMode? = null,
caption_entities: List? = null,
show_caption_above_media: Boolean? = null,
has_spoiler: Boolean? = null,
supports_streaming: Boolean? = null,
disable_notification: Boolean? = null,
protect_content: Boolean? = null,
message_effect_id: MessageEffectId? = null,
reply_parameters: ReplyParameters? = null,
reply_markup: KeyboardOption? = null,
) = telegramPost(
"$basePath/sendVideo",
SendVideoRequest(
chat_id,
video,
business_connection_id,
message_thread_id,
duration,
width,
height,
thumbnail,
caption,
parse_mode,
caption_entities,
show_caption_above_media,
has_spoiler,
supports_streaming,
disable_notification,
protect_content,
message_effect_id,
reply_parameters,
reply_markup,
).toJsonForRequest(),
Message.serializer()
)
/**
* Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound). On success, the sent Message is returned. Bots can currently send animation files of up to 50 MB in size, this limit may be changed in the future.
*
* @property chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
* @property animation Animation to send. Pass a file_id as String to send an animation that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get an animation from the Internet, or upload a new animation using multipart/form-data. More information on Sending Files »
* @property business_connection_id Unique identifier of the business connection on behalf of which the message will be sent
* @property message_thread_id Unique identifier for the target message thread (topic) of the forum; for forum supergroups only
* @property duration Duration of sent animation in seconds
* @property width Animation width
* @property height Animation height
* @property thumbnail Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass “attach://<file_attach_name>” if the thumbnail was uploaded using multipart/form-data under <file_attach_name>. More information on Sending Files »
* @property caption Animation caption (may also be used when resending animation by file_id), 0-1024 characters after entities parsing
* @property parse_mode Mode for parsing entities in the animation caption. See formatting options for more details.
* @property caption_entities A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode
* @property show_caption_above_media Pass True, if the caption must be shown above the message media
* @property has_spoiler Pass True if the animation needs to be covered with a spoiler animation
* @property disable_notification Sends the message silently. Users will receive a notification with no sound.
* @property protect_content Protects the contents of the sent message from forwarding and saving
* @property message_effect_id Unique identifier of the message effect to be added to the message; for private chats only
* @property reply_parameters Description of the message to reply to
* @property reply_markup Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user
*
* @return [Message]
* */
suspend fun sendAnimation(
chat_id: ChatId,
animation: String,
business_connection_id: BusinessConnectionId? = null,
message_thread_id: MessageThreadId? = null,
duration: Long? = null,
width: Long? = null,
height: Long? = null,
thumbnail: String? = null,
caption: String? = null,
parse_mode: ParseMode? = null,
caption_entities: List? = null,
show_caption_above_media: Boolean? = null,
has_spoiler: Boolean? = null,
disable_notification: Boolean? = null,
protect_content: Boolean? = null,
message_effect_id: MessageEffectId? = null,
reply_parameters: ReplyParameters? = null,
reply_markup: KeyboardOption? = null,
) = telegramPost(
"$basePath/sendAnimation",
SendAnimationRequest(
chat_id,
animation,
business_connection_id,
message_thread_id,
duration,
width,
height,
thumbnail,
caption,
parse_mode,
caption_entities,
show_caption_above_media,
has_spoiler,
disable_notification,
protect_content,
message_effect_id,
reply_parameters,
reply_markup,
).toJsonForRequest(),
Message.serializer()
)
/**
* Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. For this to work, your audio must be in an .OGG file encoded with OPUS, or in .MP3 format, or in .M4A format (other formats may be sent as Audio or Document). On success, the sent Message is returned. Bots can currently send voice messages of up to 50 MB in size, this limit may be changed in the future.
*
* @property chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
* @property voice Audio file to send. Pass a file_id as String to send a file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. More information on Sending Files »
* @property business_connection_id Unique identifier of the business connection on behalf of which the message will be sent
* @property message_thread_id Unique identifier for the target message thread (topic) of the forum; for forum supergroups only
* @property caption Voice message caption, 0-1024 characters after entities parsing
* @property parse_mode Mode for parsing entities in the voice message caption. See formatting options for more details.
* @property caption_entities A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode
* @property duration Duration of the voice message in seconds
* @property disable_notification Sends the message silently. Users will receive a notification with no sound.
* @property protect_content Protects the contents of the sent message from forwarding and saving
* @property message_effect_id Unique identifier of the message effect to be added to the message; for private chats only
* @property reply_parameters Description of the message to reply to
* @property reply_markup Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user
*
* @return [Message]
* */
suspend fun sendVoice(
chat_id: ChatId,
voice: String,
business_connection_id: BusinessConnectionId? = null,
message_thread_id: MessageThreadId? = null,
caption: String? = null,
parse_mode: ParseMode? = null,
caption_entities: List? = null,
duration: Long? = null,
disable_notification: Boolean? = null,
protect_content: Boolean? = null,
message_effect_id: MessageEffectId? = null,
reply_parameters: ReplyParameters? = null,
reply_markup: KeyboardOption? = null,
) = telegramPost(
"$basePath/sendVoice",
SendVoiceRequest(
chat_id,
voice,
business_connection_id,
message_thread_id,
caption,
parse_mode,
caption_entities,
duration,
disable_notification,
protect_content,
message_effect_id,
reply_parameters,
reply_markup,
).toJsonForRequest(),
Message.serializer()
)
/**
* As of v.4.0, Telegram clients support rounded square MPEG4 videos of up to 1 minute long. Use this method to send video messages. On success, the sent Message is returned.
*
* @property chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
* @property video_note Video note to send. Pass a file_id as String to send a video note that exists on the Telegram servers (recommended) or upload a new video using multipart/form-data. More information on Sending Files ». Sending video notes by a URL is currently unsupported
* @property business_connection_id Unique identifier of the business connection on behalf of which the message will be sent
* @property message_thread_id Unique identifier for the target message thread (topic) of the forum; for forum supergroups only
* @property duration Duration of sent video in seconds
* @property length Video width and height, i.e. diameter of the video message
* @property thumbnail Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass “attach://<file_attach_name>” if the thumbnail was uploaded using multipart/form-data under <file_attach_name>. More information on Sending Files »
* @property disable_notification Sends the message silently. Users will receive a notification with no sound.
* @property protect_content Protects the contents of the sent message from forwarding and saving
* @property message_effect_id Unique identifier of the message effect to be added to the message; for private chats only
* @property reply_parameters Description of the message to reply to
* @property reply_markup Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user
*
* @return [Message]
* */
suspend fun sendVideoNote(
chat_id: ChatId,
video_note: String,
business_connection_id: BusinessConnectionId? = null,
message_thread_id: MessageThreadId? = null,
duration: Long? = null,
length: Long? = null,
thumbnail: String? = null,
disable_notification: Boolean? = null,
protect_content: Boolean? = null,
message_effect_id: MessageEffectId? = null,
reply_parameters: ReplyParameters? = null,
reply_markup: KeyboardOption? = null,
) = telegramPost(
"$basePath/sendVideoNote",
SendVideoNoteRequest(
chat_id,
video_note,
business_connection_id,
message_thread_id,
duration,
length,
thumbnail,
disable_notification,
protect_content,
message_effect_id,
reply_parameters,
reply_markup,
).toJsonForRequest(),
Message.serializer()
)
/**
* Use this method to send paid media. On success, the sent Message is returned.
*
* @property chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername
). If the chat is a channel, all Telegram Star proceeds from this media will be credited to the chat's balance. Otherwise, they will be credited to the bot's balance.
* @property star_count The number of Telegram Stars that must be paid to buy access to the media
* @property media A JSON-serialized array describing the media to be sent; up to 10 items
* @property business_connection_id Unique identifier of the business connection on behalf of which the message will be sent
* @property caption Media caption, 0-1024 characters after entities parsing
* @property parse_mode Mode for parsing entities in the media caption. See formatting options for more details.
* @property caption_entities A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode
* @property show_caption_above_media Pass True, if the caption must be shown above the message media
* @property disable_notification Sends the message silently. Users will receive a notification with no sound.
* @property protect_content Protects the contents of the sent message from forwarding and saving
* @property reply_parameters Description of the message to reply to
* @property reply_markup Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user
*
* @return [Message]
* */
suspend fun sendPaidMedia(
chat_id: ChatId,
star_count: Long,
media: List,
business_connection_id: BusinessConnectionId? = null,
caption: String? = null,
parse_mode: ParseMode? = null,
caption_entities: List? = null,
show_caption_above_media: Boolean? = null,
disable_notification: Boolean? = null,
protect_content: Boolean? = null,
reply_parameters: ReplyParameters? = null,
reply_markup: KeyboardOption? = null,
) = telegramPost(
"$basePath/sendPaidMedia",
SendPaidMediaRequest(
chat_id,
star_count,
media,
business_connection_id,
caption,
parse_mode,
caption_entities,
show_caption_above_media,
disable_notification,
protect_content,
reply_parameters,
reply_markup,
).toJsonForRequest(),
Message.serializer()
)
/**
* Use this method to send a group of photos, videos, documents or audios as an album. Documents and audio files can be only grouped in an album with messages of the same type. On success, an array of Messages that were sent is returned.
*
* @property chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
* @property media A JSON-serialized array describing messages to be sent, must include 2-10 items
* @property business_connection_id Unique identifier of the business connection on behalf of which the message will be sent
* @property message_thread_id Unique identifier for the target message thread (topic) of the forum; for forum supergroups only
* @property disable_notification Sends messages silently. Users will receive a notification with no sound.
* @property protect_content Protects the contents of the sent messages from forwarding and saving
* @property message_effect_id Unique identifier of the message effect to be added to the message; for private chats only
* @property reply_parameters Description of the message to reply to
*
* @return [List]
* */
suspend fun sendMediaGroup(
chat_id: ChatId,
media: List,
business_connection_id: BusinessConnectionId? = null,
message_thread_id: MessageThreadId? = null,
disable_notification: Boolean? = null,
protect_content: Boolean? = null,
message_effect_id: MessageEffectId? = null,
reply_parameters: ReplyParameters? = null,
) = telegramPost(
"$basePath/sendMediaGroup",
SendMediaGroupRequest(
chat_id,
media,
business_connection_id,
message_thread_id,
disable_notification,
protect_content,
message_effect_id,
reply_parameters,
).toJsonForRequest(),
ListSerializer(Message.serializer())
)
/**
* Use this method to send point on the map. On success, the sent Message is returned.
*
* @property chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
* @property latitude Latitude of the location
* @property longitude Longitude of the location
* @property business_connection_id Unique identifier of the business connection on behalf of which the message will be sent
* @property message_thread_id Unique identifier for the target message thread (topic) of the forum; for forum supergroups only
* @property horizontal_accuracy The radius of uncertainty for the location, measured in meters; 0-1500
* @property live_period Period in seconds during which the location will be updated (see Live Locations, should be between 60 and 86400, or 0x7FFFFFFF for live locations that can be edited indefinitely.
* @property heading For live locations, a direction in which the user is moving, in degrees. Must be between 1 and 360 if specified.
* @property proximity_alert_radius For live locations, a maximum distance for proximity alerts about approaching another chat member, in meters. Must be between 1 and 100000 if specified.
* @property disable_notification Sends the message silently. Users will receive a notification with no sound.
* @property protect_content Protects the contents of the sent message from forwarding and saving
* @property message_effect_id Unique identifier of the message effect to be added to the message; for private chats only
* @property reply_parameters Description of the message to reply to
* @property reply_markup Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user
*
* @return [Message]
* */
suspend fun sendLocation(
chat_id: ChatId,
latitude: Float,
longitude: Float,
business_connection_id: BusinessConnectionId? = null,
message_thread_id: MessageThreadId? = null,
horizontal_accuracy: Float? = null,
live_period: Long? = null,
heading: Long? = null,
proximity_alert_radius: Long? = null,
disable_notification: Boolean? = null,
protect_content: Boolean? = null,
message_effect_id: MessageEffectId? = null,
reply_parameters: ReplyParameters? = null,
reply_markup: KeyboardOption? = null,
) = telegramPost(
"$basePath/sendLocation",
SendLocationRequest(
chat_id,
latitude,
longitude,
business_connection_id,
message_thread_id,
horizontal_accuracy,
live_period,
heading,
proximity_alert_radius,
disable_notification,
protect_content,
message_effect_id,
reply_parameters,
reply_markup,
).toJsonForRequest(),
Message.serializer()
)
/**
* Use this method to send information about a venue. On success, the sent Message is returned.
*
* @property chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
* @property latitude Latitude of the venue
* @property longitude Longitude of the venue
* @property title Name of the venue
* @property address Address of the venue
* @property business_connection_id Unique identifier of the business connection on behalf of which the message will be sent
* @property message_thread_id Unique identifier for the target message thread (topic) of the forum; for forum supergroups only
* @property foursquare_id Foursquare identifier of the venue
* @property foursquare_type Foursquare type of the venue, if known. (For example, “arts_entertainment/default”, “arts_entertainment/aquarium” or “food/icecream”.)
* @property google_place_id Google Places identifier of the venue
* @property google_place_type Google Places type of the venue. (See supported types.)
* @property disable_notification Sends the message silently. Users will receive a notification with no sound.
* @property protect_content Protects the contents of the sent message from forwarding and saving
* @property message_effect_id Unique identifier of the message effect to be added to the message; for private chats only
* @property reply_parameters Description of the message to reply to
* @property reply_markup Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user
*
* @return [Message]
* */
suspend fun sendVenue(
chat_id: ChatId,
latitude: Float,
longitude: Float,
title: String,
address: String,
business_connection_id: BusinessConnectionId? = null,
message_thread_id: MessageThreadId? = null,
foursquare_id: String? = null,
foursquare_type: String? = null,
google_place_id: String? = null,
google_place_type: String? = null,
disable_notification: Boolean? = null,
protect_content: Boolean? = null,
message_effect_id: MessageEffectId? = null,
reply_parameters: ReplyParameters? = null,
reply_markup: KeyboardOption? = null,
) = telegramPost(
"$basePath/sendVenue",
SendVenueRequest(
chat_id,
latitude,
longitude,
title,
address,
business_connection_id,
message_thread_id,
foursquare_id,
foursquare_type,
google_place_id,
google_place_type,
disable_notification,
protect_content,
message_effect_id,
reply_parameters,
reply_markup,
).toJsonForRequest(),
Message.serializer()
)
/**
* Use this method to send phone contacts. On success, the sent Message is returned.
*
* @property chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
* @property phone_number Contact's phone number
* @property first_name Contact's first name
* @property business_connection_id Unique identifier of the business connection on behalf of which the message will be sent
* @property message_thread_id Unique identifier for the target message thread (topic) of the forum; for forum supergroups only
* @property last_name Contact's last name
* @property vcard Additional data about the contact in the form of a vCard, 0-2048 bytes
* @property disable_notification Sends the message silently. Users will receive a notification with no sound.
* @property protect_content Protects the contents of the sent message from forwarding and saving
* @property message_effect_id Unique identifier of the message effect to be added to the message; for private chats only
* @property reply_parameters Description of the message to reply to
* @property reply_markup Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user
*
* @return [Message]
* */
suspend fun sendContact(
chat_id: ChatId,
phone_number: String,
first_name: String,
business_connection_id: BusinessConnectionId? = null,
message_thread_id: MessageThreadId? = null,
last_name: String? = null,
vcard: String? = null,
disable_notification: Boolean? = null,
protect_content: Boolean? = null,
message_effect_id: MessageEffectId? = null,
reply_parameters: ReplyParameters? = null,
reply_markup: KeyboardOption? = null,
) = telegramPost(
"$basePath/sendContact",
SendContactRequest(
chat_id,
phone_number,
first_name,
business_connection_id,
message_thread_id,
last_name,
vcard,
disable_notification,
protect_content,
message_effect_id,
reply_parameters,
reply_markup,
).toJsonForRequest(),
Message.serializer()
)
/**
* Use this method to send a native poll. On success, the sent Message is returned.
*
* @property chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
* @property question Poll question, 1-300 characters
* @property options A JSON-serialized list of 2-10 answer options
* @property business_connection_id Unique identifier of the business connection on behalf of which the message will be sent
* @property message_thread_id Unique identifier for the target message thread (topic) of the forum; for forum supergroups only
* @property question_parse_mode Mode for parsing entities in the question. See formatting options for more details. Currently, only custom emoji entities are allowed
* @property question_entities A JSON-serialized list of special entities that appear in the poll question. It can be specified instead of question_parse_mode
* @property is_anonymous True, if the poll needs to be anonymous, defaults to True
* @property type Poll type, “quiz” or “regular”, defaults to “regular”
* @property allows_multiple_answers True, if the poll allows multiple answers, ignored for polls in quiz mode, defaults to False
* @property correct_option_id 0-based identifier of the correct answer option, required for polls in quiz mode
* @property explanation Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style poll, 0-200 characters with at most 2 line feeds after entities parsing
* @property explanation_parse_mode Mode for parsing entities in the explanation. See formatting options for more details.
* @property explanation_entities A JSON-serialized list of special entities that appear in the poll explanation. It can be specified instead of explanation_parse_mode
* @property open_period Amount of time in seconds the poll will be active after creation, 5-600. Can't be used together with close_date.
* @property close_date Point in time (Unix timestamp) when the poll will be automatically closed. Must be at least 5 and no more than 600 seconds in the future. Can't be used together with open_period.
* @property is_closed Pass True if the poll needs to be immediately closed. This can be useful for poll preview.
* @property disable_notification Sends the message silently. Users will receive a notification with no sound.
* @property protect_content Protects the contents of the sent message from forwarding and saving
* @property message_effect_id Unique identifier of the message effect to be added to the message; for private chats only
* @property reply_parameters Description of the message to reply to
* @property reply_markup Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user
*
* @return [Message]
* */
suspend fun sendPoll(
chat_id: ChatId,
question: String,
options: List,
business_connection_id: BusinessConnectionId? = null,
message_thread_id: MessageThreadId? = null,
question_parse_mode: String? = null,
question_entities: List? = null,
is_anonymous: Boolean? = null,
type: String? = null,
allows_multiple_answers: Boolean? = null,
correct_option_id: Long? = null,
explanation: String? = null,
explanation_parse_mode: String? = null,
explanation_entities: List? = null,
open_period: Long? = null,
close_date: Long? = null,
is_closed: Boolean? = null,
disable_notification: Boolean? = null,
protect_content: Boolean? = null,
message_effect_id: MessageEffectId? = null,
reply_parameters: ReplyParameters? = null,
reply_markup: KeyboardOption? = null,
) = telegramPost(
"$basePath/sendPoll",
SendPollRequest(
chat_id,
question,
options,
business_connection_id,
message_thread_id,
question_parse_mode,
question_entities,
is_anonymous,
type,
allows_multiple_answers,
correct_option_id,
explanation,
explanation_parse_mode,
explanation_entities,
open_period,
close_date,
is_closed,
disable_notification,
protect_content,
message_effect_id,
reply_parameters,
reply_markup,
).toJsonForRequest(),
Message.serializer()
)
/**
* Use this method to send an animated emoji that will display a random value. On success, the sent Message is returned.
*
* @property chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
* @property business_connection_id Unique identifier of the business connection on behalf of which the message will be sent
* @property message_thread_id Unique identifier for the target message thread (topic) of the forum; for forum supergroups only
* @property emoji Emoji on which the dice throw animation is based. Currently, must be one of “”, “”, “”, “”, “”, or “”. Dice can have values 1-6 for “”, “” and “”, values 1-5 for “” and “”, and values 1-64 for “”. Defaults to “”
* @property disable_notification Sends the message silently. Users will receive a notification with no sound.
* @property protect_content Protects the contents of the sent message from forwarding
* @property message_effect_id Unique identifier of the message effect to be added to the message; for private chats only
* @property reply_parameters Description of the message to reply to
* @property reply_markup Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user
*
* @return [Message]
* */
suspend fun sendDice(
chat_id: ChatId,
business_connection_id: BusinessConnectionId? = null,
message_thread_id: MessageThreadId? = null,
emoji: String? = null,
disable_notification: Boolean? = null,
protect_content: Boolean? = null,
message_effect_id: MessageEffectId? = null,
reply_parameters: ReplyParameters? = null,
reply_markup: KeyboardOption? = null,
) = telegramPost(
"$basePath/sendDice",
SendDiceRequest(
chat_id,
business_connection_id,
message_thread_id,
emoji,
disable_notification,
protect_content,
message_effect_id,
reply_parameters,
reply_markup,
).toJsonForRequest(),
Message.serializer()
)
/**
* Use this method when you need to tell the user that something is happening on the bot's side. The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status). Returns True on success.
* Example: The ImageBot needs some time to process a request and upload the image. Instead of sending a text message along the lines of “Retrieving image, please wait…”, the bot may use sendChatAction with action = upload_photo. The user will see a “sending photo” status for the bot.
*
We only recommend using this method when a response from the bot will take a noticeable amount of time to arrive.
*
* @property chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
* @property action Type of action to broadcast. Choose one, depending on what the user is about to receive: typing for text messages, upload_photo for photos, record_video or upload_video for videos, record_voice or upload_voice for voice notes, upload_document for general files, choose_sticker for stickers, find_location for location data, record_video_note or upload_video_note for video notes.
* @property business_connection_id Unique identifier of the business connection on behalf of which the action will be sent
* @property message_thread_id Unique identifier for the target message thread; for supergroups only
*
* @return [Boolean]
* */
suspend fun sendChatAction(
chat_id: ChatId,
action: String,
business_connection_id: BusinessConnectionId? = null,
message_thread_id: MessageThreadId? = null,
) = telegramPost(
"$basePath/sendChatAction",
SendChatActionRequest(
chat_id,
action,
business_connection_id,
message_thread_id,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to change the chosen reactions on a message. Service messages can't be reacted to. Automatically forwarded messages from a channel to its discussion group have the same available reactions as messages in the channel. Bots can't use paid reactions. Returns True on success.
*
* @property chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
* @property message_id Identifier of the target message. If the message belongs to a media group, the reaction is set to the first non-deleted message in the group instead.
* @property reaction A JSON-serialized list of reaction types to set on the message. Currently, as non-premium users, bots can set up to one reaction per message. A custom emoji reaction can be used if it is either already present on the message or explicitly allowed by chat administrators. Paid reactions can't be used by bots.
* @property is_big Pass True to set the reaction with a big animation
*
* @return [Boolean]
* */
suspend fun setMessageReaction(
chat_id: ChatId,
message_id: MessageId,
reaction: List? = null,
is_big: Boolean? = null,
) = telegramPost(
"$basePath/setMessageReaction",
SetMessageReactionRequest(
chat_id,
message_id,
reaction,
is_big,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to get a list of profile pictures for a user. Returns a UserProfilePhotos object.
*
* @property user_id Unique identifier of the target user
* @property offset Sequential number of the first photo to be returned. By default, all photos are returned.
* @property limit Limits the number of photos to be retrieved. Values between 1-100 are accepted. Defaults to 100.
*
* @return [UserProfilePhotos]
* */
suspend fun getUserProfilePhotos(
user_id: UserId,
offset: Long? = null,
limit: Long? = null,
) = telegramPost(
"$basePath/getUserProfilePhotos",
GetUserProfilePhotosRequest(
user_id,
offset,
limit,
).toJsonForRequest(),
UserProfilePhotos.serializer()
)
/**
* Use this method to get basic information about a file and prepare it for downloading. For the moment, bots can download files of up to 20MB in size. On success, a File object is returned. The file can then be downloaded via the link https://api.telegram.org/file/bot<token>/<file_path>
, where <file_path>
is taken from the response. It is guaranteed that the link will be valid for at least 1 hour. When the link expires, a new one can be requested by calling getFile again.
Note: This function may not preserve the original file name and MIME type. You should save the file's MIME type and name (if available) when the File object is received.
*
* @property file_id File identifier to get information about
*
* @return [File]
* */
suspend fun getFile(
file_id: String,
) = telegramPost(
"$basePath/getFile",
GetFileRequest(
file_id,
).toJsonForRequest(),
File.serializer()
)
/**
* Use this method to ban a user in a group, a supergroup or a channel. In the case of supergroups and channels, the user will not be able to return to the chat on their own using invite links, etc., unless unbanned first. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns True on success.
*
* @property chat_id Unique identifier for the target group or username of the target supergroup or channel (in the format @channelusername
)
* @property user_id Unique identifier of the target user
* @property until_date Date when the user will be unbanned; Unix time. If user is banned for more than 366 days or less than 30 seconds from the current time they are considered to be banned forever. Applied for supergroups and channels only.
* @property revoke_messages Pass True to delete all messages from the chat for the user that is being removed. If False, the user will be able to see messages in the group that were sent before the user was removed. Always True for supergroups and channels.
*
* @return [Boolean]
* */
suspend fun banChatMember(
chat_id: ChatId,
user_id: UserId,
until_date: Long? = null,
revoke_messages: Boolean? = null,
) = telegramPost(
"$basePath/banChatMember",
BanChatMemberRequest(
chat_id,
user_id,
until_date,
revoke_messages,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to unban a previously banned user in a supergroup or channel. The user will not return to the group or channel automatically, but will be able to join via link, etc. The bot must be an administrator for this to work. By default, this method guarantees that after the call the user is not a member of the chat, but will be able to join it. So if the user is a member of the chat they will also be removed from the chat. If you don't want this, use the parameter only_if_banned. Returns True on success.
*
* @property chat_id Unique identifier for the target group or username of the target supergroup or channel (in the format @channelusername
)
* @property user_id Unique identifier of the target user
* @property only_if_banned Do nothing if the user is not banned
*
* @return [Boolean]
* */
suspend fun unbanChatMember(
chat_id: ChatId,
user_id: UserId,
only_if_banned: Boolean? = null,
) = telegramPost(
"$basePath/unbanChatMember",
UnbanChatMemberRequest(
chat_id,
user_id,
only_if_banned,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to restrict a user in a supergroup. The bot must be an administrator in the supergroup for this to work and must have the appropriate administrator rights. Pass True for all permissions to lift restrictions from a user. Returns True on success.
*
* @property chat_id Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername
)
* @property user_id Unique identifier of the target user
* @property permissions A JSON-serialized object for new user permissions
* @property use_independent_chat_permissions Pass True if chat permissions are set independently. Otherwise, the can_send_other_messages and can_add_web_page_previews permissions will imply the can_send_messages, can_send_audios, can_send_documents, can_send_photos, can_send_videos, can_send_video_notes, and can_send_voice_notes permissions; the can_send_polls permission will imply the can_send_messages permission.
* @property until_date Date when restrictions will be lifted for the user; Unix time. If user is restricted for more than 366 days or less than 30 seconds from the current time, they are considered to be restricted forever
*
* @return [Boolean]
* */
suspend fun restrictChatMember(
chat_id: ChatId,
user_id: UserId,
permissions: ChatPermissions,
use_independent_chat_permissions: Boolean? = null,
until_date: Long? = null,
) = telegramPost(
"$basePath/restrictChatMember",
RestrictChatMemberRequest(
chat_id,
user_id,
permissions,
use_independent_chat_permissions,
until_date,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to promote or demote a user in a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Pass False for all boolean parameters to demote a user. Returns True on success.
*
* @property chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
* @property user_id Unique identifier of the target user
* @property is_anonymous Pass True if the administrator's presence in the chat is hidden
* @property can_manage_chat Pass True if the administrator can access the chat event log, get boost list, see hidden supergroup and channel members, report spam messages and ignore slow mode. Implied by any other administrator privilege.
* @property can_delete_messages Pass True if the administrator can delete messages of other users
* @property can_manage_video_chats Pass True if the administrator can manage video chats
* @property can_restrict_members Pass True if the administrator can restrict, ban or unban chat members, or access supergroup statistics
* @property can_promote_members Pass True if the administrator can add new administrators with a subset of their own privileges or demote administrators that they have promoted, directly or indirectly (promoted by administrators that were appointed by him)
* @property can_change_info Pass True if the administrator can change chat title, photo and other settings
* @property can_invite_users Pass True if the administrator can invite new users to the chat
* @property can_post_stories Pass True if the administrator can post stories to the chat
* @property can_edit_stories Pass True if the administrator can edit stories posted by other users, post stories to the chat page, pin chat stories, and access the chat's story archive
* @property can_delete_stories Pass True if the administrator can delete stories posted by other users
* @property can_post_messages Pass True if the administrator can post messages in the channel, or access channel statistics; for channels only
* @property can_edit_messages Pass True if the administrator can edit messages of other users and can pin messages; for channels only
* @property can_pin_messages Pass True if the administrator can pin messages; for supergroups only
* @property can_manage_topics Pass True if the user is allowed to create, rename, close, and reopen forum topics; for supergroups only
*
* @return [Boolean]
* */
suspend fun promoteChatMember(
chat_id: ChatId,
user_id: UserId,
is_anonymous: Boolean? = null,
can_manage_chat: Boolean? = null,
can_delete_messages: Boolean? = null,
can_manage_video_chats: Boolean? = null,
can_restrict_members: Boolean? = null,
can_promote_members: Boolean? = null,
can_change_info: Boolean? = null,
can_invite_users: Boolean? = null,
can_post_stories: Boolean? = null,
can_edit_stories: Boolean? = null,
can_delete_stories: Boolean? = null,
can_post_messages: Boolean? = null,
can_edit_messages: Boolean? = null,
can_pin_messages: Boolean? = null,
can_manage_topics: Boolean? = null,
) = telegramPost(
"$basePath/promoteChatMember",
PromoteChatMemberRequest(
chat_id,
user_id,
is_anonymous,
can_manage_chat,
can_delete_messages,
can_manage_video_chats,
can_restrict_members,
can_promote_members,
can_change_info,
can_invite_users,
can_post_stories,
can_edit_stories,
can_delete_stories,
can_post_messages,
can_edit_messages,
can_pin_messages,
can_manage_topics,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to set a custom title for an administrator in a supergroup promoted by the bot. Returns True on success.
*
* @property chat_id Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername
)
* @property user_id Unique identifier of the target user
* @property custom_title New custom title for the administrator; 0-16 characters, emoji are not allowed
*
* @return [Boolean]
* */
suspend fun setChatAdministratorCustomTitle(
chat_id: ChatId,
user_id: UserId,
custom_title: String,
) = telegramPost(
"$basePath/setChatAdministratorCustomTitle",
SetChatAdministratorCustomTitleRequest(
chat_id,
user_id,
custom_title,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to ban a channel chat in a supergroup or a channel. Until the chat is unbanned, the owner of the banned chat won't be able to send messages on behalf of any of their channels. The bot must be an administrator in the supergroup or channel for this to work and must have the appropriate administrator rights. Returns True on success.
*
* @property chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
* @property sender_chat_id Unique identifier of the target sender chat
*
* @return [Boolean]
* */
suspend fun banChatSenderChat(
chat_id: ChatId,
sender_chat_id: ChatId,
) = telegramPost(
"$basePath/banChatSenderChat",
BanChatSenderChatRequest(
chat_id,
sender_chat_id,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to unban a previously banned channel chat in a supergroup or channel. The bot must be an administrator for this to work and must have the appropriate administrator rights. Returns True on success.
*
* @property chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
* @property sender_chat_id Unique identifier of the target sender chat
*
* @return [Boolean]
* */
suspend fun unbanChatSenderChat(
chat_id: ChatId,
sender_chat_id: ChatId,
) = telegramPost(
"$basePath/unbanChatSenderChat",
UnbanChatSenderChatRequest(
chat_id,
sender_chat_id,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to set default chat permissions for all members. The bot must be an administrator in the group or a supergroup for this to work and must have the can_restrict_members administrator rights. Returns True on success.
*
* @property chat_id Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername
)
* @property permissions A JSON-serialized object for new default chat permissions
* @property use_independent_chat_permissions Pass True if chat permissions are set independently. Otherwise, the can_send_other_messages and can_add_web_page_previews permissions will imply the can_send_messages, can_send_audios, can_send_documents, can_send_photos, can_send_videos, can_send_video_notes, and can_send_voice_notes permissions; the can_send_polls permission will imply the can_send_messages permission.
*
* @return [Boolean]
* */
suspend fun setChatPermissions(
chat_id: ChatId,
permissions: ChatPermissions,
use_independent_chat_permissions: Boolean? = null,
) = telegramPost(
"$basePath/setChatPermissions",
SetChatPermissionsRequest(
chat_id,
permissions,
use_independent_chat_permissions,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to generate a new primary invite link for a chat; any previously generated primary link is revoked. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns the new invite link as String on success.
* Note: Each administrator in a chat generates their own invite links. Bots can't use invite links generated by other administrators. If you want your bot to work with invite links, it will need to generate its own link using exportChatInviteLink or by calling the getChat method. If your bot needs to generate a new primary invite link replacing its previous one, use exportChatInviteLink again.
*
*
* @property chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
*
* @return [String]
* */
suspend fun exportChatInviteLink(
chat_id: ChatId,
) = telegramPost(
"$basePath/exportChatInviteLink",
ExportChatInviteLinkRequest(
chat_id,
).toJsonForRequest(),
String.serializer()
)
/**
* Use this method to create an additional invite link for a chat. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. The link can be revoked using the method revokeChatInviteLink. Returns the new invite link as ChatInviteLink object.
*
* @property chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
* @property name Invite link name; 0-32 characters
* @property expire_date Point in time (Unix timestamp) when the link will expire
* @property member_limit The maximum number of users that can be members of the chat simultaneously after joining the chat via this invite link; 1-99999
* @property creates_join_request True, if users joining the chat via the link need to be approved by chat administrators. If True, member_limit can't be specified
*
* @return [ChatInviteLink]
* */
suspend fun createChatInviteLink(
chat_id: ChatId,
name: String? = null,
expire_date: Long? = null,
member_limit: Long? = null,
creates_join_request: Boolean? = null,
) = telegramPost(
"$basePath/createChatInviteLink",
CreateChatInviteLinkRequest(
chat_id,
name,
expire_date,
member_limit,
creates_join_request,
).toJsonForRequest(),
ChatInviteLink.serializer()
)
/**
* Use this method to edit a non-primary invite link created by the bot. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns the edited invite link as a ChatInviteLink object.
*
* @property chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
* @property invite_link The invite link to edit
* @property name Invite link name; 0-32 characters
* @property expire_date Point in time (Unix timestamp) when the link will expire
* @property member_limit The maximum number of users that can be members of the chat simultaneously after joining the chat via this invite link; 1-99999
* @property creates_join_request True, if users joining the chat via the link need to be approved by chat administrators. If True, member_limit can't be specified
*
* @return [ChatInviteLink]
* */
suspend fun editChatInviteLink(
chat_id: ChatId,
invite_link: String,
name: String? = null,
expire_date: Long? = null,
member_limit: Long? = null,
creates_join_request: Boolean? = null,
) = telegramPost(
"$basePath/editChatInviteLink",
EditChatInviteLinkRequest(
chat_id,
invite_link,
name,
expire_date,
member_limit,
creates_join_request,
).toJsonForRequest(),
ChatInviteLink.serializer()
)
/**
* Use this method to create a subscription invite link for a channel chat. The bot must have the can_invite_users administrator rights. The link can be edited using the method editChatSubscriptionInviteLink or revoked using the method revokeChatInviteLink. Returns the new invite link as a ChatInviteLink object.
*
* @property chat_id Unique identifier for the target channel chat or username of the target channel (in the format @channelusername
)
* @property subscription_period The number of seconds the subscription will be active for before the next payment. Currently, it must always be 2592000 (30 days).
* @property subscription_price The amount of Telegram Stars a user must pay initially and after each subsequent subscription period to be a member of the chat; 1-2500
* @property name Invite link name; 0-32 characters
*
* @return [ChatInviteLink]
* */
suspend fun createChatSubscriptionInviteLink(
chat_id: ChatId,
subscription_period: Long,
subscription_price: Long,
name: String? = null,
) = telegramPost(
"$basePath/createChatSubscriptionInviteLink",
CreateChatSubscriptionInviteLinkRequest(
chat_id,
subscription_period,
subscription_price,
name,
).toJsonForRequest(),
ChatInviteLink.serializer()
)
/**
* Use this method to edit a subscription invite link created by the bot. The bot must have the can_invite_users administrator rights. Returns the edited invite link as a ChatInviteLink object.
*
* @property chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
* @property invite_link The invite link to edit
* @property name Invite link name; 0-32 characters
*
* @return [ChatInviteLink]
* */
suspend fun editChatSubscriptionInviteLink(
chat_id: ChatId,
invite_link: String,
name: String? = null,
) = telegramPost(
"$basePath/editChatSubscriptionInviteLink",
EditChatSubscriptionInviteLinkRequest(
chat_id,
invite_link,
name,
).toJsonForRequest(),
ChatInviteLink.serializer()
)
/**
* Use this method to revoke an invite link created by the bot. If the primary link is revoked, a new link is automatically generated. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns the revoked invite link as ChatInviteLink object.
*
* @property chat_id Unique identifier of the target chat or username of the target channel (in the format @channelusername
)
* @property invite_link The invite link to revoke
*
* @return [ChatInviteLink]
* */
suspend fun revokeChatInviteLink(
chat_id: ChatId,
invite_link: String,
) = telegramPost(
"$basePath/revokeChatInviteLink",
RevokeChatInviteLinkRequest(
chat_id,
invite_link,
).toJsonForRequest(),
ChatInviteLink.serializer()
)
/**
* Use this method to approve a chat join request. The bot must be an administrator in the chat for this to work and must have the can_invite_users administrator right. Returns True on success.
*
* @property chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
* @property user_id Unique identifier of the target user
*
* @return [Boolean]
* */
suspend fun approveChatJoinRequest(
chat_id: ChatId,
user_id: UserId,
) = telegramPost(
"$basePath/approveChatJoinRequest",
ApproveChatJoinRequestRequest(
chat_id,
user_id,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to decline a chat join request. The bot must be an administrator in the chat for this to work and must have the can_invite_users administrator right. Returns True on success.
*
* @property chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
* @property user_id Unique identifier of the target user
*
* @return [Boolean]
* */
suspend fun declineChatJoinRequest(
chat_id: ChatId,
user_id: UserId,
) = telegramPost(
"$basePath/declineChatJoinRequest",
DeclineChatJoinRequestRequest(
chat_id,
user_id,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to set a new profile photo for the chat. Photos can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns True on success.
*
* @property chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
* @property photo New chat photo, uploaded using multipart/form-data
*
* @return [Boolean]
* */
suspend fun setChatPhoto(
chat_id: ChatId,
photo: Any,
) = telegramPost(
"$basePath/setChatPhoto",
SetChatPhotoRequest(
chat_id,
photo,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to delete a chat photo. Photos can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns True on success.
*
* @property chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
*
* @return [Boolean]
* */
suspend fun deleteChatPhoto(
chat_id: ChatId,
) = telegramPost(
"$basePath/deleteChatPhoto",
DeleteChatPhotoRequest(
chat_id,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to change the title of a chat. Titles can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns True on success.
*
* @property chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
* @property title New chat title, 1-128 characters
*
* @return [Boolean]
* */
suspend fun setChatTitle(
chat_id: ChatId,
title: String,
) = telegramPost(
"$basePath/setChatTitle",
SetChatTitleRequest(
chat_id,
title,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to change the description of a group, a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns True on success.
*
* @property chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
* @property description New chat description, 0-255 characters
*
* @return [Boolean]
* */
suspend fun setChatDescription(
chat_id: ChatId,
description: String? = null,
) = telegramPost(
"$basePath/setChatDescription",
SetChatDescriptionRequest(
chat_id,
description,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to add a message to the list of pinned messages in a chat. If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must have the 'can_pin_messages' administrator right in a supergroup or 'can_edit_messages' administrator right in a channel. Returns True on success.
*
* @property chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
* @property message_id Identifier of a message to pin
* @property business_connection_id Unique identifier of the business connection on behalf of which the message will be pinned
* @property disable_notification Pass True if it is not necessary to send a notification to all chat members about the new pinned message. Notifications are always disabled in channels and private chats.
*
* @return [Boolean]
* */
suspend fun pinChatMessage(
chat_id: ChatId,
message_id: MessageId,
business_connection_id: BusinessConnectionId? = null,
disable_notification: Boolean? = null,
) = telegramPost(
"$basePath/pinChatMessage",
PinChatMessageRequest(
chat_id,
message_id,
business_connection_id,
disable_notification,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to remove a message from the list of pinned messages in a chat. If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must have the 'can_pin_messages' administrator right in a supergroup or 'can_edit_messages' administrator right in a channel. Returns True on success.
*
* @property chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
* @property business_connection_id Unique identifier of the business connection on behalf of which the message will be unpinned
* @property message_id Identifier of the message to unpin. Required if business_connection_id is specified. If not specified, the most recent pinned message (by sending date) will be unpinned.
*
* @return [Boolean]
* */
suspend fun unpinChatMessage(
chat_id: ChatId,
business_connection_id: BusinessConnectionId? = null,
message_id: MessageId? = null,
) = telegramPost(
"$basePath/unpinChatMessage",
UnpinChatMessageRequest(
chat_id,
business_connection_id,
message_id,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to clear the list of pinned messages in a chat. If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must have the 'can_pin_messages' administrator right in a supergroup or 'can_edit_messages' administrator right in a channel. Returns True on success.
*
* @property chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
*
* @return [Boolean]
* */
suspend fun unpinAllChatMessages(
chat_id: ChatId,
) = telegramPost(
"$basePath/unpinAllChatMessages",
UnpinAllChatMessagesRequest(
chat_id,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method for your bot to leave a group, supergroup or channel. Returns True on success.
*
* @property chat_id Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername
)
*
* @return [Boolean]
* */
suspend fun leaveChat(
chat_id: ChatId,
) = telegramPost(
"$basePath/leaveChat",
LeaveChatRequest(
chat_id,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to get up-to-date information about the chat. Returns a ChatFullInfo object on success.
*
* @property chat_id Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername
)
*
* @return [ChatFullInfo]
* */
suspend fun getChat(
chat_id: ChatId,
) = telegramPost(
"$basePath/getChat",
GetChatRequest(
chat_id,
).toJsonForRequest(),
ChatFullInfo.serializer()
)
/**
* Use this method to get a list of administrators in a chat, which aren't bots. Returns an Array of ChatMember objects.
*
* @property chat_id Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername
)
*
* @return [List]
* */
suspend fun getChatAdministrators(
chat_id: ChatId,
) = telegramPost(
"$basePath/getChatAdministrators",
GetChatAdministratorsRequest(
chat_id,
).toJsonForRequest(),
ListSerializer(ChatMember.serializer())
)
/**
* Use this method to get the number of members in a chat. Returns Int on success.
*
* @property chat_id Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername
)
*
* @return [Int]
* */
suspend fun getChatMemberCount(
chat_id: ChatId,
) = telegramPost(
"$basePath/getChatMemberCount",
GetChatMemberCountRequest(
chat_id,
).toJsonForRequest(),
Int.serializer()
)
/**
* Use this method to get information about a member of a chat. The method is only guaranteed to work for other users if the bot is an administrator in the chat. Returns a ChatMember object on success.
*
* @property chat_id Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername
)
* @property user_id Unique identifier of the target user
*
* @return [ChatMember]
* */
suspend fun getChatMember(
chat_id: ChatId,
user_id: UserId,
) = telegramPost(
"$basePath/getChatMember",
GetChatMemberRequest(
chat_id,
user_id,
).toJsonForRequest(),
ChatMember.serializer()
)
/**
* Use this method to set a new group sticker set for a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Use the field can_set_sticker_set optionally returned in getChat requests to check if the bot can use this method. Returns True on success.
*
* @property chat_id Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername
)
* @property sticker_set_name Name of the sticker set to be set as the group sticker set
*
* @return [Boolean]
* */
suspend fun setChatStickerSet(
chat_id: ChatId,
sticker_set_name: String,
) = telegramPost(
"$basePath/setChatStickerSet",
SetChatStickerSetRequest(
chat_id,
sticker_set_name,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to delete a group sticker set from a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Use the field can_set_sticker_set optionally returned in getChat requests to check if the bot can use this method. Returns True on success.
*
* @property chat_id Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername
)
*
* @return [Boolean]
* */
suspend fun deleteChatStickerSet(
chat_id: ChatId,
) = telegramPost(
"$basePath/deleteChatStickerSet",
DeleteChatStickerSetRequest(
chat_id,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to get custom emoji stickers, which can be used as a forum topic icon by any user. Requires no parameters. Returns an Array of Sticker objects.
*
*
* @return [List]
* */
suspend fun getForumTopicIconStickers() =
telegramGet("$basePath/getForumTopicIconStickers", ListSerializer(Sticker.serializer()))
/**
* Use this method to create a topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights. Returns information about the created topic as a ForumTopic object.
*
* @property chat_id Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername
)
* @property name Topic name, 1-128 characters
* @property icon_color Color of the topic icon in RGB format. Currently, must be one of 7322096 (0x6FB9F0), 16766590 (0xFFD67E), 13338331 (0xCB86DB), 9367192 (0x8EEE98), 16749490 (0xFF93B2), or 16478047 (0xFB6F5F)
* @property icon_custom_emoji_id Unique identifier of the custom emoji shown as the topic icon. Use getForumTopicIconStickers to get all allowed custom emoji identifiers.
*
* @return [ForumTopic]
* */
suspend fun createForumTopic(
chat_id: ChatId,
name: String,
icon_color: Long? = null,
icon_custom_emoji_id: String? = null,
) = telegramPost(
"$basePath/createForumTopic",
CreateForumTopicRequest(
chat_id,
name,
icon_color,
icon_custom_emoji_id,
).toJsonForRequest(),
ForumTopic.serializer()
)
/**
* Use this method to edit name and icon of a topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic. Returns True on success.
*
* @property chat_id Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername
)
* @property message_thread_id Unique identifier for the target message thread of the forum topic
* @property name New topic name, 0-128 characters. If not specified or empty, the current name of the topic will be kept
* @property icon_custom_emoji_id New unique identifier of the custom emoji shown as the topic icon. Use getForumTopicIconStickers to get all allowed custom emoji identifiers. Pass an empty string to remove the icon. If not specified, the current icon will be kept
*
* @return [Boolean]
* */
suspend fun editForumTopic(
chat_id: ChatId,
message_thread_id: MessageThreadId,
name: String? = null,
icon_custom_emoji_id: String? = null,
) = telegramPost(
"$basePath/editForumTopic",
EditForumTopicRequest(
chat_id,
message_thread_id,
name,
icon_custom_emoji_id,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to close an open topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic. Returns True on success.
*
* @property chat_id Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername
)
* @property message_thread_id Unique identifier for the target message thread of the forum topic
*
* @return [Boolean]
* */
suspend fun closeForumTopic(
chat_id: ChatId,
message_thread_id: MessageThreadId,
) = telegramPost(
"$basePath/closeForumTopic",
CloseForumTopicRequest(
chat_id,
message_thread_id,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to reopen a closed topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic. Returns True on success.
*
* @property chat_id Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername
)
* @property message_thread_id Unique identifier for the target message thread of the forum topic
*
* @return [Boolean]
* */
suspend fun reopenForumTopic(
chat_id: ChatId,
message_thread_id: MessageThreadId,
) = telegramPost(
"$basePath/reopenForumTopic",
ReopenForumTopicRequest(
chat_id,
message_thread_id,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to delete a forum topic along with all its messages in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_delete_messages administrator rights. Returns True on success.
*
* @property chat_id Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername
)
* @property message_thread_id Unique identifier for the target message thread of the forum topic
*
* @return [Boolean]
* */
suspend fun deleteForumTopic(
chat_id: ChatId,
message_thread_id: MessageThreadId,
) = telegramPost(
"$basePath/deleteForumTopic",
DeleteForumTopicRequest(
chat_id,
message_thread_id,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to clear the list of pinned messages in a forum topic. The bot must be an administrator in the chat for this to work and must have the can_pin_messages administrator right in the supergroup. Returns True on success.
*
* @property chat_id Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername
)
* @property message_thread_id Unique identifier for the target message thread of the forum topic
*
* @return [Boolean]
* */
suspend fun unpinAllForumTopicMessages(
chat_id: ChatId,
message_thread_id: MessageThreadId,
) = telegramPost(
"$basePath/unpinAllForumTopicMessages",
UnpinAllForumTopicMessagesRequest(
chat_id,
message_thread_id,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to edit the name of the 'General' topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights. Returns True on success.
*
* @property chat_id Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername
)
* @property name New topic name, 1-128 characters
*
* @return [Boolean]
* */
suspend fun editGeneralForumTopic(
chat_id: ChatId,
name: String,
) = telegramPost(
"$basePath/editGeneralForumTopic",
EditGeneralForumTopicRequest(
chat_id,
name,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to close an open 'General' topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights. Returns True on success.
*
* @property chat_id Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername
)
*
* @return [Boolean]
* */
suspend fun closeGeneralForumTopic(
chat_id: ChatId,
) = telegramPost(
"$basePath/closeGeneralForumTopic",
CloseGeneralForumTopicRequest(
chat_id,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to reopen a closed 'General' topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights. The topic will be automatically unhidden if it was hidden. Returns True on success.
*
* @property chat_id Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername
)
*
* @return [Boolean]
* */
suspend fun reopenGeneralForumTopic(
chat_id: ChatId,
) = telegramPost(
"$basePath/reopenGeneralForumTopic",
ReopenGeneralForumTopicRequest(
chat_id,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to hide the 'General' topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights. The topic will be automatically closed if it was open. Returns True on success.
*
* @property chat_id Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername
)
*
* @return [Boolean]
* */
suspend fun hideGeneralForumTopic(
chat_id: ChatId,
) = telegramPost(
"$basePath/hideGeneralForumTopic",
HideGeneralForumTopicRequest(
chat_id,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to unhide the 'General' topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights. Returns True on success.
*
* @property chat_id Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername
)
*
* @return [Boolean]
* */
suspend fun unhideGeneralForumTopic(
chat_id: ChatId,
) = telegramPost(
"$basePath/unhideGeneralForumTopic",
UnhideGeneralForumTopicRequest(
chat_id,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to clear the list of pinned messages in a General forum topic. The bot must be an administrator in the chat for this to work and must have the can_pin_messages administrator right in the supergroup. Returns True on success.
*
* @property chat_id Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername
)
*
* @return [Boolean]
* */
suspend fun unpinAllGeneralForumTopicMessages(
chat_id: ChatId,
) = telegramPost(
"$basePath/unpinAllGeneralForumTopicMessages",
UnpinAllGeneralForumTopicMessagesRequest(
chat_id,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to send answers to callback queries sent from inline keyboards. The answer will be displayed to the user as a notification at the top of the chat screen or as an alert. On success, True is returned.
* Alternatively, the user can be redirected to the specified Game URL. For this option to work, you must first create a game for your bot via @BotFather and accept the terms. Otherwise, you may use links like t.me/your_bot?start=XXXX
that open your bot with a parameter.
*
*
* @property callback_query_id Unique identifier for the query to be answered
* @property text Text of the notification. If not specified, nothing will be shown to the user, 0-200 characters
* @property show_alert If True, an alert will be shown by the client instead of a notification at the top of the chat screen. Defaults to false.
* @property url URL that will be opened by the user's client. If you have created a Game and accepted the conditions via @BotFather, specify the URL that opens your game - note that this will only work if the query comes from a callback_game button.
Otherwise, you may use links like t.me/your_bot?start=XXXX
that open your bot with a parameter.
* @property cache_time The maximum amount of time in seconds that the result of the callback query may be cached client-side. Telegram apps will support caching starting in version 3.14. Defaults to 0.
*
* @return [Boolean]
* */
suspend fun answerCallbackQuery(
callback_query_id: String,
text: String? = null,
show_alert: Boolean? = null,
url: String? = null,
cache_time: Long? = null,
) = telegramPost(
"$basePath/answerCallbackQuery",
AnswerCallbackQueryRequest(
callback_query_id,
text,
show_alert,
url,
cache_time,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to get the list of boosts added to a chat by a user. Requires administrator rights in the chat. Returns a UserChatBoosts object.
*
* @property chat_id Unique identifier for the chat or username of the channel (in the format @channelusername
)
* @property user_id Unique identifier of the target user
*
* @return [UserChatBoosts]
* */
suspend fun getUserChatBoosts(
chat_id: ChatId,
user_id: UserId,
) = telegramPost(
"$basePath/getUserChatBoosts",
GetUserChatBoostsRequest(
chat_id,
user_id,
).toJsonForRequest(),
UserChatBoosts.serializer()
)
/**
* Use this method to get information about the connection of the bot with a business account. Returns a BusinessConnection object on success.
*
* @property business_connection_id Unique identifier of the business connection
*
* @return [BusinessConnection]
* */
suspend fun getBusinessConnection(
business_connection_id: BusinessConnectionId,
) = telegramPost(
"$basePath/getBusinessConnection",
GetBusinessConnectionRequest(
business_connection_id,
).toJsonForRequest(),
BusinessConnection.serializer()
)
/**
* Use this method to change the list of the bot's commands. See this manual for more details about bot commands. Returns True on success.
*
* @property commands A JSON-serialized list of bot commands to be set as the list of the bot's commands. At most 100 commands can be specified.
* @property scope A JSON-serialized object, describing scope of users for which the commands are relevant. Defaults to BotCommandScopeDefault.
* @property language_code A two-letter ISO 639-1 language code. If empty, commands will be applied to all users from the given scope, for whose language there are no dedicated commands
*
* @return [Boolean]
* */
suspend fun setMyCommands(
commands: List,
scope: BotCommandScope? = null,
language_code: String? = null,
) = telegramPost(
"$basePath/setMyCommands",
SetMyCommandsRequest(
commands,
scope,
language_code,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to delete the list of the bot's commands for the given scope and user language. After deletion, higher level commands will be shown to affected users. Returns True on success.
*
* @property scope A JSON-serialized object, describing scope of users for which the commands are relevant. Defaults to BotCommandScopeDefault.
* @property language_code A two-letter ISO 639-1 language code. If empty, commands will be applied to all users from the given scope, for whose language there are no dedicated commands
*
* @return [Boolean]
* */
suspend fun deleteMyCommands(
scope: BotCommandScope? = null,
language_code: String? = null,
) = telegramPost(
"$basePath/deleteMyCommands",
DeleteMyCommandsRequest(
scope,
language_code,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to get the current list of the bot's commands for the given scope and user language. Returns an Array of BotCommand objects. If commands aren't set, an empty list is returned.
*
* @property scope A JSON-serialized object, describing scope of users. Defaults to BotCommandScopeDefault.
* @property language_code A two-letter ISO 639-1 language code or an empty string
*
* @return [List]
* */
suspend fun getMyCommands(
scope: BotCommandScope? = null,
language_code: String? = null,
) = telegramPost(
"$basePath/getMyCommands",
GetMyCommandsRequest(
scope,
language_code,
).toJsonForRequest(),
ListSerializer(BotCommand.serializer())
)
/**
* Use this method to change the bot's name. Returns True on success.
*
* @property name New bot name; 0-64 characters. Pass an empty string to remove the dedicated name for the given language.
* @property language_code A two-letter ISO 639-1 language code. If empty, the name will be shown to all users for whose language there is no dedicated name.
*
* @return [Boolean]
* */
suspend fun setMyName(
name: String? = null,
language_code: String? = null,
) = telegramPost(
"$basePath/setMyName",
SetMyNameRequest(
name,
language_code,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to get the current bot name for the given user language. Returns BotName on success.
*
* @property language_code A two-letter ISO 639-1 language code or an empty string
*
* @return [BotName]
* */
suspend fun getMyName(
language_code: String? = null,
) = telegramPost(
"$basePath/getMyName",
GetMyNameRequest(
language_code,
).toJsonForRequest(),
BotName.serializer()
)
/**
* Use this method to change the bot's description, which is shown in the chat with the bot if the chat is empty. Returns True on success.
*
* @property description New bot description; 0-512 characters. Pass an empty string to remove the dedicated description for the given language.
* @property language_code A two-letter ISO 639-1 language code. If empty, the description will be applied to all users for whose language there is no dedicated description.
*
* @return [Boolean]
* */
suspend fun setMyDescription(
description: String? = null,
language_code: String? = null,
) = telegramPost(
"$basePath/setMyDescription",
SetMyDescriptionRequest(
description,
language_code,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to get the current bot description for the given user language. Returns BotDescription on success.
*
* @property language_code A two-letter ISO 639-1 language code or an empty string
*
* @return [BotDescription]
* */
suspend fun getMyDescription(
language_code: String? = null,
) = telegramPost(
"$basePath/getMyDescription",
GetMyDescriptionRequest(
language_code,
).toJsonForRequest(),
BotDescription.serializer()
)
/**
* Use this method to change the bot's short description, which is shown on the bot's profile page and is sent together with the link when users share the bot. Returns True on success.
*
* @property short_description New short description for the bot; 0-120 characters. Pass an empty string to remove the dedicated short description for the given language.
* @property language_code A two-letter ISO 639-1 language code. If empty, the short description will be applied to all users for whose language there is no dedicated short description.
*
* @return [Boolean]
* */
suspend fun setMyShortDescription(
short_description: String? = null,
language_code: String? = null,
) = telegramPost(
"$basePath/setMyShortDescription",
SetMyShortDescriptionRequest(
short_description,
language_code,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to get the current bot short description for the given user language. Returns BotShortDescription on success.
*
* @property language_code A two-letter ISO 639-1 language code or an empty string
*
* @return [BotShortDescription]
* */
suspend fun getMyShortDescription(
language_code: String? = null,
) = telegramPost(
"$basePath/getMyShortDescription",
GetMyShortDescriptionRequest(
language_code,
).toJsonForRequest(),
BotShortDescription.serializer()
)
/**
* Use this method to change the bot's menu button in a private chat, or the default menu button. Returns True on success.
*
* @property chat_id Unique identifier for the target private chat. If not specified, default bot's menu button will be changed
* @property menu_button A JSON-serialized object for the bot's new menu button. Defaults to MenuButtonDefault
*
* @return [Boolean]
* */
suspend fun setChatMenuButton(
chat_id: ChatId? = null,
menu_button: MenuButton? = null,
) = telegramPost(
"$basePath/setChatMenuButton",
SetChatMenuButtonRequest(
chat_id,
menu_button,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to get the current value of the bot's menu button in a private chat, or the default menu button. Returns MenuButton on success.
*
* @property chat_id Unique identifier for the target private chat. If not specified, default bot's menu button will be returned
*
* @return [MenuButton]
* */
suspend fun getChatMenuButton(
chat_id: ChatId? = null,
) = telegramPost(
"$basePath/getChatMenuButton",
GetChatMenuButtonRequest(
chat_id,
).toJsonForRequest(),
MenuButton.serializer()
)
/**
* Use this method to change the default administrator rights requested by the bot when it's added as an administrator to groups or channels. These rights will be suggested to users, but they are free to modify the list before adding the bot. Returns True on success.
*
* @property rights A JSON-serialized object describing new default administrator rights. If not specified, the default administrator rights will be cleared.
* @property for_channels Pass True to change the default administrator rights of the bot in channels. Otherwise, the default administrator rights of the bot for groups and supergroups will be changed.
*
* @return [Boolean]
* */
suspend fun setMyDefaultAdministratorRights(
rights: ChatAdministratorRights? = null,
for_channels: Boolean? = null,
) = telegramPost(
"$basePath/setMyDefaultAdministratorRights",
SetMyDefaultAdministratorRightsRequest(
rights,
for_channels,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to get the current default administrator rights of the bot. Returns ChatAdministratorRights on success.
*
* @property for_channels Pass True to get default administrator rights of the bot in channels. Otherwise, default administrator rights of the bot for groups and supergroups will be returned.
*
* @return [ChatAdministratorRights]
* */
suspend fun getMyDefaultAdministratorRights(
for_channels: Boolean? = null,
) = telegramPost(
"$basePath/getMyDefaultAdministratorRights",
GetMyDefaultAdministratorRightsRequest(
for_channels,
).toJsonForRequest(),
ChatAdministratorRights.serializer()
)
// Updating messages
/**
* Use this method to edit text and game messages. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. Note that business messages that were not sent by the bot and do not contain an inline keyboard can only be edited within 48 hours from the time they were sent.
*
* @property text New text of the message, 1-4096 characters after entities parsing
* @property business_connection_id Unique identifier of the business connection on behalf of which the message to be edited was sent
* @property chat_id Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
* @property message_id Required if inline_message_id is not specified. Identifier of the message to edit
* @property inline_message_id Required if chat_id and message_id are not specified. Identifier of the inline message
* @property parse_mode Mode for parsing entities in the message text. See formatting options for more details.
* @property entities A JSON-serialized list of special entities that appear in message text, which can be specified instead of parse_mode
* @property link_preview_options Link preview generation options for the message
* @property reply_markup A JSON-serialized object for an inline keyboard.
*
* @return [Message]
* */
suspend fun editMessageText(
text: String,
business_connection_id: BusinessConnectionId? = null,
chat_id: ChatId? = null,
message_id: MessageId? = null,
inline_message_id: String? = null,
parse_mode: ParseMode? = null,
entities: List? = null,
link_preview_options: LinkPreviewOptions? = null,
reply_markup: InlineKeyboardMarkup? = null,
) = telegramPost(
"$basePath/editMessageText",
EditMessageTextRequest(
text,
business_connection_id,
chat_id,
message_id,
inline_message_id,
parse_mode,
entities,
link_preview_options,
reply_markup,
).toJsonForRequest(),
Message.serializer()
)
/**
* Use this method to edit captions of messages. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. Note that business messages that were not sent by the bot and do not contain an inline keyboard can only be edited within 48 hours from the time they were sent.
*
* @property business_connection_id Unique identifier of the business connection on behalf of which the message to be edited was sent
* @property chat_id Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
* @property message_id Required if inline_message_id is not specified. Identifier of the message to edit
* @property inline_message_id Required if chat_id and message_id are not specified. Identifier of the inline message
* @property caption New caption of the message, 0-1024 characters after entities parsing
* @property parse_mode Mode for parsing entities in the message caption. See formatting options for more details.
* @property caption_entities A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode
* @property show_caption_above_media Pass True, if the caption must be shown above the message media. Supported only for animation, photo and video messages.
* @property reply_markup A JSON-serialized object for an inline keyboard.
*
* @return [Message]
* */
suspend fun editMessageCaption(
business_connection_id: BusinessConnectionId? = null,
chat_id: ChatId? = null,
message_id: MessageId? = null,
inline_message_id: String? = null,
caption: String? = null,
parse_mode: ParseMode? = null,
caption_entities: List? = null,
show_caption_above_media: Boolean? = null,
reply_markup: InlineKeyboardMarkup? = null,
) = telegramPost(
"$basePath/editMessageCaption",
EditMessageCaptionRequest(
business_connection_id,
chat_id,
message_id,
inline_message_id,
caption,
parse_mode,
caption_entities,
show_caption_above_media,
reply_markup,
).toJsonForRequest(),
Message.serializer()
)
/**
* Use this method to edit animation, audio, document, photo, or video messages. If a message is part of a message album, then it can be edited only to an audio for audio albums, only to a document for document albums and to a photo or a video otherwise. When an inline message is edited, a new file can't be uploaded; use a previously uploaded file via its file_id or specify a URL. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. Note that business messages that were not sent by the bot and do not contain an inline keyboard can only be edited within 48 hours from the time they were sent.
*
* @property media A JSON-serialized object for a new media content of the message
* @property business_connection_id Unique identifier of the business connection on behalf of which the message to be edited was sent
* @property chat_id Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
* @property message_id Required if inline_message_id is not specified. Identifier of the message to edit
* @property inline_message_id Required if chat_id and message_id are not specified. Identifier of the inline message
* @property reply_markup A JSON-serialized object for a new inline keyboard.
*
* @return [Message]
* */
suspend fun editMessageMedia(
media: InputMedia,
business_connection_id: BusinessConnectionId? = null,
chat_id: ChatId? = null,
message_id: MessageId? = null,
inline_message_id: String? = null,
reply_markup: InlineKeyboardMarkup? = null,
) = telegramPost(
"$basePath/editMessageMedia",
EditMessageMediaRequest(
media,
business_connection_id,
chat_id,
message_id,
inline_message_id,
reply_markup,
).toJsonForRequest(),
Message.serializer()
)
/**
* Use this method to edit live location messages. A location can be edited until its live_period expires or editing is explicitly disabled by a call to stopMessageLiveLocation. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned.
*
* @property latitude Latitude of new location
* @property longitude Longitude of new location
* @property business_connection_id Unique identifier of the business connection on behalf of which the message to be edited was sent
* @property chat_id Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
* @property message_id Required if inline_message_id is not specified. Identifier of the message to edit
* @property inline_message_id Required if chat_id and message_id are not specified. Identifier of the inline message
* @property live_period New period in seconds during which the location can be updated, starting from the message send date. If 0x7FFFFFFF is specified, then the location can be updated forever. Otherwise, the new value must not exceed the current live_period by more than a day, and the live location expiration date must remain within the next 90 days. If not specified, then live_period remains unchanged
* @property horizontal_accuracy The radius of uncertainty for the location, measured in meters; 0-1500
* @property heading Direction in which the user is moving, in degrees. Must be between 1 and 360 if specified.
* @property proximity_alert_radius The maximum distance for proximity alerts about approaching another chat member, in meters. Must be between 1 and 100000 if specified.
* @property reply_markup A JSON-serialized object for a new inline keyboard.
*
* @return [Message]
* */
suspend fun editMessageLiveLocation(
latitude: Float,
longitude: Float,
business_connection_id: BusinessConnectionId? = null,
chat_id: ChatId? = null,
message_id: MessageId? = null,
inline_message_id: String? = null,
live_period: Long? = null,
horizontal_accuracy: Float? = null,
heading: Long? = null,
proximity_alert_radius: Long? = null,
reply_markup: InlineKeyboardMarkup? = null,
) = telegramPost(
"$basePath/editMessageLiveLocation",
EditMessageLiveLocationRequest(
latitude,
longitude,
business_connection_id,
chat_id,
message_id,
inline_message_id,
live_period,
horizontal_accuracy,
heading,
proximity_alert_radius,
reply_markup,
).toJsonForRequest(),
Message.serializer()
)
/**
* Use this method to stop updating a live location message before live_period expires. On success, if the message is not an inline message, the edited Message is returned, otherwise True is returned.
*
* @property business_connection_id Unique identifier of the business connection on behalf of which the message to be edited was sent
* @property chat_id Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
* @property message_id Required if inline_message_id is not specified. Identifier of the message with live location to stop
* @property inline_message_id Required if chat_id and message_id are not specified. Identifier of the inline message
* @property reply_markup A JSON-serialized object for a new inline keyboard.
*
* @return [Message]
* */
suspend fun stopMessageLiveLocation(
business_connection_id: BusinessConnectionId? = null,
chat_id: ChatId? = null,
message_id: MessageId? = null,
inline_message_id: String? = null,
reply_markup: InlineKeyboardMarkup? = null,
) = telegramPost(
"$basePath/stopMessageLiveLocation",
StopMessageLiveLocationRequest(
business_connection_id,
chat_id,
message_id,
inline_message_id,
reply_markup,
).toJsonForRequest(),
Message.serializer()
)
/**
* Use this method to edit only the reply markup of messages. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. Note that business messages that were not sent by the bot and do not contain an inline keyboard can only be edited within 48 hours from the time they were sent.
*
* @property business_connection_id Unique identifier of the business connection on behalf of which the message to be edited was sent
* @property chat_id Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
* @property message_id Required if inline_message_id is not specified. Identifier of the message to edit
* @property inline_message_id Required if chat_id and message_id are not specified. Identifier of the inline message
* @property reply_markup A JSON-serialized object for an inline keyboard.
*
* @return [Message]
* */
suspend fun editMessageReplyMarkup(
business_connection_id: BusinessConnectionId? = null,
chat_id: ChatId? = null,
message_id: MessageId? = null,
inline_message_id: String? = null,
reply_markup: InlineKeyboardMarkup? = null,
) = telegramPost(
"$basePath/editMessageReplyMarkup",
EditMessageReplyMarkupRequest(
business_connection_id,
chat_id,
message_id,
inline_message_id,
reply_markup,
).toJsonForRequest(),
Message.serializer()
)
/**
* Use this method to stop a poll which was sent by the bot. On success, the stopped Poll is returned.
*
* @property chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
* @property message_id Identifier of the original message with the poll
* @property business_connection_id Unique identifier of the business connection on behalf of which the message to be edited was sent
* @property reply_markup A JSON-serialized object for a new message inline keyboard.
*
* @return [Poll]
* */
suspend fun stopPoll(
chat_id: ChatId,
message_id: MessageId,
business_connection_id: BusinessConnectionId? = null,
reply_markup: InlineKeyboardMarkup? = null,
) = telegramPost(
"$basePath/stopPoll",
StopPollRequest(
chat_id,
message_id,
business_connection_id,
reply_markup,
).toJsonForRequest(),
Poll.serializer()
)
/**
* Use this method to delete a message, including service messages, with the following limitations:
- A message can only be deleted if it was sent less than 48 hours ago.
- Service messages about a supergroup, channel, or forum topic creation can't be deleted.
- A dice message in a private chat can only be deleted if it was sent more than 24 hours ago.
- Bots can delete outgoing messages in private chats, groups, and supergroups.
- Bots can delete incoming messages in private chats.
- Bots granted can_post_messages permissions can delete outgoing messages in channels.
- If the bot is an administrator of a group, it can delete any message there.
- If the bot has can_delete_messages permission in a supergroup or a channel, it can delete any message there.
Returns True on success.
*
* @property chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
* @property message_id Identifier of the message to delete
*
* @return [Boolean]
* */
suspend fun deleteMessage(
chat_id: ChatId,
message_id: MessageId,
) = telegramPost(
"$basePath/deleteMessage",
DeleteMessageRequest(
chat_id,
message_id,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to delete multiple messages simultaneously. If some of the specified messages can't be found, they are skipped. Returns True on success.
*
* @property chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
* @property message_ids A JSON-serialized list of 1-100 identifiers of messages to delete. See deleteMessage for limitations on which messages can be deleted
*
* @return [Boolean]
* */
suspend fun deleteMessages(
chat_id: ChatId,
message_ids: List,
) = telegramPost(
"$basePath/deleteMessages",
DeleteMessagesRequest(
chat_id,
message_ids,
).toJsonForRequest(),
Boolean.serializer()
)
// Stickers
/**
* Use this method to send static .WEBP, animated .TGS, or video .WEBM stickers. On success, the sent Message is returned.
*
* @property chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
* @property sticker Sticker to send. Pass a file_id as String to send a file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a .WEBP sticker from the Internet, or upload a new .WEBP, .TGS, or .WEBM sticker using multipart/form-data. More information on Sending Files ». Video and animated stickers can't be sent via an HTTP URL.
* @property business_connection_id Unique identifier of the business connection on behalf of which the message will be sent
* @property message_thread_id Unique identifier for the target message thread (topic) of the forum; for forum supergroups only
* @property emoji Emoji associated with the sticker; only for just uploaded stickers
* @property disable_notification Sends the message silently. Users will receive a notification with no sound.
* @property protect_content Protects the contents of the sent message from forwarding and saving
* @property message_effect_id Unique identifier of the message effect to be added to the message; for private chats only
* @property reply_parameters Description of the message to reply to
* @property reply_markup Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user
*
* @return [Message]
* */
suspend fun sendSticker(
chat_id: ChatId,
sticker: String,
business_connection_id: BusinessConnectionId? = null,
message_thread_id: MessageThreadId? = null,
emoji: String? = null,
disable_notification: Boolean? = null,
protect_content: Boolean? = null,
message_effect_id: MessageEffectId? = null,
reply_parameters: ReplyParameters? = null,
reply_markup: KeyboardOption? = null,
) = telegramPost(
"$basePath/sendSticker",
SendStickerRequest(
chat_id,
sticker,
business_connection_id,
message_thread_id,
emoji,
disable_notification,
protect_content,
message_effect_id,
reply_parameters,
reply_markup,
).toJsonForRequest(),
Message.serializer()
)
/**
* Use this method to get a sticker set. On success, a StickerSet object is returned.
*
* @property name Name of the sticker set
*
* @return [StickerSet]
* */
suspend fun getStickerSet(
name: String,
) = telegramPost(
"$basePath/getStickerSet",
GetStickerSetRequest(
name,
).toJsonForRequest(),
StickerSet.serializer()
)
/**
* Use this method to get information about custom emoji stickers by their identifiers. Returns an Array of Sticker objects.
*
* @property custom_emoji_ids A JSON-serialized list of custom emoji identifiers. At most 200 custom emoji identifiers can be specified.
*
* @return [List]
* */
suspend fun getCustomEmojiStickers(
custom_emoji_ids: List,
) = telegramPost(
"$basePath/getCustomEmojiStickers",
GetCustomEmojiStickersRequest(
custom_emoji_ids,
).toJsonForRequest(),
ListSerializer(Sticker.serializer())
)
/**
* Use this method to upload a file with a sticker for later use in the createNewStickerSet, addStickerToSet, or replaceStickerInSet methods (the file can be used multiple times). Returns the uploaded File on success.
*
* @property user_id User identifier of sticker file owner
* @property sticker A file with the sticker in .WEBP, .PNG, .TGS, or .WEBM format. See https://core.telegram.org/stickers for technical requirements. More information on Sending Files »
* @property sticker_format Format of the sticker, must be one of “static”, “animated”, “video”
*
* @return [File]
* */
suspend fun uploadStickerFile(
user_id: UserId,
sticker: Any,
sticker_format: String,
) = telegramPost(
"$basePath/uploadStickerFile",
UploadStickerFileRequest(
user_id,
sticker,
sticker_format,
).toJsonForRequest(),
File.serializer()
)
/**
* Use this method to create a new sticker set owned by a user. The bot will be able to edit the sticker set thus created. Returns True on success.
*
* @property user_id User identifier of created sticker set owner
* @property name Short name of sticker set, to be used in t.me/addstickers/
URLs (e.g., animals). Can contain only English letters, digits and underscores. Must begin with a letter, can't contain consecutive underscores and must end in "_by_<bot_username>"
. <bot_username>
is case insensitive. 1-64 characters.
* @property title Sticker set title, 1-64 characters
* @property stickers A JSON-serialized list of 1-50 initial stickers to be added to the sticker set
* @property sticker_type Type of stickers in the set, pass “regular”, “mask”, or “custom_emoji”. By default, a regular sticker set is created.
* @property needs_repainting Pass True if stickers in the sticker set must be repainted to the color of text when used in messages, the accent color if used as emoji status, white on chat photos, or another appropriate color based on context; for custom emoji sticker sets only
*
* @return [Boolean]
* */
suspend fun createNewStickerSet(
user_id: UserId,
name: String,
title: String,
stickers: List,
sticker_type: String? = null,
needs_repainting: Boolean? = null,
) = telegramPost(
"$basePath/createNewStickerSet",
CreateNewStickerSetRequest(
user_id,
name,
title,
stickers,
sticker_type,
needs_repainting,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to add a new sticker to a set created by the bot. Emoji sticker sets can have up to 200 stickers. Other sticker sets can have up to 120 stickers. Returns True on success.
*
* @property user_id User identifier of sticker set owner
* @property name Sticker set name
* @property sticker A JSON-serialized object with information about the added sticker. If exactly the same sticker had already been added to the set, then the set isn't changed.
*
* @return [Boolean]
* */
suspend fun addStickerToSet(
user_id: UserId,
name: String,
sticker: InputSticker,
) = telegramPost(
"$basePath/addStickerToSet",
AddStickerToSetRequest(
user_id,
name,
sticker,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to move a sticker in a set created by the bot to a specific position. Returns True on success.
*
* @property sticker File identifier of the sticker
* @property position New sticker position in the set, zero-based
*
* @return [Boolean]
* */
suspend fun setStickerPositionInSet(
sticker: String,
position: Long,
) = telegramPost(
"$basePath/setStickerPositionInSet",
SetStickerPositionInSetRequest(
sticker,
position,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to delete a sticker from a set created by the bot. Returns True on success.
*
* @property sticker File identifier of the sticker
*
* @return [Boolean]
* */
suspend fun deleteStickerFromSet(
sticker: String,
) = telegramPost(
"$basePath/deleteStickerFromSet",
DeleteStickerFromSetRequest(
sticker,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to replace an existing sticker in a sticker set with a new one. The method is equivalent to calling deleteStickerFromSet, then addStickerToSet, then setStickerPositionInSet. Returns True on success.
*
* @property user_id User identifier of the sticker set owner
* @property name Sticker set name
* @property old_sticker File identifier of the replaced sticker
* @property sticker A JSON-serialized object with information about the added sticker. If exactly the same sticker had already been added to the set, then the set remains unchanged.
*
* @return [Boolean]
* */
suspend fun replaceStickerInSet(
user_id: UserId,
name: String,
old_sticker: String,
sticker: InputSticker,
) = telegramPost(
"$basePath/replaceStickerInSet",
ReplaceStickerInSetRequest(
user_id,
name,
old_sticker,
sticker,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to change the list of emoji assigned to a regular or custom emoji sticker. The sticker must belong to a sticker set created by the bot. Returns True on success.
*
* @property sticker File identifier of the sticker
* @property emoji_list A JSON-serialized list of 1-20 emoji associated with the sticker
*
* @return [Boolean]
* */
suspend fun setStickerEmojiList(
sticker: String,
emoji_list: List,
) = telegramPost(
"$basePath/setStickerEmojiList",
SetStickerEmojiListRequest(
sticker,
emoji_list,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to change search keywords assigned to a regular or custom emoji sticker. The sticker must belong to a sticker set created by the bot. Returns True on success.
*
* @property sticker File identifier of the sticker
* @property keywords A JSON-serialized list of 0-20 search keywords for the sticker with total length of up to 64 characters
*
* @return [Boolean]
* */
suspend fun setStickerKeywords(
sticker: String,
keywords: List? = null,
) = telegramPost(
"$basePath/setStickerKeywords",
SetStickerKeywordsRequest(
sticker,
keywords,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to change the mask position of a mask sticker. The sticker must belong to a sticker set that was created by the bot. Returns True on success.
*
* @property sticker File identifier of the sticker
* @property mask_position A JSON-serialized object with the position where the mask should be placed on faces. Omit the parameter to remove the mask position.
*
* @return [Boolean]
* */
suspend fun setStickerMaskPosition(
sticker: String,
mask_position: MaskPosition? = null,
) = telegramPost(
"$basePath/setStickerMaskPosition",
SetStickerMaskPositionRequest(
sticker,
mask_position,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to set the title of a created sticker set. Returns True on success.
*
* @property name Sticker set name
* @property title Sticker set title, 1-64 characters
*
* @return [Boolean]
* */
suspend fun setStickerSetTitle(
name: String,
title: String,
) = telegramPost(
"$basePath/setStickerSetTitle",
SetStickerSetTitleRequest(
name,
title,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to set the thumbnail of a regular or mask sticker set. The format of the thumbnail file must match the format of the stickers in the set. Returns True on success.
*
* @property name Sticker set name
* @property user_id User identifier of the sticker set owner
* @property format Format of the thumbnail, must be one of “static” for a .WEBP or .PNG image, “animated” for a .TGS animation, or “video” for a WEBM video
* @property thumbnail A .WEBP or .PNG image with the thumbnail, must be up to 128 kilobytes in size and have a width and height of exactly 100px, or a .TGS animation with a thumbnail up to 32 kilobytes in size (see https://core.telegram.org/stickers#animation-requirements for animated sticker technical requirements), or a WEBM video with the thumbnail up to 32 kilobytes in size; see https://core.telegram.org/stickers#video-requirements for video sticker technical requirements. Pass a file_id as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. More information on Sending Files ». Animated and video sticker set thumbnails can't be uploaded via HTTP URL. If omitted, then the thumbnail is dropped and the first sticker is used as the thumbnail.
*
* @return [Boolean]
* */
suspend fun setStickerSetThumbnail(
name: String,
user_id: UserId,
format: String,
thumbnail: String? = null,
) = telegramPost(
"$basePath/setStickerSetThumbnail",
SetStickerSetThumbnailRequest(
name,
user_id,
format,
thumbnail,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to set the thumbnail of a custom emoji sticker set. Returns True on success.
*
* @property name Sticker set name
* @property custom_emoji_id Custom emoji identifier of a sticker from the sticker set; pass an empty string to drop the thumbnail and use the first sticker as the thumbnail.
*
* @return [Boolean]
* */
suspend fun setCustomEmojiStickerSetThumbnail(
name: String,
custom_emoji_id: String? = null,
) = telegramPost(
"$basePath/setCustomEmojiStickerSetThumbnail",
SetCustomEmojiStickerSetThumbnailRequest(
name,
custom_emoji_id,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to delete a sticker set that was created by the bot. Returns True on success.
*
* @property name Sticker set name
*
* @return [Boolean]
* */
suspend fun deleteStickerSet(
name: String,
) = telegramPost(
"$basePath/deleteStickerSet",
DeleteStickerSetRequest(
name,
).toJsonForRequest(),
Boolean.serializer()
)
// Inline mode
/**
* Use this method to send answers to an inline query. On success, True is returned.
No more than 50 results per query are allowed.
*
* @property inline_query_id Unique identifier for the answered query
* @property results A JSON-serialized array of results for the inline query
* @property cache_time The maximum amount of time in seconds that the result of the inline query may be cached on the server. Defaults to 300.
* @property is_personal Pass True if results may be cached on the server side only for the user that sent the query. By default, results may be returned to any user who sends the same query.
* @property next_offset Pass the offset that a client should send in the next query with the same text to receive more results. Pass an empty string if there are no more results or if you don't support pagination. Offset length can't exceed 64 bytes.
* @property button A JSON-serialized object describing a button to be shown above inline query results
*
* @return [Boolean]
* */
suspend fun answerInlineQuery(
inline_query_id: String,
results: List,
cache_time: Long? = null,
is_personal: Boolean? = null,
next_offset: String? = null,
button: InlineQueryResultsButton? = null,
) = telegramPost(
"$basePath/answerInlineQuery",
AnswerInlineQueryRequest(
inline_query_id,
results,
cache_time,
is_personal,
next_offset,
button,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Use this method to set the result of an interaction with a Web App and send a corresponding message on behalf of the user to the chat from which the query originated. On success, a SentWebAppMessage object is returned.
*
* @property web_app_query_id Unique identifier for the query to be answered
* @property result A JSON-serialized object describing the message to be sent
*
* @return [SentWebAppMessage]
* */
suspend fun answerWebAppQuery(
web_app_query_id: String,
result: InlineQueryResult,
) = telegramPost(
"$basePath/answerWebAppQuery",
AnswerWebAppQueryRequest(
web_app_query_id,
result,
).toJsonForRequest(),
SentWebAppMessage.serializer()
)
// Payments
/**
* Use this method to send invoices. On success, the sent Message is returned.
*
* @property chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername
)
* @property title Product name, 1-32 characters
* @property description Product description, 1-255 characters
* @property payload Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes.
* @property currency Three-letter ISO 4217 currency code, see more on currencies. Pass “XTR” for payments in Telegram Stars.
* @property prices Price breakdown, a JSON-serialized list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.). Must contain exactly one item for payments in Telegram Stars.
* @property message_thread_id Unique identifier for the target message thread (topic) of the forum; for forum supergroups only
* @property provider_token Payment provider token, obtained via @BotFather. Pass an empty string for payments in Telegram Stars.
* @property max_tip_amount The maximum accepted amount for tips in the smallest units of the currency (integer, not float/double). For example, for a maximum tip of US$ 1.45
pass max_tip_amount = 145
. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). Defaults to 0. Not supported for payments in Telegram Stars.
* @property suggested_tip_amounts A JSON-serialized array of suggested amounts of tips in the smallest units of the currency (integer, not float/double). At most 4 suggested tip amounts can be specified. The suggested tip amounts must be positive, passed in a strictly increased order and must not exceed max_tip_amount.
* @property start_parameter Unique deep-linking parameter. If left empty, forwarded copies of the sent message will have a Pay button, allowing multiple users to pay directly from the forwarded message, using the same invoice. If non-empty, forwarded copies of the sent message will have a URL button with a deep link to the bot (instead of a Pay button), with the value used as the start parameter
* @property provider_data JSON-serialized data about the invoice, which will be shared with the payment provider. A detailed description of required fields should be provided by the payment provider.
* @property photo_url URL of the product photo for the invoice. Can be a photo of the goods or a marketing image for a service. People like it better when they see what they are paying for.
* @property photo_size Photo size in bytes
* @property photo_width Photo width
* @property photo_height Photo height
* @property need_name Pass True if you require the user's full name to complete the order. Ignored for payments in Telegram Stars.
* @property need_phone_number Pass True if you require the user's phone number to complete the order. Ignored for payments in Telegram Stars.
* @property need_email Pass True if you require the user's email address to complete the order. Ignored for payments in Telegram Stars.
* @property need_shipping_address Pass True if you require the user's shipping address to complete the order. Ignored for payments in Telegram Stars.
* @property send_phone_number_to_provider Pass True if the user's phone number should be sent to the provider. Ignored for payments in Telegram Stars.
* @property send_email_to_provider Pass True if the user's email address should be sent to the provider. Ignored for payments in Telegram Stars.
* @property is_flexible Pass True if the final price depends on the shipping method. Ignored for payments in Telegram Stars.
* @property disable_notification Sends the message silently. Users will receive a notification with no sound.
* @property protect_content Protects the contents of the sent message from forwarding and saving
* @property message_effect_id Unique identifier of the message effect to be added to the message; for private chats only
* @property reply_parameters Description of the message to reply to
* @property reply_markup A JSON-serialized object for an inline keyboard. If empty, one 'Pay total price
' button will be shown. If not empty, the first button must be a Pay button.
*
* @return [Message]
* */
suspend fun sendInvoice(
chat_id: ChatId,
title: String,
description: String,
payload: String,
currency: String,
prices: List,
message_thread_id: MessageThreadId? = null,
provider_token: String? = null,
max_tip_amount: Long? = null,
suggested_tip_amounts: List? = null,
start_parameter: String? = null,
provider_data: String? = null,
photo_url: String? = null,
photo_size: Long? = null,
photo_width: Long? = null,
photo_height: Long? = null,
need_name: Boolean? = null,
need_phone_number: Boolean? = null,
need_email: Boolean? = null,
need_shipping_address: Boolean? = null,
send_phone_number_to_provider: Boolean? = null,
send_email_to_provider: Boolean? = null,
is_flexible: Boolean? = null,
disable_notification: Boolean? = null,
protect_content: Boolean? = null,
message_effect_id: MessageEffectId? = null,
reply_parameters: ReplyParameters? = null,
reply_markup: InlineKeyboardMarkup? = null,
) = telegramPost(
"$basePath/sendInvoice",
SendInvoiceRequest(
chat_id,
title,
description,
payload,
currency,
prices,
message_thread_id,
provider_token,
max_tip_amount,
suggested_tip_amounts,
start_parameter,
provider_data,
photo_url,
photo_size,
photo_width,
photo_height,
need_name,
need_phone_number,
need_email,
need_shipping_address,
send_phone_number_to_provider,
send_email_to_provider,
is_flexible,
disable_notification,
protect_content,
message_effect_id,
reply_parameters,
reply_markup,
).toJsonForRequest(),
Message.serializer()
)
/**
* Use this method to create a link for an invoice. Returns the created invoice link as String on success.
*
* @property title Product name, 1-32 characters
* @property description Product description, 1-255 characters
* @property payload Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes.
* @property currency Three-letter ISO 4217 currency code, see more on currencies. Pass “XTR” for payments in Telegram Stars.
* @property prices Price breakdown, a JSON-serialized list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.). Must contain exactly one item for payments in Telegram Stars.
* @property provider_token Payment provider token, obtained via @BotFather. Pass an empty string for payments in Telegram Stars.
* @property max_tip_amount The maximum accepted amount for tips in the smallest units of the currency (integer, not float/double). For example, for a maximum tip of US$ 1.45
pass max_tip_amount = 145
. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). Defaults to 0. Not supported for payments in Telegram Stars.
* @property suggested_tip_amounts A JSON-serialized array of suggested amounts of tips in the smallest units of the currency (integer, not float/double). At most 4 suggested tip amounts can be specified. The suggested tip amounts must be positive, passed in a strictly increased order and must not exceed max_tip_amount.
* @property provider_data JSON-serialized data about the invoice, which will be shared with the payment provider. A detailed description of required fields should be provided by the payment provider.
* @property photo_url URL of the product photo for the invoice. Can be a photo of the goods or a marketing image for a service.
* @property photo_size Photo size in bytes
* @property photo_width Photo width
* @property photo_height Photo height
* @property need_name Pass True if you require the user's full name to complete the order. Ignored for payments in Telegram Stars.
* @property need_phone_number Pass True if you require the user's phone number to complete the order. Ignored for payments in Telegram Stars.
* @property need_email Pass True if you require the user's email address to complete the order. Ignored for payments in Telegram Stars.
* @property need_shipping_address Pass True if you require the user's shipping address to complete the order. Ignored for payments in Telegram Stars.
* @property send_phone_number_to_provider Pass True if the user's phone number should be sent to the provider. Ignored for payments in Telegram Stars.
* @property send_email_to_provider Pass True if the user's email address should be sent to the provider. Ignored for payments in Telegram Stars.
* @property is_flexible Pass True if the final price depends on the shipping method. Ignored for payments in Telegram Stars.
*
* @return [String]
* */
suspend fun createInvoiceLink(
title: String,
description: String,
payload: String,
currency: String,
prices: List,
provider_token: String? = null,
max_tip_amount: Long? = null,
suggested_tip_amounts: List? = null,
provider_data: String? = null,
photo_url: String? = null,
photo_size: Long? = null,
photo_width: Long? = null,
photo_height: Long? = null,
need_name: Boolean? = null,
need_phone_number: Boolean? = null,
need_email: Boolean? = null,
need_shipping_address: Boolean? = null,
send_phone_number_to_provider: Boolean? = null,
send_email_to_provider: Boolean? = null,
is_flexible: Boolean? = null,
) = telegramPost(
"$basePath/createInvoiceLink",
CreateInvoiceLinkRequest(
title,
description,
payload,
currency,
prices,
provider_token,
max_tip_amount,
suggested_tip_amounts,
provider_data,
photo_url,
photo_size,
photo_width,
photo_height,
need_name,
need_phone_number,
need_email,
need_shipping_address,
send_phone_number_to_provider,
send_email_to_provider,
is_flexible,
).toJsonForRequest(),
String.serializer()
)
/**
* If you sent an invoice requesting a shipping address and the parameter is_flexible was specified, the Bot API will send an Update with a shipping_query field to the bot. Use this method to reply to shipping queries. On success, True is returned.
*
* @property shipping_query_id Unique identifier for the query to be answered
* @property ok Pass True if delivery to the specified address is possible and False if there are any problems (for example, if delivery to the specified address is not possible)
* @property shipping_options Required if ok is True. A JSON-serialized array of available shipping options.
* @property error_message Required if ok is False. Error message in human readable form that explains why it is impossible to complete the order (e.g. "Sorry, delivery to your desired address is unavailable'). Telegram will display this message to the user.
*
* @return [Boolean]
* */
suspend fun answerShippingQuery(
shipping_query_id: String,
ok: Boolean,
shipping_options: List? = null,
error_message: String? = null,
) = telegramPost(
"$basePath/answerShippingQuery",
AnswerShippingQueryRequest(
shipping_query_id,
ok,
shipping_options,
error_message,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Once the user has confirmed their payment and shipping details, the Bot API sends the final confirmation in the form of an Update with the field pre_checkout_query. Use this method to respond to such pre-checkout queries. On success, True is returned. Note: The Bot API must receive an answer within 10 seconds after the pre-checkout query was sent.
*
* @property pre_checkout_query_id Unique identifier for the query to be answered
* @property ok Specify True if everything is alright (goods are available, etc.) and the bot is ready to proceed with the order. Use False if there are any problems.
* @property error_message Required if ok is False. Error message in human readable form that explains the reason for failure to proceed with the checkout (e.g. "Sorry, somebody just bought the last of our amazing black T-shirts while you were busy filling out your payment details. Please choose a different color or garment!"). Telegram will display this message to the user.
*
* @return [Boolean]
* */
suspend fun answerPreCheckoutQuery(
pre_checkout_query_id: String,
ok: Boolean,
error_message: String? = null,
) = telegramPost(
"$basePath/answerPreCheckoutQuery",
AnswerPreCheckoutQueryRequest(
pre_checkout_query_id,
ok,
error_message,
).toJsonForRequest(),
Boolean.serializer()
)
/**
* Returns the bot's Telegram Star transactions in chronological order. On success, returns a StarTransactions object.
*
* @property offset Number of transactions to skip in the response
* @property limit The maximum number of transactions to be retrieved. Values between 1-100 are accepted. Defaults to 100.
*
* @return [StarTransactions]
* */
suspend fun getStarTransactions(
offset: Long? = null,
limit: Long? = null,
) = telegramPost(
"$basePath/getStarTransactions",
GetStarTransactionsRequest(
offset,
limit,
).toJsonForRequest(),
StarTransactions.serializer()
)
/**
* Refunds a successful payment in Telegram Stars. Returns True on success.
*
* @property user_id Identifier of the user whose payment will be refunded
* @property telegram_payment_charge_id Telegram payment identifier
*
* @return [Boolean]
* */
suspend fun refundStarPayment(
user_id: UserId,
telegram_payment_charge_id: String,
) = telegramPost(
"$basePath/refundStarPayment",
RefundStarPaymentRequest(
user_id,
telegram_payment_charge_id,
).toJsonForRequest(),
Boolean.serializer()
)
// Telegram Passport
/**
* Informs a user that some of the Telegram Passport elements they provided contains errors. The user will not be able to re-submit their Passport to you until the errors are fixed (the contents of the field for which you returned the error must change). Returns True on success.
Use this if the data submitted by the user doesn't satisfy the standards your service requires for any reason. For example, if a birthday date seems invalid, a submitted document is blurry, a scan shows evidence of tampering, etc. Supply some details in the error message to make sure the user knows how to correct the issues.
*
* @property user_id User identifier
* @property errors A JSON-serialized array describing the errors
*
* @return [Boolean]
* */
suspend fun setPassportDataErrors(
user_id: UserId,
errors: List,
) = telegramPost(
"$basePath/setPassportDataErrors",
SetPassportDataErrorsRequest(
user_id,
errors,
).toJsonForRequest(),
Boolean.serializer()
)
// Games
/**
* Use this method to send a game. On success, the sent Message is returned.
*
* @property chat_id Unique identifier for the target chat
* @property game_short_name Short name of the game, serves as the unique identifier for the game. Set up your games via @BotFather.
* @property business_connection_id Unique identifier of the business connection on behalf of which the message will be sent
* @property message_thread_id Unique identifier for the target message thread (topic) of the forum; for forum supergroups only
* @property disable_notification Sends the message silently. Users will receive a notification with no sound.
* @property protect_content Protects the contents of the sent message from forwarding and saving
* @property message_effect_id Unique identifier of the message effect to be added to the message; for private chats only
* @property reply_parameters Description of the message to reply to
* @property reply_markup A JSON-serialized object for an inline keyboard. If empty, one 'Play game_title' button will be shown. If not empty, the first button must launch the game.
*
* @return [Message]
* */
suspend fun sendGame(
chat_id: ChatId,
game_short_name: String,
business_connection_id: BusinessConnectionId? = null,
message_thread_id: MessageThreadId? = null,
disable_notification: Boolean? = null,
protect_content: Boolean? = null,
message_effect_id: MessageEffectId? = null,
reply_parameters: ReplyParameters? = null,
reply_markup: InlineKeyboardMarkup? = null,
) = telegramPost(
"$basePath/sendGame",
SendGameRequest(
chat_id,
game_short_name,
business_connection_id,
message_thread_id,
disable_notification,
protect_content,
message_effect_id,
reply_parameters,
reply_markup,
).toJsonForRequest(),
Message.serializer()
)
/**
* Use this method to set the score of the specified user in a game message. On success, if the message is not an inline message, the Message is returned, otherwise True is returned. Returns an error, if the new score is not greater than the user's current score in the chat and force is False.
*
* @property user_id User identifier
* @property score New score, must be non-negative
* @property force Pass True if the high score is allowed to decrease. This can be useful when fixing mistakes or banning cheaters
* @property disable_edit_message Pass True if the game message should not be automatically edited to include the current scoreboard
* @property chat_id Required if inline_message_id is not specified. Unique identifier for the target chat
* @property message_id Required if inline_message_id is not specified. Identifier of the sent message
* @property inline_message_id Required if chat_id and message_id are not specified. Identifier of the inline message
*
* @return [Message]
* */
suspend fun setGameScore(
user_id: UserId,
score: Long,
force: Boolean? = null,
disable_edit_message: Boolean? = null,
chat_id: ChatId? = null,
message_id: MessageId? = null,
inline_message_id: String? = null,
) = telegramPost(
"$basePath/setGameScore",
SetGameScoreRequest(
user_id,
score,
force,
disable_edit_message,
chat_id,
message_id,
inline_message_id,
).toJsonForRequest(),
Message.serializer()
)
/**
* Use this method to get data for high score tables. Will return the score of the specified user and several of their neighbors in a game. Returns an Array of GameHighScore objects.
* This method will currently return scores for the target user, plus two of their closest neighbors on each side. Will also return the top three users if the user and their neighbors are not among them. Please note that this behavior is subject to change.
*
*
* @property user_id Target user id
* @property chat_id Required if inline_message_id is not specified. Unique identifier for the target chat
* @property message_id Required if inline_message_id is not specified. Identifier of the sent message
* @property inline_message_id Required if chat_id and message_id are not specified. Identifier of the inline message
*
* @return [List]
* */
suspend fun getGameHighScores(
user_id: UserId,
chat_id: ChatId? = null,
message_id: MessageId? = null,
inline_message_id: String? = null,
) = telegramPost(
"$basePath/getGameHighScores",
GetGameHighScoresRequest(
user_id,
chat_id,
message_id,
inline_message_id,
).toJsonForRequest(),
ListSerializer(GameHighScore.serializer())
)
}