https://github.com/bondiano/telega-gleam
Gleam library to build Telegram bots
https://github.com/bondiano/telega-gleam
gleam telegram telegram-bots
Last synced: about 2 months ago
JSON representation
Gleam library to build Telegram bots
- Host: GitHub
- URL: https://github.com/bondiano/telega-gleam
- Owner: bondiano
- License: apache-2.0
- Created: 2024-03-22T14:42:01.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-10-20T14:57:36.000Z (about 2 months ago)
- Last Synced: 2025-10-20T16:42:03.038Z (about 2 months ago)
- Topics: gleam, telegram, telegram-bots
- Language: Gleam
- Homepage: https://hexdocs.pm/telega/
- Size: 1.12 MB
- Stars: 41
- Watchers: 2
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-gleam - telega - [📚](https://hexdocs.pm/telega/) - A Gleam library for the Telegram Bot API with HTTP-based APIs, client implementation, wisp adapter, session bot, and conversation support (Packages / API Clients)
README
# Telega
[](https://hex.pm/packages/telega)
[](https://hexdocs.pm/telega/)
A [Gleam](https://gleam.run/) library for the Telegram Bot API on BEAM.
## It provides
- an interface to the Telegram Bot HTTP-based APIs `telega/api`
- an client for the Telegram Bot API `telega/client`
- adapter to use with [wisp](https://github.com/gleam-wisp/wisp)
- polling implementation
- session bot implementation
- conversation implementation
- convenient utilities for common tasks
## Quick start
> If you are new to Telegram bots, read the official [Introduction for Developers](https://core.telegram.org/bots) written by the Telegram team.
First, visit [@BotFather](https://t.me/botfather) to create a new bot. Copy **the token** and save it for later.
Initiate a gleam project and add `telega` as a dependencies:
```sh
$ gleam new first_tg_bot
$ cd first_tg_bot
$ gleam add telega
```
Replace the `first_tg_bot.gleam` file content with the following code:
```gleam
import telega
import telega/polling
import telega/reply
import telega/router
import telega/update
fn handle_text(ctx, text) {
use ctx <- telega.log_context(ctx, "echo_text")
let assert Ok(_) = reply.with_text(ctx, text)
Ok(ctx)
}
fn handle_command(ctx, command: update.Command) {
use ctx <- telega.log_context(ctx, "echo_command")
let assert Ok(_) = reply.with_text(ctx, "Command: " <> command.text)
Ok(ctx)
}
pub fn main() {
let router =
router.new("echo_bot")
|> router.on_any_text(handle_text)
|> router.on_commands(["start", "help"], handle_command)
let assert Ok(bot) =
telega.new_for_polling(token: "BOT_TOKEN")
|> telega.with_router(router)
|> telega.init_for_polling_nil_session()
let assert Ok(poller) = polling.start_polling_default(bot)
polling.wait_finish(poller)
}
```
Replace `"BOT_TOKEN"` with the token you received from the BotFather. Then run the bot:
```sh
$ gleam run
```
And it will echo all received text messages.
Congratulations! You just wrote a Telegram bot :)
## Examples
Other examples can be found in the [examples](./examples) directory.
## Development
```sh
gleam run # Run the project
gleam test # Run the tests
gleam shell # Run an Erlang shell
```