Skip to content
Go 1.27+Bot API 10.3MIT Licensev0.1.2

TeleIQ

A Go library for the Telegram Bot API.

Every type and method of Bot API 10.3 as typed Go code, and a framework for bots that run for months: it receives updates by long polling or webhook, handles the updates of each chat in order, retries failed requests, and never writes the bot token to errors or logs.

go get github.com/DhurghamAhmed/teleiq@latest
TeleIQ logo

185

Bot API methods

400

Bot API types

0

dependencies

7

packages

Why TeleIQ

Built for bots that stay up: the hard parts of talking to Telegram are done for you.

01

The whole Bot API

Every one of the 185 methods and 400 types of Bot API 10.3 is typed Go, generated from Telegram's official documentation and checked for updates every day.

02

Only the standard library

No third-party dependencies: nothing extra to download, audit or keep up to date.

03

Ordered, never lost

The updates of each chat are handled one at a time and in order, and an update is confirmed to Telegram only after it is handled.

04

Retries and rate limits

Failed requests are retried after network errors, server errors and flood control, and an optional rate limiter paces requests in all and per chat.

05

Errors by name

Check errors with errors.Is: ErrBotBlocked, ErrChatNotFound, ErrMessageNotModified, ErrNotEnoughRights and more.

06

The token stays secret

The bot token never appears in errors or logs, so they can be shared safely.

Your first bot

From nothing to a running bot in four steps.

  1. 1

    Install

    TeleIQ needs Go 1.27 or later.

    go get github.com/DhurghamAhmed/teleiq@latest
  2. 2

    Get a token

    Talk to @BotFather on Telegram, send /newbot and copy the token it gives you.

  3. 3

    Write the bot

    A complete bot that greets /start and repeats every other message.

    main.go
    package main
    
    import (
    	"context"
    	"log"
    	"os"
    	"os/signal"
    
    	"github.com/DhurghamAhmed/teleiq"
    	"github.com/DhurghamAhmed/teleiq/bot"
    )
    
    func main() {
    	// ctx ends on Ctrl+C, which stops the bot.
    	ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
    	defer stop()
    
    	client, err := teleiq.NewClient(os.Getenv("BOT_TOKEN"))
    	if err != nil {
    		log.Fatal(err)
    	}
    	b := bot.New(client) // b is the bot
    	b.OnCommand("start", bot.ReplyWith("Hello! Send me a message and I will repeat it."))
    	// c is the current message; c.Send replies in its chat.
    	b.OnMessage(func(ctx context.Context, c *bot.Context) error {
    		return c.Send(ctx, "You said: "+c.Text())
    	})
    	if err := b.Run(ctx); err != nil { // receives updates until ctx ends
    		log.Fatal(err)
    	}
    }
  4. 4

    Run it

    Start the bot, then open it in Telegram and send /start.

    export BOT_TOKEN='<token from @BotFather>'
    go run .

The packages

Use the client alone, or the whole framework. Each package has one job.

Examples

Short and real: every snippet comes from the library's README and examples.

Required parameters are plain fields; optional ones are pointers, set with teleiq.Ptr. Errors match by name.

methods.go
me, err := client.GetMe(ctx)
if err != nil {
	log.Fatal(err)
}
_, err = client.SendMessage(ctx, teleiq.SendMessageParams{
	ChatID:              models.ID(123456789), // or models.Username("@channel")
	Text:                "Hello from " + me.FirstName,
	DisableNotification: teleiq.Ptr(true),
})
switch {
case errors.Is(err, teleiq.ErrBotBlocked):
	// The user blocked the bot.
case errors.Is(err, teleiq.ErrTooManyRequests):
	// Flood control that the retries could not wait out.
}

15 complete programs, each with a test, are in the examples folder.

Follow TeleIQ

News, help and the docs, right inside Telegram.