haskell-telegram-api icon indicating copy to clipboard operation
haskell-telegram-api copied to clipboard

Automatically add "bot"-prefix to tokens in URLs

Open Philonous opened this issue 7 years ago • 1 comments

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 avatar Mar 26 '18 08:03 Philonous

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.

Philonous avatar Mar 26 '18 08:03 Philonous