Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
T

telego

> 编程语言
Open source

Telegram Bot API library for Go

1.1K stars0 likes2 views
WebsiteGitHub

About

Telegram Bot API library for Go

Telego • Go Telegram Bot API

[![Telegram Bot API Version][TelegramVersionBadge]][TelegramLastVersion] Telego is a Telegram Bot API library for Golang with full [API][TelegramBotAPI] implementation (one-to-one)

The goal of this library was to create API with the same types and methods as actual Telegram Bot API. Every type and method have been represented in types.go and methods.go files with mostly all documentation from Telegram.

For more detailed documentation, see docs at telego.pixelbox.dev.

Note: Telego uses fasthttp instead of net/http and go-json instead of encoding/json by default (both can be changed).

:rocket: Powered by

:clipboard: Table Of Content

Click to show • hide

  • :zap: Getting Started
    • :jigsaw: Basic setup
    • :envelope_with_arrow: Getting updates
    • :kite: Using Telegram methods
    • :soap: Utility methods
    • :mechanical_arm: Helper With... methods
    • :sun_behind_large_cloud: Bot handlers
    • :gear: Build configuration
  • :art: Contribution
  • :star: Stargazers over time
  • :closed_lock_with_key: License

:zap: Getting Started

How to get the library:

bash
go get github.com/mymmrac/telego

Make sure you get the latest version to have all new features and fixes.

More examples can be seen here:

Click to show • hide

  • Basic
  • Configuration
  • Methods
  • Updates (long polling)
  • Updates (webhook)
  • Ngrok webhook
  • Echo bot
  • Echo bot (with handlers)
  • Echo bot (handlers + webhook + graceful shutdown + docker)
  • Conversation bot (state machine)
  • Sending files (documents, photos, media groups)
  • Downloading files
  • Inline keyboard
  • Keyboard
  • Rich text
  • Edit message
  • Utility methods
  • Inline query bot
  • Bot handlers
  • Bot handles (groups + middleware)
  • Update's context
  • Graceful shutdown (no helpers)
  • Graceful shutdown (long polling)
  • Graceful shutdown (webhook)
  • Custom predicates for handlers
  • Handler ordering
  • Specific handlers
  • Update processor
  • Message entities
  • Multi bot webhook
  • Multi bot webhook (using Fiber)
  • Retry caller
  • Menu bot
  • Test server
  • Web Apps (Mini Apps)

Note: Error handling may be missing in examples, but I strongly recommend handling all errors.

Generally, useful information about Telegram Bots and their features:

Click to show • hide

  • :page_facing_up: Telegram Bot API • Telegram documentation of Bot API (full reference)
  • :jigsaw: Telegram Bot Fundamentals • Bots: An introduction for developers
  • :star2: Telegram Bot Features • Describes individual bot elements and features in detail
  • :headphones: Telegram Bot Webhooks • Marvin's Marvellous Guide to All Things Webhook
  • :moneybag: Telegram Bot Payments • Describes payment system and payment lifecycle
  • :iphone: Telegram Bot WebApps • Describes WebApps and interactions with them
  • :link: Ngrok • Connect localhost to the Internet
  • :shield: Let's Encrypt • TLS certificates for free

:jigsaw: Basic setup

▲ Go Up ▲

For start, you need to create an instance of your bot and specify token.

…

:envelope_with_arrow: Getting updates

▲ Go Up ▲

To receive updates, you can use one of two methods:

  • using long polling (bot.UpdatesViaLongPolling)
  • using webhook (bot.UpdatesViaWebhook, recommended way)

Let's start from long polling (easier for local testing):

…

Webhook example (recommended way):

…

For running multiple bots from a single server, see this example.

Tip: For testing webhooks locally, you can use Ngrok to make a tunnel to your localhost, and get a random domain available from the Internet. It's as simple as ngrok http 8080. Or follow Telego + Ngrok example using ngrok/ngrok-go for most convenient bot testing.

Tip: You may wish to use Let's Encrypt in order to generate your free TLS certificate.

:kite: Using Telegram methods

▲ Go Up ▲

All Telegram Bot API methods described in documentation can be used by the library. They have the same names and the same parameters, parameters represented by struct with name: `` + Params. If method doesn't have required parameters nil value can be used as a parameter.

Note: types.go and methods.go were automatically generated from [documentation][TelegramBotAPI], and it's possible that they have errors or missing parts both in comments and actual code. Feel free to report such things.

…

:soap: Utility methods

▲ Go Up ▲

In Telego even though you have all types and methods available, it's often not so convenient to use them directly. To solve this issues telegoutil package was created. It contains utility-helper function that will make your life a bit easier.

I suggest including it with alias to get cleaner code:

go
import tu "github.com/mymmrac/telego/telegoutil"

The package contains couple methods for creating send parameters with all required parameters like:

  • Message(chatID, text) => SendMessageParams
  • Photo(chatID, photoFile) => SendPhotoParams
  • Location(chatID, latitude, longitude) => SendLocationParams
  • ...

Or other useful methods like:

  • ID(intID) => ChatID
  • File(namedReader) => InputFile
  • ...

Utils related to methods can be found in telegoutil/methods, for types in telegoutil/types, for handlers in telegoutil/handler, for api in telegoutil/api.

Note: If you think that something can be added to telegoutil package fill free to create an issue or pull request with desired changes.

:mechanical_arm: Helper With... methods

▲ Go Up ▲

Creating method parameters is sometimes bulky and not convenient, so you can use with methods in combination with utility methods.

Here is a simple example of creating a message with a keyboard that has 4 buttons with different parameters.

…

Those methods allow you to modify values without directly accessing them, also as you saw with methods can be staked one to another to update multiple values.

:sun_behind_large_cloud: Bot handlers

▲ Go Up ▲

Processing updates just in for loop is not the most pleasing thing to do, so Telego provides net/http like handlers, but instead of the path, you provide predicates.

One update will only match to the first handler whose predicates are satisfied, predicates checked in order of handler registration (it's useful to first specify the most specific predicates and then more general).

Also, all handlers (but not their predicates) are processed in parallel.

I suggest including it with alias to get cleaner code:

go
import th "github.com/mymmrac/telego/telegohandler"

Here is an example of using handlers with long polling updates. You can see the full list of available predicates in telegohandler/predicates, or define your own.

…

Just handling updates is useful, but handling specific updates like messages or callback queries in most of the cases is more straightforward and provides cleaner code.

So Telego provides specific handles for all fields of telego.Update. See the list of all available handler types in telegohandler/handlers, or define your own.

…

One more important part of handlers is groups and middlewares. Telego allows creating groups with and without predicates and attaching middleware to groups.

go
package main

import (
	"fmt"

	"github.com/mymmrac/telego"
	th "github.com/mymmrac/telego/telegohandler"
)

func main() {
	// Init ...

	// Add global middleware, it will be applied in order of addition
	bh.Use(func(ctx *th.Context, update telego.Update) error {
		fmt.Println("Global middleware") // Will be called first
		return ctx.Next(update)
	})

	// Create any groups with or without predicates
	// Note: Updates first checked by groups and only then by handlers 
	// (group -> ... -> group -> handler)
	task := bh.Group(th.TextContains("task"))

	// Add middleware to groups
	task.Use(func(ctx *th.Context, update telego.Update) error {
		fmt.Println("Group-based middleware") // Will be called second

		if len(update.Message.Text)  Note: Use `sonic` only on supported platforms as it has its own limitations, more
> [here](https://github.com/bytedance/sonic?tab=readme-ov-file#requirement).

If you wish to set JSON encoding/decoding methods to something custom, there are global methods `SetJSONMarshal` and
`SetJSONUnmarshal` that can be used.

## :art: Contribution

Contribution guidelines listed [here](docs/CONTRIBUTING.md).

## :star: Stargazers over time
> Powered by [caarlos0/starcharts](https://github.com/caarlos0/starcharts)

## :closed_lock_with_key: License

Telego is distributed under [MIT licence](LICENSE).

[TelegramBotAPI]: https://core.telegram.org/bots/api

[TelegramVersionBadge]: https://img.shields.io/static/v1?label=Supported%20Telegram%20Bot%20API&color=29a1d4&logo=telegram&message=v10.3

[TelegramLastVersion]: https://core.telegram.org/bots/api#august-24-2026

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Gobotbot-apibot-frameworkgo

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言