telegram icon indicating copy to clipboard operation
telegram copied to clipboard

[examples] Add ZIO example

Open ex0ns opened this issue 2 years ago • 4 comments

ex0ns avatar Jul 26 '22 06:07 ex0ns

Is function .startPolling() in file Launcher.scala run Long Pooling bot mode?

If Yes, could you please provide example with weebhook (special with setting https context, maybe with override def certificate override val httpsContext )

I ask this question because in example: new CommandsBot(token).startPolling() return Task[Unit]

If I remove "with Polling[Task]" and add "with Webhook" I don't know how get ZIO type.

AlexGruPerm avatar Jul 26 '22 21:07 AlexGruPerm

Unfortunately the webhook part (available inside the akka version of this library) is only compatible with Future (and not directly with Cats/ZIO unless you convert your IO/Task into a future first.

It might be possible to make this part tagless final as well and have another runtime next to the Akka one, but I never tried that and I will not have the time to investigate this very soon.

If you wanted to try, I would start with the Webhook class that currently forces a BotBase[Future] and make it a

trait Webhook[F[_]] extends WebRoutes with StrictLogging {
  this: BotBase[F] with BotExecutionContext with AkkaImplicits =>

But I don't know if this could work or not yet

Another idea I have would be to totally remove the hard dependency on akka for the webhook part of this project and setup a more generic webserver approach (using Tapir for instance), where it could then be possible to provide a custom backend to deal with webhook, I think that could work and could be nice but this would require quite a lot of change for this package (breaking changes).

Another idea I have is to re-implement the webhook handling for your specific use-case. By using the request(SetWebhook(...)) call from BotBase[Task] and then spinning a webserver with the correct path that would decode the query into an Update and call receiveUpdate from BotBase it should work, in order for that you would not need the akka package and could do whatever you want it the webserver that you are starting.

Please let me know if this makes sense @AlexGruPerm

ex0ns avatar Jul 27 '22 08:07 ex0ns

Check the latest commit https://github.com/bot4s/telegram/pull/239/commits/ee12798dfe5520ae11e61c28b96ae2148b0cb952 to see an example of a webhook bot running on zio-http

ex0ns avatar Jul 27 '22 11:07 ex0ns

"Another idea I have is to re-implement the webhook handling for your specific use-case." - it's little bit difficult for me to understand. My level in TP is small.

But this is a good news - "to see an example of a webhook bot running on zio-http" thanks a lot, I will investigate it in the coming days. Will return with feedback.

AlexGruPerm avatar Jul 27 '22 11:07 AlexGruPerm