vendelieu/telegram-bot

Wiki error

Closed this issue · 4 comments

d-w-x commented

link: https://github.com/vendelieu/telegram-bot/wiki/Updates-handling#handling-updates-by-its-type
Bug: ProcessedUpdate don't have User, so

@UpdateHandler([UpdateType.MESSAGE])
suspend fun handleAllMessages(update: ProcessedUpdate, bot: TelegramBot) {
    message { "Hello" }.send(update.user, bot)
}

can't compile.

Thanks for noticing!

Now you can use MessageUpdate right away instead ProcessedUpdate (if you need)!
Also, if you want to use the user in your requests, you can simply declare User in the function and if it is present, it will be passed.

@UpdateHandler([UpdateType.MESSAGE])
suspend fun handleAllMessages(user: User, update: MessageUpdate, bot: TelegramBot) {
    message { "Hello" }.send(user, bot)
}

Also, if the parameters are not needed, it is not necessary to specify them, this will not cause any problems.
They are only passed if declared.

But anyway if you want to have more specific logic with options to handle different types of update, as example if you're using UnprocessedHandler you can use smartcasts, there's example.

d-w-x commented

Thanks for your kindly reply.

Maybe we should correct the wiki to make things more clearly?

Sure, updated the wiki to a more up to date version.