vendelieu / telegram-bot

Telegram Bot API wrapper with handy Kotlin DSL.
https://vendelieu.github.io/telegram-bot/
Apache License 2.0
197 stars 15 forks source link

Handling WebAppData #175

Closed spaiman closed 5 months ago

spaiman commented 5 months ago

Hi, it's me again. I was creating a Telegram Mini Apps triggered via reply keyboard markup. Upon sending the data to the backend, I also call Telegram.WebApp.sendData. I can see that my bot receives the data:

webAppData=WebAppData(data=<data>, buttonText=<button text>)

But, I don't know how can I receive and process the data from my bot. Tried with @CommandHandler and @InputHandler to match the data that was sent, but no dice. What's the best way to handle and process the WebAppData?

spaiman commented 5 months ago

I was able to get it working:

@UpdateHandler([UpdateType.MESSAGE])
suspend fun commandUpdateMessage(update: ProcessedUpdate, user: User, bot: TelegramBot) {
    val webAppData = update.update.message?.webAppData?.data
    // process webAppData
}

Just a suggestion: would probably beneficial to add these things to the doc.

All good then!