Hi @augustjune and thanks for the library :)
a quick question: i'm developing a bot with different scenarios and callbacks and was wondering if there are any way to have a "global exception handler" instead of use .attempt
or .handleErrorWith
for each of the scenarios.
i was expecting the app not to crash if something fails during the evaluation of one of the scenarios (because of a bad input, some unhandled edge case, temporary connection error with external sources, telegram server not responding ..).
i'have tried to use the handleErrorWith/attempt in the main stream:
telegramClient
.flatMap(implicit client =>
Bot
.polling[IO]
.follow(scen1,scen2,scen3)
.through(callback1)
//tried here
)
//tried here
.compile
.drain
.as(ExitCode.Success)
but the underlying stream seems to explode:
[ioapp-compute-3] INFO o.h.c.PoolManager - Shutting down connection pool: curAllocated=1 idleQueues.size=1 waitQueue.size=0 maxWaitQueueLimit=256 closed=false
Non-daemon threads currently preventing JVM termination: - 29: Thread[pool-1-thread-1,5,main]
- - 44: Thread[DestroyJavaVM,5,main]
Am i missing something?
.tolerate
and .cancel
methods that you can use to steer the flow
.attempt
and .handleErrorWith
Hi. I'm trying to handle inline queries with code from the NoScenario example, and it doesn't work. I see an error "unexpected HTTP status: 400 Bad Request". It's working fine when I return empty List() but fails with InlineQueryResultArticle content. Probably somebody has any ideas what could go wrong?
A simple "echo" bot is working fine as well. The only issue is inline queries
/start
again. I know that I can save chat identifier, create ChatApi using id and send the message. But I do not understand how to write "main" (def run(args: List[String]): IO[ExitCode] = ???
) function(( In the examples, there are only starting one Stream with polling, but it is not my case. Can someone help me pls
Stream
.resource(TelegramClient.global[IO](token))
.flatMap { implicit client =>
Bot.polling[IO]
.follow(payment)
.through(answerCallbacks)
}
.compile
.drain
.as(ExitCode.Success)
def payment[F[_] : TelegramClient]: Scenario[F, Unit] = {
for {
driveInvoice = InvoiceContent(
title = "Title",
description = "Description",
payload = "Test",
providerToken = acquiringToken,
startParameter = "Test",
currency = Currency.RUB,
prices = Seq(LabeledPrice(label = "Test", amount = 10000))
)
_ <- Scenario.eval(chat.send(driveInvoice))
_ <- Scenario.eval(chat.send("Hello"))
} yield ()
}
def answerCallbacks[F[_] : Monad : TelegramClient]: Pipe[F, Update, Update] =
_.evalTap {
case PreCheckoutQueryReceived(_, preCheckoutQuery) => for {
_ <- preCheckoutQuery.confirm
} yield ()
case _ => Applicative[F].unit
}