klappvisor / haskell-telegram-api

Telegram Bot API for Haskell
BSD 3-Clause "New" or "Revised" License
202 stars 67 forks source link

Automatically add "bot"-prefix to tokens in URLs #116

Open Philonous opened 6 years ago

Philonous commented 6 years ago

The telegram bot API requires URLs to be of the form https://api.telegram.org/bot<token>/... but this library constructs them as https://api.telegram.org/<token>/... , so users have to add the "bot" manually to the token. This is surprising as the "bot" prefix isn't part of the token given by telegram.

Philonous commented 6 years ago

I'd be willing to work on this if there's a chance that it would be merged. I believe just adding the "bot" prefix as a breaking change and bumping the major version is the cleanest solution. But if backwards-compatibility absolutely has to be maintained, something like

addBotPrefix (Token tok) = 
  Token (if "bot" `Text.isPrefixOf` tok then tok else "bot" <> tok)

would work because the token apparently always start with digits, so the strings should be prefix-free.