{"id":17767143,"url":"https://github.com/prillan/telegram-bot-edsl","last_synced_at":"2025-09-17T18:31:03.212Z","repository":{"id":146191696,"uuid":"64841326","full_name":"Prillan/telegram-bot-edsl","owner":"Prillan","description":null,"archived":false,"fork":false,"pushed_at":"2018-09-09T16:34:00.000Z","size":34,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-28T04:04:08.166Z","etag":null,"topics":["telegram","telegram-bot"],"latest_commit_sha":null,"homepage":null,"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/Prillan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-08-03T11:35:39.000Z","updated_at":"2022-03-05T16:43:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"9088f11a-3698-47a2-8cd5-3e5504878973","html_url":"https://github.com/Prillan/telegram-bot-edsl","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Prillan%2Ftelegram-bot-edsl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Prillan%2Ftelegram-bot-edsl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Prillan%2Ftelegram-bot-edsl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Prillan%2Ftelegram-bot-edsl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Prillan","download_url":"https://codeload.github.com/Prillan/telegram-bot-edsl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233413542,"owners_count":18672696,"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":["telegram","telegram-bot"],"created_at":"2024-10-26T20:42:55.284Z","updated_at":"2025-09-17T18:30:57.894Z","avatar_url":"https://github.com/Prillan.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"This is a WIP. You have been warned.\n\n## Telegram Bot EDSL\n\nThis is a library for easy creation of telegram bots. A full example\ncan be found in `example/Main.hs`.\n\nNote: Currently requires\n[this patched version of `telegram-api`](https://github.com/Prillan/haskell-telegram-api/tree/setwebhook-patch). It\nadds the possibility of uploading self-signed certs.\n\n## Syntax\n\nThe DSL is built on top of\n[`pipes`](https://www.stackage.org/package/pipes) using `await` to get\nan update from telegram and `yield` to send a response back. It also\nprovides a set of combinator to make all of this easier.\n\n### Base\n\n```haskell\ntype Bot m = Proxy () BotInput () BotOutput (ReaderT BotEnv m)\n\ntype MessageId = Int\ndata BotInput = BotTextMessage { botTextMessageText   :: Text\n                               , botTextMessageId     :: MessageId\n                               , botTextMessageUserId :: Int }\n\ndata BotOutput = BotSend Text (Maybe MessageId)\ndata BotEnv = BotEnv { botName :: Text }\n```\n\n### Combinators\n\n```haskell\nsend           :: Monad m =\u003e Text -\u003e Bot m ()\ninput          :: Monad m =\u003e Bot m Text\ninputWithReply :: Monad m =\u003e Bot m (Text, Text -\u003e Bot m ())\nenv            :: Monad m =\u003e Bot m BotEnv\ncmd            :: Monad m =\u003e Text -\u003e (Text -\u003e Bot m a) -\u003e BotCommand (Bot m a)\nchoice         :: Monad m =\u003e BotCommand (Bot m a) -\u003e Bot m a\n```\n\n### Example\n```haskell\nimport qualified Data.Text as T\nimport Data.Time (getZonedTime)\nimport Web.Telegram.Bot.DSL\n\nbot = choice $ cmd \"echo\"    (\\m -\u003e send m)\n            \u003c\u003e cmd \"reverse\" (\\m -\u003e send (T.reverse m))\n            \u003c\u003e cmd \"date\"    (\\_ -\u003e do\n                               t \u003c- liftIO $ getZonedTime\n                               send $ \"The time is: \" \u003c\u003e (T.pack . show $ t))\n```\n\n## How to run it\n\nYou can always test your bot in the terminal by running\n`runBotInTerminal bot`.\n\nThere are two main ways of running the bot, via webhooks or long\npolling.\n\n### Run the bot with webhooks\n\nYou need five things.\n\n1. The ssl certificate file.\n2. The ssl private key file.\n3. A url that telegram will send it's updates too. (Needs to match the\n   ssl certificate)\n4. The local port\n5. The bot token\n\n#### Generating a SSL certificate\n\nSee\n[Generating a self-signed certificate pair](https://core.telegram.org/bots/self-signed).\n\n#### Getting a bot token\n\nFollow the steps over at\n[Bots: An introduction for developers](https://core.telegram.org/bots#6-botfather).\n\n#### What's up with the remote url and local port?\n\nIn order for your bot to receive update you have to expose it to the\ninternet. The first step is to get a domain pointing at your server,\nlet's say `example.com`. Then you need an open port to point at your\nlocal server port. Telegram will only send updates to the ports 80,\n88, 443 and 8443 so make sure that you're using one of those.\n\nExample:\n`example.com  → x.y.z.w`\n`:8443 → :5000`\n\n#### (Optional) Extra server settings\n\nSee [the docs for the Warp web server](https://www.stackage.org/package/warp).\n\n#### Putting it all together\n\n```haskell\nbs = BotSettings\n  {\n    bsSslCert        = \"\u003cPATH_TO_SELF_SIGNED_CERT\u003e.pem\"\n  , bsSSlKey         = \"\u003cPATH_TO_SELF_SIGNED_KEY\u003e.key\"\n  , bsRemoteUrl      = \"https://example.com:8443\"\n  , bsListeningPort  = 5000\n  , bsToken          = \"\u003cYOUR_BOT_TOKEN\u003e\"\n  , bsServerSettings = Nothing\n  , bsBotEnv         = BotEnv \"\u003cBOT_USER_NAME\u003e\"\n  }\n```\n\nRun the server: `runBotWithWebhooks bs bot`.\n\n\n### Run the bot with long polling\n\nThis is a lot easier and you only need the bot token and the bot user\nname.\n\n```haskell\nenv = BotEnv\n  {\n    botName = \"\u003cBOT_USER_NAME\u003e\"\n  }\ntoken = \"\u003cBOT_TOKEN\u003e\"\n```\n\nRun it: `runBotWithPolling token env`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprillan%2Ftelegram-bot-edsl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprillan%2Ftelegram-bot-edsl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprillan%2Ftelegram-bot-edsl/lists"}