rapierorg / telegram-bot-swift

Telegram Bot SDK for Swift (unofficial)
https://github.com/rapierorg/telegram-bot-swift/wiki
Apache License 2.0
375 stars 63 forks source link

Callback doesn't work because can't read data #33

Closed savelii closed 7 years ago

savelii commented 7 years ago

Hey, what the idea behind this pull request? https://github.com/zmeyc/telegram-bot-swift/pull/30/commits/b442d6763b437ee9a825425aaebcc494233c0bd0

Because of it example stop working https://github.com/zmeyc/telegram-bot-swift/blob/master/Examples/shopster-bot/Sources/shopster-bot/Controllers/MainController.swift

  // "toggle 1234567"
        guard context.args.scanWord() == "toggle" else { return false }
        guard let itemId = context.args.scanInt64() else { return false }

args is empty and always no reaction on inline keyboard press

zmeyc commented 7 years ago

Hi! Initially, if text was missing args were initialized with callback_query.data as a fallback. This allowed to use router for callback_data:

router["someCallbackData"] = { }

But this approach had two problems:

So, we removed the fallback. Now this form should be used instead:

router[.callback_query(data: "someCallbackData")] = { }

args should be replaced with context.update.callback_query?.data

I forgot to fix the example, thanks!

zmeyc commented 7 years ago

Fixed in dev branch: https://github.com/zmeyc/telegram-bot-swift/commit/8295ef42eabe50c13aec6f734f4efe69b809fc98