Elixir library for building Telegram bots with a macro-based API.
def deps do
[
{:telegram_ex, "~> 1.2.0"}
]
endConfigure your bot token in config/runtime.exs:
import Config
config :telegram_ex,
my_bot: System.fetch_env!("MY_BOT_TELEGRAM_TOKEN")Define a minimal bot:
defmodule MyBot do
use TelegramEx, name: :my_bot
def handle_message(%{text: "/start", chat: chat}, ctx) do
ctx
|> Message.text("Hello from TelegramEx.")
|> Message.send(chat["id"])
end
def handle_callback(_callback, _ctx), do: :ok
endStart it under your supervision tree:
children = [MyBot]
Supervisor.start_link(children, strategy: :one_for_one)- Getting Started
- Development Model
- Effects
- Commands
- Messages and Media
- Routers
- Finite State Machines
- Examples
- message and callback handlers with pattern matching
- effect-based builder pipelines for error-aware execution
- command DSL with Telegram command menu registration
- fluent builders for messages, keyboards, media, polls, contacts, and locations
- router modules for organizing larger bots
- per-chat FSM state for multi-step conversations
- structured Telegram API errors
See HexDocs for API reference and guides.