{"id":17339521,"url":"https://github.com/lubien/elixir-lang-bot","last_synced_at":"2025-03-27T08:24:24.348Z","repository":{"id":112974298,"uuid":"74424409","full_name":"lubien/elixir-lang-bot","owner":"lubien","description":"Bot that posts @elixirstatus, @rElixir, @elixir_forum and @pctguama news on Telegram","archived":false,"fork":false,"pushed_at":"2017-02-09T01:12:28.000Z","size":35,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-01T13:24:26.222Z","etag":null,"topics":["elixir","nadia","telegram-bot"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lubien.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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-11-22T02:06:02.000Z","updated_at":"2017-02-14T23:01:16.000Z","dependencies_parsed_at":null,"dependency_job_id":"451f0cd0-c32e-48ca-9fdf-a51b3bec5b34","html_url":"https://github.com/lubien/elixir-lang-bot","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/lubien%2Felixir-lang-bot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lubien%2Felixir-lang-bot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lubien%2Felixir-lang-bot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lubien%2Felixir-lang-bot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lubien","download_url":"https://codeload.github.com/lubien/elixir-lang-bot/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245807447,"owners_count":20675530,"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":["elixir","nadia","telegram-bot"],"created_at":"2024-10-15T15:42:01.133Z","updated_at":"2025-03-27T08:24:24.329Z","avatar_url":"https://github.com/lubien.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Elixir Telegram Bot Boilerplate\n\n\u003e A boilerplate for making bots for telegram using Elixir because of yes\n\n## Getting Started\n\n  1. Setup you bot name and telegram bot token at `config/config.ex`\n\n  \u003e You may set up environment-wide configurations at `dev.ex`, `prod.ex`\n  \u003e and `test` at the `config/` folder if you have different bots for different\n  \u003e environments\n\n    ```elixir\n    config :app,\n      bot_name: \"bot_user_name\"\n\n    config :nadia,\n      token: \"abcdefg_12345678910_the_game\"\n    ```\n\n  2. Setup commands at `lib/app/commands.ex`\n\n  3. Run at your shell\n\n    ```sh\n    λ mix\n    ```\n\n## Macros\n\n```elixir\ncommand \"foo\" do\n    IO.inspect update\n    send_message \"Hello Telegram\"\nend\n```\n\nThe `command/2` macro take a string and a block. In this case, it'll try to match\nanything that starts with `/foo`. Once it matches, it'll inject a constant named\n`update` at the scope of the `do` block.\n\n`send_message/2` is a macro that takes a string and a keyword list of options.\nBut, in fact, `send_message/2` maps to [Nadia.send_message/3](https://hexdocs.pm/nadia/Nadia.html#send_message/3)\na function that takes a chat ID as the first parameter.\n\nThe `send_message/2` macro automatically understands the local scoped `update`\nconstant and properly injects the chat ID for you so you can focus on sending stuff.\nMost of the methods at Nadia module have it's macro version for you. Take a look at\n[App.Commander](lib/app/commander.ex) to understand better.\n\nAnother feature that must be mentioned is that these macros can understand context.\nLet's take a look at the `get_chat_id/2` definitions:\n\n```elixir\n  defmacro get_chat_id do\n    quote do\n      case var!(update) do\n        %{inline_query: inline_query} when not is_nil(inline_query) -\u003e\n          inline_query.from.id\n        %{callback_query: callback_query} when not is_nil(callback_query) -\u003e\n          callback_query.message.chat.id\n        update -\u003e\n          update.message.chat.id\n      end\n    end\n  end\n```\n\nIf you ever used telegram bot API you may have experienced issues trying to find\nwhere is the chat ID for the current update. That's solves it under the hood in\nthis boilerplate for you. Read more about it at [App.Commands](lib/app/commands.ex).\n\n### Matcher macros\n\n```elixir\n# matches \"/foo\" commands\ncommand \"foo\" do\nend\n```\n\n```elixir\n# matches \"/foo\" commands from callback querys\ncallback_query_command \"foo\" do\nend\n```\n\n```elixir\n# matches \"/foo\" commands from inline querys\ninline_query_command \"foo\" do\nend\n```\n\n```elixir\n# fallback for callback querys\ncallback_query do\nend\n```\n\n```elixir\n# fallback for inline querys\ninline_query do\nend\n```\n\n```elixir\n# fallback for all updates\n# must be at the end of the file\nmessage do\nend\n```\n### Sender macros\n\n```elixir\nanswer_callback_query(options \\\\ [])\n```\n\n```elixir\nanswer_inline_query(results, options \\\\ [])\n```\n\n```elixir\nsend_audio(audio, options \\\\ [])\n```\n\n```elixir\nsend_chat_action(action)\n```\n\n```elixir\nsend_contact(phone_number, first_name, options \\\\ [])\n```\n\n```elixir\nsend_document(document, options \\\\ [])\n```\n\n```elixir\nsend_location(latitude, longitude, options \\\\ [])\n```\n\n```elixir\nsend_message(text, options \\\\ [])\n```\n\n```elixir\nsend_photo(photo, options \\\\ [])\n```\n\n```elixir\nsend_sticker(sticker, options \\\\ [])\n```\n\n```elixir\nsend_venue(latitude, longitude, title, address, options \\\\ [])\n```\n\n```elixir\nsend_videos(video, options \\\\ [])\n```\n\n```elixir\nsend_voice(voice, options \\\\ [])\n```\n\n### Action macros\n\n```elixir\n# except for inline querys\nforward_message(chat_id)\n```\n\n```elixir\nget_chat\n```\n\n```elixir\n# except for inline querys\nget_chat_admnistrators\n```\n\n```elixir\nget_chat_member(user_id)\n```\n\n```elixir\nget_chat_member_count\n```\n\n```elixir\n# except for inline querys\nkick_chat_member(user_id)\n```\n\n```elixir\n# except for inline querys\nleave_chat\n```\n\n```elixir\n# except for inline querys\nunban_chat_member\n```\n\n```elixir\nget_chat_id\n```\n\n## See also\n\n* [Rekyuu's version](https://github.com/rekyuu/elixir_telegram_bot).\nI've based my bot mostly in his\n\n## License\n\n[MIT](LICENSE.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flubien%2Felixir-lang-bot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flubien%2Felixir-lang-bot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flubien%2Felixir-lang-bot/lists"}