DEV Community

ZenDrx
ZenDrx

Posted on

From Ruby to Crystal: Why I ported telegem to telecr

After my work on telegem (a Ruby gem for creating DSLs), I began to notice the stark differences between interpreted and compiled languages.

Ruby is fast, but for high-concurrency needs like Telegram bots, I wanted to see what Crystal could do. To my surprise, porting the logic worked beautifully. Today, I’m excited to announce telecr.

What is Telecr?

Telecr is a fast, fiber-based library for creating Telegram bots in Crystal. Think of it as telegem with superpowers.

Key Features

  • Blazing Fast: Leverages Crystal's performance and fiber-based concurrency.
  • Type Safe: Catch errors at compile time before they hit production.
  • Disk Backup: Reliable data handling.
  • Clean DSL: Designed for a great developer experience.

Quick Look at the DSL

 bot.command("start") do ctx 
   ctx.reply("welcome")
end
Enter fullscreen mode Exit fullscreen mode

Join the Project

I'm officially opening this up for contributions and improvements! You can find the source code and documentation here:

GitHub logo slick-lab / telecr

A modern fiber based crystal framework for create telegram bots

Telecr

Telegram bot framework for Crystal. Inspired by telegem (Ruby).

Pipeline Status Coverage Latest Release Crystal License: MIT

Documentation

Full API documentation is available at: https://telecr.gitlab.io

Installation

Add to your shard.yml:

dependencies:
  telecr:
    github: slick-lab/telecr
    version: ~> 1.0.0
Enter fullscreen mode Exit fullscreen mode

Then run:

shards install
Enter fullscreen mode Exit fullscreen mode

Quick Start

require "telecr"

bot = Telecr.new("YOUR_BOT_TOKEN")

bot.command("start") do |ctx|
  ctx.reply("Welcome to Telecr!")
end

bot.start_polling
Enter fullscreen mode Exit fullscreen mode

Features

  • Full Telegram Bot API support
  • Polling and webhook modes
  • Middleware system (session, rate limiting, file upload)
  • Reply and inline keyboards
  • Type-safe context objects
  • Session management with disk backup
  • File upload to shrine storage

Usage

Basic Bot

bot = Telecr.new("TOKEN")

bot.command("start") do |ctx|
  ctx.reply("Hello! I'm a Telecr bot.")
end

bot.hears(/hi/i) do |ctx|
  ctx.reply("Hi there!")
end

bot.start_polling
Enter fullscreen mode Exit fullscreen mode

I'm curious—have any of you moved a project from Ruby to Crystal? What was your biggest "aha!" moment during the port?

Top comments (0)