Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to deserialize an Update in a web server request handler? #87

Closed
madhead opened this issue May 13, 2020 · 4 comments · Fixed by #88
Closed

How to deserialize an Update in a web server request handler? #87

madhead opened this issue May 13, 2020 · 4 comments · Fixed by #88
Labels
enhancement New feature or request good first issue Good for newcomers question Further information is requested

Comments

@madhead
Copy link
Contributor

madhead commented May 13, 2020

I'm writing a TG webhook handler in Ktor. I guess, that in order to deserialize an Update, I need to use UpdateSerializerWithoutSerialization / UpdateDeserializationStrategy or have direct access to RawUpdate (which is serializable).

But all those classes are internal and cannot be used in user code. So, how do we deserialize incoming updates?

@InsanusMokrassar
Copy link
Owner

InsanusMokrassar commented May 13, 2020

Hello! Here I pasted a minimal workaround for using of webhooks:

val bot = telegramBot("BOT TOKEN")
val flowUpdates = FlowsUpdatesFilter(64)
runBlocking {
    bot.setWebhook(
        "https://your.domain/some_secret",
        8081,
        flowUpdates,
        Netty
    )
}

Unfortunately, currently it is impossible to work with updates directly "by hands" and it is supposed that you will use long polling (via startGettingOfUpdates/startGettingFlowsUpdates) or webhooks (as it was mentioned in the example above, setWebhook). But I think, that it is possible to make Update serializable via setting up internal serializer. The problem here is that currently it does not support serialization. The other option is to make UpdateDeserializationStrategy public, but in this case I afraid that it could be a little bit sensitive to updates in other parts of library.

@madhead
Copy link
Contributor Author

madhead commented May 13, 2020

I think it's not a rare case when bot developers will use BotFather to set up webhooks for their own web servers written on Ktor or Spring Boot. Even more, some bots may use Heroku or AWS Lambda (serverless) deployments, where it's impossible to have a long-running process listening for updates, and where every update triggers (wakes up) some computation. It's crucial to have an ability to deserialize payloads directly to Update in such scenarios. Could you please consider making it possible?

@InsanusMokrassar
Copy link
Owner

InsanusMokrassar commented May 13, 2020

Here setWebhook will start ktor server for updates retrieving. But I think that in the next release it will be allowed to deserialize updates outside of library.

@InsanusMokrassar
Copy link
Owner

Fixed in #88

@InsanusMokrassar InsanusMokrassar added good first issue Good for newcomers question Further information is requested enhancement New feature or request labels May 15, 2020
@InsanusMokrassar InsanusMokrassar linked a pull request May 16, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants