Bot

A Telegram Bot.

Process Event

Instead of using subscribe directly, you can also register event handlers using a convenient extension function.

Bot.subscribe

bot.process<Message> { event: Event, content: Message ->
// ...
}

See Bot.subscribe for more information.

Bot.onXxx

For example: Bot.onEditedMessage

bot.onEditedMessage { event, editedMessage ->
// ...
}

See Bot.onEditedMessage (Or other similar functions, which are automatically generated) for more information.

Author

ForteScarlet

Types

Link copied to clipboard
data class Ticket(val token: String)

Bot ticket.

Properties

Link copied to clipboard
abstract val apiClient: HttpClient

HttpClient used by the Bot to make API requests internally.

Link copied to clipboard
abstract override val coroutineContext: CoroutineContext
Link copied to clipboard
abstract val isActive: Boolean

Similar to Job.isActive

Link copied to clipboard
abstract val isCancelled: Boolean

Similar to Job.isCancelled

Link copied to clipboard
abstract val isCompleted: Boolean

Similar to Job.isCompleted

Link copied to clipboard
abstract val isStarted: Boolean

Whether the launch start was successfully executed once.

Link copied to clipboard
abstract var longPolling: LongPolling?

Gets or modifies long polling config.

Link copied to clipboard
abstract val server: Url

The server address used by the Bot. If BotConfiguration.server is null, Telegram.BaseServerUrl is returned.

Link copied to clipboard
abstract val ticket: Bot.Ticket

Ticket.

Functions

Link copied to clipboard
open fun cancel()
abstract fun cancel(cause: Throwable?)

Close the Bot. A closed Bot cannot be started again, nor can it push or process events.

Link copied to clipboard
abstract suspend fun join()

Suspend until bot is canceled

Link copied to clipboard
abstract suspend fun pushUpdate(update: Update, raw: String? = null)

Proactively pushes an Update and triggers internal event handling.

Link copied to clipboard
abstract suspend fun start()

Start this bot.

Link copied to clipboard
open fun subscribe(processor: EventProcessor)

Register a processor with the SubscribeSequence.NORMAL sequence level for subscribing to events.

abstract fun subscribe(sequence: SubscribeSequence, processor: EventProcessor)

Register a processor with the specified sequence level for subscribing to events.

Inherited functions

Link copied to clipboard
inline fun Bot.onCallbackQuery(sequence: SubscribeSequence = NORMAL, crossinline processor: suspend (Event, callbackQuery: CallbackQuery) -> Unit)

Register processor for CallbackQuery named CALLBACK_QUERY_NAME

Link copied to clipboard
inline fun Bot.onChannelPost(sequence: SubscribeSequence = NORMAL, crossinline processor: suspend (Event, channelPost: Message) -> Unit)

Register processor for Message named CHANNEL_POST_NAME

Link copied to clipboard
inline fun Bot.onChatBoost(sequence: SubscribeSequence = NORMAL, crossinline processor: suspend (Event, chatBoost: ChatBoostUpdated) -> Unit)

Register processor for ChatBoostUpdated named CHAT_BOOST_NAME

Link copied to clipboard
inline fun Bot.onChatJoinRequest(sequence: SubscribeSequence = NORMAL, crossinline processor: suspend (Event, chatJoinRequest: ChatJoinRequest) -> Unit)

Register processor for ChatJoinRequest named CHAT_JOIN_REQUEST_NAME

Link copied to clipboard
inline fun Bot.onChatMember(sequence: SubscribeSequence = NORMAL, crossinline processor: suspend (Event, chatMember: ChatMemberUpdated) -> Unit)

Register processor for ChatMemberUpdated named CHAT_MEMBER_NAME

Link copied to clipboard
inline fun Bot.onChosenInlineResult(sequence: SubscribeSequence = NORMAL, crossinline processor: suspend (Event, chosenInlineResult: ChosenInlineResult) -> Unit)

Register processor for ChosenInlineResult named CHOSEN_INLINE_RESULT_NAME

Link copied to clipboard
inline fun Bot.onEditedChannelPost(sequence: SubscribeSequence = NORMAL, crossinline processor: suspend (Event, editedChannelPost: Message) -> Unit)

Register processor for Message named EDITED_CHANNEL_POST_NAME

Link copied to clipboard
inline fun Bot.onEditedMessage(sequence: SubscribeSequence = NORMAL, crossinline processor: suspend (Event, editedMessage: Message) -> Unit)

Register processor for Message named EDITED_MESSAGE_NAME

Link copied to clipboard
inline fun Bot.onInlineQuery(sequence: SubscribeSequence = NORMAL, crossinline processor: suspend (Event, inlineQuery: InlineQuery) -> Unit)

Register processor for InlineQuery named INLINE_QUERY_NAME

Link copied to clipboard
inline fun Bot.onMessage(sequence: SubscribeSequence = NORMAL, crossinline processor: suspend (Event, message: Message) -> Unit)

Register processor for Message named MESSAGE_NAME

Link copied to clipboard
inline fun Bot.onMessageReaction(sequence: SubscribeSequence = NORMAL, crossinline processor: suspend (Event, messageReaction: MessageReactionUpdated) -> Unit)

Register processor for MessageReactionUpdated named MESSAGE_REACTION_NAME

Link copied to clipboard
inline fun Bot.onMessageReactionCount(sequence: SubscribeSequence = NORMAL, crossinline processor: suspend (Event, messageReactionCount: MessageReactionCountUpdated) -> Unit)
Link copied to clipboard
inline fun Bot.onMyChatMember(sequence: SubscribeSequence = NORMAL, crossinline processor: suspend (Event, myChatMember: ChatMemberUpdated) -> Unit)

Register processor for ChatMemberUpdated named MY_CHAT_MEMBER_NAME

Link copied to clipboard
inline fun Bot.onPoll(sequence: SubscribeSequence = NORMAL, crossinline processor: suspend (Event, poll: Poll) -> Unit)

Register processor for Poll named POLL_NAME

Link copied to clipboard
inline fun Bot.onPollAnswer(sequence: SubscribeSequence = NORMAL, crossinline processor: suspend (Event, pollAnswer: PollAnswer) -> Unit)

Register processor for PollAnswer named POLL_ANSWER_NAME

Link copied to clipboard
inline fun Bot.onPreCheckoutQuery(sequence: SubscribeSequence = NORMAL, crossinline processor: suspend (Event, preCheckoutQuery: PreCheckoutQuery) -> Unit)

Register processor for PreCheckoutQuery named PRE_CHECKOUT_QUERY_NAME

Link copied to clipboard
inline fun Bot.onRemovedChatBoost(sequence: SubscribeSequence = NORMAL, crossinline processor: suspend (Event, removedChatBoost: ChatBoostRemoved) -> Unit)

Register processor for ChatBoostRemoved named REMOVED_CHAT_BOOST_NAME

Link copied to clipboard
inline fun Bot.onShippingQuery(sequence: SubscribeSequence = NORMAL, crossinline processor: suspend (Event, shippingQuery: ShippingQuery) -> Unit)

Register processor for ShippingQuery named SHIPPING_QUERY_NAME

Link copied to clipboard
suspend fun Bot.pushRawUpdate(raw: String)

Push a Update raw JSON string.

Link copied to clipboard
inline fun <T> Bot.subscribe(name: String? = null, sequence: SubscribeSequence = SubscribeSequence.NORMAL, crossinline processor: suspend (Event, T) -> Unit)

Bot.subscribe simplified extension. Matches events based on type T (and optional name).