TelegramBotMiddleware

class TelegramBotMiddleware(onRequestException: suspend (request: Request<*>, t: Throwable?) -> Any?? = null, onBeforeSearchCallFactory: suspend (request: Request<*>, callsFactories: List<KtorCallFactory>) -> Unit? = null, onBeforeCallFactoryMakeCall: suspend (request: Request<*>, potentialFactory: KtorCallFactory) -> Unit? = null, onAfterCallFactoryMakeCall: suspend (result: Any?, request: Request<*>, potentialFactory: KtorCallFactory) -> Any?? = null, onRequestResultPresented: suspend (result: Any?, request: Request<*>, resultCallFactory: KtorCallFactory, callsFactories: List<KtorCallFactory>) -> Any?? = null, onRequestResultAbsent: suspend (request: Request<*>, callsFactories: List<KtorCallFactory>) -> Any?? = null, onRequestReturnResult: suspend (result: Result<*>, request: Request<*>, callsFactories: List<KtorCallFactory>) -> Result<Any?>?? = null) : TelegramBotPipelinesHandler

Parameters

onRequestException

Will be called when some exception happen during Request handling. Non-null result of lambda will be used as the result of request handling

onBeforeSearchCallFactory

Will be called when telegram bot starts to choose which KtorCallFactory will handle Request

onBeforeCallFactoryMakeCall

Will be called when telegram bot trying to use KtorCallFactory as potential handler for Request

onAfterCallFactoryMakeCall

Will be called when KtorCallFactory made call. Non-null result of lambda will be used as the result of request handling

onRequestResultPresented

Will be called when KtorCallFactory or TelegramBotPipelinesHandler/TelegramBotMiddleware returned non-null result. Non-null result of lambda will be used as the result of request handling

onRequestResultAbsent

Will be called when some there is no any result of Request handling. Non-null result of lambda will be used as the result of request handling

onRequestReturnResult

Latest lambda before result returning. Will be called after all previous stages. Non-null result of lambda will be used as the result of request handling

Constructors

Link copied to clipboard
constructor(onRequestException: suspend (request: Request<*>, t: Throwable?) -> Any?? = null, onBeforeSearchCallFactory: suspend (request: Request<*>, callsFactories: List<KtorCallFactory>) -> Unit? = null, onBeforeCallFactoryMakeCall: suspend (request: Request<*>, potentialFactory: KtorCallFactory) -> Unit? = null, onAfterCallFactoryMakeCall: suspend (result: Any?, request: Request<*>, potentialFactory: KtorCallFactory) -> Any?? = null, onRequestResultPresented: suspend (result: Any?, request: Request<*>, resultCallFactory: KtorCallFactory, callsFactories: List<KtorCallFactory>) -> Any?? = null, onRequestResultAbsent: suspend (request: Request<*>, callsFactories: List<KtorCallFactory>) -> Any?? = null, onRequestReturnResult: suspend (result: Result<*>, request: Request<*>, callsFactories: List<KtorCallFactory>) -> Result<Any?>?? = null)

Types

Link copied to clipboard
object Companion
Link copied to clipboard

Functions

Link copied to clipboard
open suspend override fun <T : Any> onAfterCallFactoryMakeCall(result: T?, request: Request<T>, potentialFactory: KtorCallFactory): T?

Will always be called after potentialFactory has tried to make request and got some result. If returns value - that value will be returned from dev.inmo.tgbotapi.bot.RequestsExecutor.execute instead

Link copied to clipboard
open suspend override fun onBeforeCallFactoryMakeCall(request: Request<*>, potentialFactory: KtorCallFactory)

Will always be called before potentialFactory will try to make request

Link copied to clipboard
open suspend override fun onBeforeSearchCallFactory(request: Request<*>, callsFactories: List<KtorCallFactory>)

Will always be called before requests executor will check all callsFactories for an opportunity to make call of request

Link copied to clipboard
open suspend override fun <T : Any> onRequestException(request: Request<T>, t: Throwable): T?

Will be called when any exception will happen due to the request handling. If returns value - that value will be returned from dev.inmo.tgbotapi.bot.RequestsExecutor.execute instead

Link copied to clipboard
open suspend override fun <T : Any> onRequestResultAbsent(request: Request<T>, callsFactories: List<KtorCallFactory>): T?

Will be called when there is no KtorCallFactory from callsFactories which may handle request. If returns value - that value will be returned from dev.inmo.tgbotapi.bot.RequestsExecutor.execute instead

Link copied to clipboard
open suspend override fun <T : Any> onRequestResultPresented(result: T, request: Request<T>, resultCallFactory: KtorCallFactory, callsFactories: List<KtorCallFactory>): T?

Will be called when resultCallFactory is the KtorCallFactory from callsFactories which has successfully handled request and returned result. If returns value - that value will be returned from dev.inmo.tgbotapi.bot.RequestsExecutor.execute instead

Link copied to clipboard
open suspend override fun <T : Any> onRequestReturnResult(result: Result<T>, request: Request<T>, callsFactories: List<KtorCallFactory>): Result<T>

This step will be called when the result has been retrieved (or exception has happened). If returns value - that value will be returned from dev.inmo.tgbotapi.bot.RequestsExecutor.execute instead