{"id":13461884,"url":"https://github.com/klappvisor/haskell-telegram-api","last_synced_at":"2025-04-04T08:09:54.104Z","repository":{"id":3368356,"uuid":"48983684","full_name":"klappvisor/haskell-telegram-api","owner":"klappvisor","description":"Telegram Bot API for Haskell","archived":false,"fork":false,"pushed_at":"2023-03-07T14:13:05.000Z","size":1720,"stargazers_count":202,"open_issues_count":20,"forks_count":67,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-10-30T05:57:16.260Z","etag":null,"topics":["bot","haskell","servant","telegram-bot","telegram-bot-api"],"latest_commit_sha":null,"homepage":"","language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/klappvisor.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2016-01-04T08:19:58.000Z","updated_at":"2024-10-08T00:08:14.000Z","dependencies_parsed_at":"2023-01-13T12:27:56.727Z","dependency_job_id":null,"html_url":"https://github.com/klappvisor/haskell-telegram-api","commit_stats":{"total_commits":237,"total_committers":21,"mean_commits":"11.285714285714286","dds":0.4978902953586498,"last_synced_commit":"abbfd76c40f2783c113b660184a03cc94d58e751"},"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klappvisor%2Fhaskell-telegram-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klappvisor%2Fhaskell-telegram-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klappvisor%2Fhaskell-telegram-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klappvisor%2Fhaskell-telegram-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/klappvisor","download_url":"https://codeload.github.com/klappvisor/haskell-telegram-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247142074,"owners_count":20890653,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bot","haskell","servant","telegram-bot","telegram-bot-api"],"created_at":"2024-07-31T12:00:26.358Z","updated_at":"2025-04-04T08:09:54.080Z","avatar_url":"https://github.com/klappvisor.png","language":"Haskell","funding_links":[],"categories":["Telegram Libraries","Libraries"],"sub_categories":["Other Languages","Haskell"],"readme":"# telegram-api\n\n[![Join the chat at https://gitter.im/klappvisor/haskell-telegram-api](https://badges.gitter.im/klappvisor/haskell-telegram-api.svg)](https://gitter.im/klappvisor/haskell-telegram-api?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\n![Build Status](https://img.shields.io/circleci/project/klappvisor/haskell-telegram-api.svg)\n![Hackage](https://img.shields.io/hackage/v/telegram-api.svg)\n![Hackage Dependencies](https://img.shields.io/hackage-deps/v/telegram-api.svg)\n![Haskell Programming Language](https://img.shields.io/badge/language-Haskell-blue.svg)\n![BSD3 License](http://img.shields.io/badge/license-BSD3-brightgreen.svg)\n\nHigh-level bindings to the [Telegram Bot API][telegram-bot-api] based on [servant][servant] library.\nBoth `getUpdates` request or webhook can be used to receive updates for your bot.\nInline mode is supported.\nUploading stickers, documents, video, etc is not supported yet, but you can send items which are already uploaded on the Telegram servers.\n\n**Support of [Bot-3.5 API][bot-api]**\n\n## Usage\n\nThere are two ways of using Telegram Bot API. First and original way is to run IO directly for every Telegram servers request, another one is based on `TelegramClient` which is just `ReaderT`.\n\n### Use `TelegramClient`\n\n```haskell\n{-# LANGUAGE OverloadedStrings #-}\n\nimport           Network.HTTP.Client      (newManager)\nimport           Network.HTTP.Client.TLS  (tlsManagerSettings)\nimport           Web.Telegram.API.Bot\n\nmain :: IO ()\nmain = do\n  let token = Token \"bot\u003ctoken\u003e\" -- entire Token should be bot123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11\n  manager \u003c- newManager tlsManagerSettings\n  result \u003c- runTelegramClient token manager $ do\n    info \u003c- getWebhookInfoM\n    let request = setWebhookRequest' \"https://example.com/hook\"\n    isSet \u003c- setWebhookM request\n    getMeM\n  print result\n  print \"done!\"\n```\n\n### Running IO directly (planning to deprecate this option)\n:warning: This method to interact with a Telegram bot is about to be depricated and all new API calls will only have their `M` versions. You can run them using `runTelegramClient` function, for example `runTelegramClient token manager $ sendMessageM message` or in example below replace `getMe token manager` with `runTelegramClient token manager getMeM` to get the same behavior.\n\n`getMe` example\n\n```haskell\n{-# LANGUAGE OverloadedStrings #-}\n\nimport           Network.HTTP.Client      (newManager)\nimport           Network.HTTP.Client.TLS  (tlsManagerSettings)\nimport           Web.Telegram.API.Bot\n\nmain :: IO ()\nmain = do\n  manager \u003c- newManager tlsManagerSettings\n  res \u003c- getMe token manager\n  case res of\n    Left e -\u003e do\n      putStrLn \"Request failed\"\n      print e\n    Right Response { result = u } -\u003e do\n      putStrLn \"Request succeded\"\n      print $ user_first_name u\n  where token = Token \"bot\u003ctoken\u003e\" -- entire Token should be bot123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11\n```\n\n`sendMessage` example\n\n```haskell\n{-# LANGUAGE OverloadedStrings #-}\n\nimport           Network.HTTP.Client      (newManager)\nimport           Network.HTTP.Client.TLS  (tlsManagerSettings)\nimport           Web.Telegram.API.Bot\n\nmain :: IO ()\nmain = do\n  manager \u003c- newManager tlsManagerSettings\n  let request = sendMessageRequest chatId message\n  res \u003c- sendMessage token request manager\n  case res of\n    Left e -\u003e do\n      putStrLn \"Request failed\"\n      print e\n    Right Response { result = m } -\u003e do\n      putStrLn \"Request succeded\"\n      print $ message_id m\n      print $ text m\n  where token = Token \"bot\u003ctoken\u003e\" -- entire Token should be bot123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11\n        chatId = ChatId \u003cchat_id\u003e -- use ChatId 10231 or ChatChannel \"\u003c@channelusername\u003e\"\n        message = \"text *bold* _italic_ [github](github.com/klappvisor/haskell-telegram-api)\"\n```\n\n#### Note on requests:\n\nMany request data records have a lot of optional parameters which are usually redundant.\nThere are two ways to create requests:\n\nWith data type constructor:\n```haskell\nlet request = SendMessageRequest (ChatId int64_chatId) \"text\" Nothing (Just True) Nothing Nothing Nothing\n```\nUsing default instance:\n\n```haskell\nlet request = sendMessageRequest (ChatId int64_chatId) \"text\" -- only with required fields\n```\n\n```haskell\nlet request = (sendMessageRequest ChatId int64_chatId) \"text\") {\n  message_disable_notification = Just True -- with optional fields\n}\n```\n\n## Contribution\n\nContributions are welcome!\n\n1. Fork repository\n2. Do some changes\n3. Create pull request\n4. Wait for CI build and review\n5. ??????\n6. PROFIT\n\nBear in mind that the CI build won't run integration test suite against your pull request since the necessary environment\nvariables (`$BOT_TOKEN`, `$STRIPE_TOKEN`, `$CHAT_ID` and `$BOT_NAME`) aren't exported when a fork\nstarts the build (for security reasons). If you do want to run them before creating RP, you can setup integration of your fork\nwith CircleCI.\n\nYou can use `stack` to build project\n\n```\nstack build\n```\n\nTo run test you have to create your own bot. Go to [BotFather](https://telegram.me/botfather) and create the bot. As the result you will have private bot's access token. Keep it safe!\n\n```\nstack test --test-arguments \"--integration -c CHAT_ID -b BOT_NAME -- HSPEC_ARGS\"\n```\n\nwhere\n\n* `BOT_TOKEN` is the token obtained from BotFather and must be defined as environment variable\n* `PAYMENT_TOKEN` is the token obtained from BotFather and must be defined as environment variable\n* `CHAT_ID` can be id of your chat with your bot. Send some messages to this chat in Telegram and do `curl \"https://api.telegram.org/bot\u003creplace_with_token\u003e/getUpdates\"`, you'll have to parse some JSON with your brain ;-) or any other suitable tool and you will find chat id there.\n* `BOT_NAME` is the name of your bot\n* `HSPEC_ARGS` are the normal `hspec` arguments you can find [here][hspec-args]\n\nThe help option is available for the tests and for hspec:\n\n```\nstack test --test-arguments \"-h\"\nstack test --test-arguments \"--integration -c CHAT_ID -b BOT_NAME -- -h\"\n```\n\nNote: Inline Spec is disabled for now...\n\nIf everything is fine after running the tests you will receive a few new messages from your bot.\n\n[telegram-bot-api]: https://core.telegram.org/bots/api\n[servant]: https://haskell-servant.github.io/\n[hspec-args]: https://hspec.github.io/running-specs.html\n[bot-api]: https://core.telegram.org/bots/api\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fklappvisor%2Fhaskell-telegram-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fklappvisor%2Fhaskell-telegram-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fklappvisor%2Fhaskell-telegram-api/lists"}