DEV Community

idk
idk

Posted on

Writing a 0-dependency Telegram SDK with auto-generated types

Why I built a zero-dependency Telegram SDK from scratch

Let's be honest: most Telegram Bot SDKs are either too heavy or have inconsistent type definitions. I wanted something lean, fast, and 100% type-safe.

That's why I created Surfgram.

The "Zero" Philosophy

The main goal was to have 0 dependencies. No axios, no node-fetch, just native Node.js https.

  • Lightweight: Tiny bundle size and fast installation.
  • Secure: Fewer dependencies means a smaller attack surface.

Auto-generated Types

Instead of manually maintaining interfaces (which is a nightmare), I built a generator that scrapes the official Telegram Bot API documentation.

  • Always up-to-date: If the API changes, I just rerun the generator.
  • Strict Safety: I focused on eliminating undefined errors by using strict null checks and proper type guards for API responses.

How it looks

import { Bot, Message } from 'surfgram';

const bot = new Bot('TOKEN');

bot.onMessage('/start', (message: Message) => {
  message.sendMessage({ text: 'hi there' });
});

bot.startPolling();
Enter fullscreen mode Exit fullscreen mode

Give it a try!

The project is fully open-source. I’m looking for feedback on the architecture and type generation logic.

GitHub: https://github.com/surfgram/surfgram

If you like the "no-bloat" approach, a ⭐ would be much appreciated!

Top comments (0)