Skip to content

lsdrfrx/telegram_ex

Repository files navigation

TelegramEx

Elixir library for building Telegram bots with a macro-based API.

GitHub Actions Workflow Status Hex Version Last commit Stars License Hex.pm Downloads

Installation

def deps do
  [
    {:telegram_ex, "~> 1.2.0"}
  ]
end

Quickstart

Configure 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
end

Start it under your supervision tree:

children = [MyBot]
Supervisor.start_link(children, strategy: :one_for_one)

Guides

Features

  • 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

Documentation

See HexDocs for API reference and guides.

About

Elixir library for building Telegram bots with macro-based API

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Contributors

Languages