{"id":37187245,"url":"https://github.com/fullpipe/telebot","last_synced_at":"2026-01-14T21:45:24.970Z","repository":{"id":57515148,"uuid":"243918895","full_name":"fullpipe/telebot","owner":"fullpipe","description":"Telebot is a Telegram bot framework in Go.","archived":false,"fork":true,"pushed_at":"2020-02-29T12:34:38.000Z","size":447,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"v2","last_synced_at":"2025-12-16T03:10:41.397Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"tucnak/telebot","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fullpipe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-02-29T06:44:12.000Z","updated_at":"2020-02-29T06:44:13.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/fullpipe/telebot","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/fullpipe/telebot","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fullpipe%2Ftelebot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fullpipe%2Ftelebot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fullpipe%2Ftelebot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fullpipe%2Ftelebot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fullpipe","download_url":"https://codeload.github.com/fullpipe/telebot/tar.gz/refs/heads/v2","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fullpipe%2Ftelebot/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28436191,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T21:32:52.117Z","status":"ssl_error","status_checked_at":"2026-01-14T21:32:33.442Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-14T21:45:24.218Z","updated_at":"2026-01-14T21:45:24.964Z","avatar_url":"https://github.com/fullpipe.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Telebot\n\u003e\"I never knew creating Telegram bots could be so _sexy_!\"\n\n[![GoDoc](https://godoc.org/gopkg.in/tucnak/telebot.v2?status.svg)](https://godoc.org/gopkg.in/tucnak/telebot.v2)\n[![Travis](https://travis-ci.org/tucnak/telebot.svg?branch=v2)](https://travis-ci.org/tucnak/telebot)\n\n```bash\ngo get -u gopkg.in/tucnak/telebot.v2\n```\n\n* [Overview](#overview)\n* [Getting Started](#getting-started)\n\t- [Poller](#poller)\n\t- [Commands](#commands)\n\t- [Files](#files)\n\t- [Sendable](#sendable)\n\t- [Editable](#editable)\n\t- [Keyboards](#keyboards)\n\t- [Inline mode](#inline-mode)\n* [Contributing](#contributing)\n* [Donate](#donate)\n* [License](#license)\n\n# Overview\nTelebot is a bot framework for [Telegram Bot API](https://core.telegram.org/bots/api).\nThis package provides the best of its kind API for command routing, inline query requests and keyboards, as well\nas callbacks. Actually, I went a couple steps further, so instead of making a 1:1 API wrapper I chose to focus on\nthe beauty of API and performance. Some of the strong sides of telebot are:\n\n* Real concise API\n* Command routing\n* Middleware\n* Transparent File API\n* Effortless bot callbacks\n\nAll the methods of telebot API are _extremely_ easy to memorize and get used to. Also, consider Telebot a\nhighload-ready solution. I'll test and benchmark the most popular actions and if necessary, optimize\nagainst them without sacrificing API quality.\n\n# Getting Started\nLet's take a look at the minimal telebot setup:\n```go\npackage main\n\nimport (\n\t\"time\"\n\t\"log\"\n\n\ttb \"gopkg.in/tucnak/telebot.v2\"\n)\n\nfunc main() {\n\tb, err := tb.NewBot(tb.Settings{\n\t\tToken:  \"TOKEN_HERE\",\n\t\t// You can also set custom API URL. If field is empty it equals to \"https://api.telegram.org\"\n\t\tURL: \"http://195.129.111.17:8012\",\n\t\tPoller: \u0026tb.LongPoller{Timeout: 10 * time.Second},\n\t})\n\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t\treturn\n\t}\n\n\tb.Handle(\"/hello\", func(m *tb.Message) {\n\t\tb.Send(m.Sender, \"hello world\")\n\t})\n\n\tb.Start()\n}\n\n```\n\nSimple, innit? Telebot's routing system takes care of deliviering updates\nto their endpoints, so in order to get to handle any meaningful event,\nall you got to do is just plug your function to one of the Telebot-provided\nendpoints. You can find the full list\n[here](https://godoc.org/gopkg.in/tucnak/telebot.v2#pkg-constants).\n\n```go\nb, _ := tb.NewBot(settings)\n\nb.Handle(tb.OnText, func(m *tb.Message) {\n\t// all the text messages that weren't\n\t// captured by existing handlers\n})\n\nb.Handle(tb.OnPhoto, func(m *tb.Message) {\n\t// photos only\n})\n\nb.Handle(tb.OnChannelPost, func (m *tb.Message) {\n\t// channel posts only\n})\n\nb.Handle(tb.Query, func (q *tb.Query) {\n\t// incoming inline queries\n})\n```\n\nNow there's a dozen of supported endpoints (see package consts). Let me know\nif you'd like to see some endpoint or endpoint idea implemented. This system\nis completely extensible, so I can introduce them without breaking\nbackwards-compatibity.\n\n## Poller\nTelebot doesn't really care how you provide it with incoming updates, as long\nas you set it up with a Poller:\n```go\n// Poller is a provider of Updates.\n//\n// All pollers must implement Poll(), which accepts bot\n// pointer and subscription channel and start polling\n// synchronously straight away.\ntype Poller interface {\n\t// Poll is supposed to take the bot object\n\t// subscription channel and start polling\n\t// for Updates immediately.\n\t//\n\t// Poller must listen for stop constantly and close\n\t// it as soon as it's done polling.\n\tPoll(b *Bot, updates chan Update, stop chan struct{})\n}\n```\n\nTelegram Bot API supports long polling and webhook integration. Poller means you\ncan plug telebot into whatever existing bot infrastructure (load balancers?) you\nneed, if you need to. Another great thing about pollers is that you can chain\nthem, making some sort of middleware:\n```go\npoller := \u0026tb.LongPoller{Timeout: 15 * time.Second}\nspamProtected := tb.NewMiddlewarePoller(poller, func(upd *tb.Update) bool {\n\tif upd.Message == nil {\n\t\treturn true\n\t}\n\n\tif strings.Contains(upd.Message.Text, \"spam\") {\n\t\treturn false\n\t}\n\n\treturn true\n})\n\nbot, _ := tb.NewBot(tb.Settings{\n\t// ...\n\tPoller: spamProtected,\n})\n\n// graceful shutdown\ngo func() {\n\t\u003c-time.After(N * time.Second)\n\tbot.Stop()\n})()\n\nbot.Start() // blocks until shutdown\n\nfmt.Println(poller.LastUpdateID) // 134237\n```\n\n## Commands\nWhen handling commands, Telebot supports both direct (`/command`) and group-like\nsyntax (`/command@botname`) and will never deliver messages addressed to some\nother bot, even if [privacy mode](https://core.telegram.org/bots#privacy-mode) is off.\nFor simplified deep-linking, telebot also extracts payload:\n```go\n// Command: /start \u003cPAYLOAD\u003e\nb.Handle(\"/start\", func(m *tb.Message) {\n\tif !m.Private() {\n\t\treturn\n\t}\n\n\tfmt.Println(m.Payload) // \u003cPAYLOAD\u003e\n})\n```\n\n## Files\n\u003eTelegram allows files up to 20 MB in size.\n\nTelebot allows to both upload (from disk / by URL) and download (from Telegram)\nand files in bot's scope. Also, sending any kind of media with a File created\nfrom disk will upload the file to Telegram automatically:\n```go\na := \u0026tb.Audio{File: tb.FromDisk(\"file.ogg\")}\n\nfmt.Println(a.OnDisk()) // true\nfmt.Println(a.InCloud()) // false\n\n// Will upload the file from disk and send it to recipient\nbot.Send(recipient, a)\n\n// Next time you'll be sending this very *Audio, Telebot won't\n// re-upload the same file but rather utilize its Telegram FileID\nbot.Send(otherRecipient, a)\n\nfmt.Println(a.OnDisk()) // true\nfmt.Println(a.InCloud()) // true\nfmt.Println(a.FileID) // \u003ctelegram file id: ABC-DEF1234ghIkl-zyx57W2v1u123ew11\u003e\n```\n\nYou might want to save certain `File`s in order to avoid re-uploading. Feel free\nto marshal them into whatever format, `File` only contain public fields, so no\ndata will ever be lost.\n\n## Sendable\nSend is undoubteldy the most important method in Telebot. `Send()` accepts a\n`Recipient` (could be user, group or a channel) and a `Sendable`. FYI, not only\nall telebot-provided media types (`Photo`, `Audio`, `Video`, etc.) are `Sendable`,\nbut you can create composite types of your own. As long as they satisfy `Sendable`,\nTelebot will be able to send them out.\n\n```go\n// Sendable is any object that can send itself.\n//\n// This is pretty cool, since it lets bots implement\n// custom Sendables for complex kind of media or\n// chat objects spanning across multiple messages.\ntype Sendable interface {\n    Send(*Bot, Recipient, *SendOptions) (*Message, error)\n}\n```\n\nThe only type at the time that doesn't fit `Send()` is `Album` and there is a reason\nfor that. Albums were added not so long ago, so they are slightly quirky for backwards\ncompatibilities sake. In fact, an `Album` can be sent, but never received. Instead,\nTelegram returns a `[]Message`, one for each media object in the album:\n```go\np := \u0026tb.Photo{File: tb.FromDisk(\"chicken.jpg\")}\nv := \u0026tb.Video{File: tb.FromURL(\"http://video.mp4\")}\n\nmsgs, err := b.SendAlbum(user, tb.Album{p, v})\n```\n\n### Send options\nSend options are objects and flags you can pass to `Send()`, `Edit()` and friends\nas optional arguments (following the recipient and the text/media). The most\nimportant one is called `SendOptions`, it lets you control _all_ the properties of\nthe message supported by Telegram. The only drawback is that it's rather\ninconvenient to use at times, so `Send()` supports multiple shorthands:\n```go\n// regular send options\nb.Send(user, \"text\", \u0026tb.SendOptions{\n\t// ...\n})\n\n// ReplyMarkup is a part of SendOptions,\n// but often it's the only option you need\nb.Send(user, \"text\", \u0026tb.ReplyMarkup{\n\t// ...\n})\n\n// flags: no notification \u0026\u0026 no web link preview\nb.Send(user, \"text\", tb.Silent, tb.NoPreview)\n```\n\nFull list of supported option-flags you can find\n[here](https://github.com/tucnak/telebot/blob/v2/options.go#L9).\n\n## Editable\nIf you want to edit some existing message, you don't really need to store the\noriginal `*Message` object. In fact, upon edit, Telegram only requires `chat_id`\nand `message_id`. So you don't really need the Message as the whole. Also you\nmight want to store references to certain messages in the database, so I thought\nit made sense for *any* Go struct to be editable as a Telegram message, to implement\n`Editable`:\n```go\n// Editable is an interface for all objects that\n// provide \"message signature\", a pair of 32-bit\n// message ID and 64-bit chat ID, both required\n// for edit operations.\n//\n// Use case: DB model struct for messages to-be\n// edited with, say two collums: msg_id,chat_id\n// could easily implement MessageSig() making\n// instances of stored messages editable.\ntype Editable interface {\n\t// MessageSig is a \"message signature\".\n\t//\n\t// For inline messages, return chatID = 0.\n\tMessageSig() (messageID int, chatID int64)\n}\n```\n\nFor example, `Message` type is Editable. Here is the implementation of `StoredMessage`\ntype, provided by telebot:\n```go\n// StoredMessage is an example struct suitable for being\n// stored in the database as-is or being embedded into\n// a larger struct, which is often the case (you might\n// want to store some metadata alongside, or might not.)\ntype StoredMessage struct {\n\tMessageID int   `sql:\"message_id\" json:\"message_id\"`\n\tChatID    int64 `sql:\"chat_id\" json:\"chat_id\"`\n}\n\nfunc (x StoredMessage) MessageSig() (int, int64) {\n\treturn x.MessageID, x.ChatID\n}\n```\n\nWhy bother at all? Well, it allows you to do things like this:\n```go\n// just two integer columns in the database\nvar msgs []tb.StoredMessage\ndb.Find(\u0026msgs) // gorm syntax\n\nfor _, msg := range msgs {\n\tbot.Edit(\u0026msg, \"Updated text.\")\n\t// or\n\tbot.Delete(\u0026msg)\n}\n```\n\nI find it incredibly neat. Worth noting, at this point of time there exists\nanother method in the Edit family, `EditCaption()` which is of a pretty\nrare use, so I didn't bother including it to `Edit()`, just like I did with\n`SendAlbum()` as it would inevitably lead to unnecessary complications.\n```go\nvar m *Message\n\n// change caption of a photo, audio, etc.\nbot.EditCaption(m, \"new caption\")\n```\n\n## Keyboards\nTelebot supports both kinds of keyboards Telegram provides: reply and inline\nkeyboards. Any button can also act as an endpoints for `Handle()`:\n\n```go\nfunc main() {\n\tb, _ := tb.NewBot(tb.Settings{...})\n\n\t// This button will be displayed in the user's\n\t// reply keyboard.\n\treplyBtn := tb.ReplyButton{Text: \"🌕 Button #1\"}\n\treplyKeys := [][]tb.ReplyButton{\n\t\t[]tb.ReplyButton{replyBtn},\n\t\t// ...\n\t}\n\n\t// And this one — just under the message itself.\n\t// Pressing it will cause the client to send\n\t// the bot a callback.\n\t//\n\t// Make sure Unique stays unique as per button _kind_,\n\t// as it has to be for callback routing to work.\n\t//\n\t// Then differentiate with the callback data.\n\tinlineBtn := tb.InlineButton{\n\t\tUnique: \"sad_moon\",\n\t\tText: \"🌚 Button #2\",\n\t}\n\tinlineKeys := [][]tb.InlineButton{\n\t\t[]tb.InlineButton{inlineBtn},\n\t\t// ...\n\t}\n\n\tb.Handle(\u0026replyBtn, func(m *tb.Message) {\n\t\t// on reply button pressed\n\t})\n\n\tb.Handle(\u0026inlineBtn, func(c *tb.Callback) {\n\t\t// on inline button pressed (callback!)\n\n\t\t// always respond!\n\t\tb.Respond(c, \u0026tb.CallbackResponse{...})\n\t})\n\n\t// Command: /start \u003cPAYLOAD\u003e\n\tb.Handle(\"/start\", func(m *tb.Message) {\n\t\tif !m.Private() {\n\t\t\treturn\n\t\t}\n\n\t\t// Telegram does not support messages with both reply\n\t\t// and inline keyboard in them.\n\t\t// \n\t\t// Choose one or the other.\n\t\tb.Send(m.Sender, \"Hello!\", \u0026tb.ReplyMarkup{\n\t\t\tReplyKeyboard:  replyKeys,\n\t\t\t// or\n\t\t\tInlineKeyboard: inlineKeys,\n\t\t})\n\t})\n\n\tb.Start()\n}\n```\n\n## Inline mode\nSo if you want to handle incoming inline queries you better plug the `tb.OnQuery`\nendpoint and then use the `Answer()` method to send a list of inline queries\nback. I think at the time of writing, telebot supports all of the provided result\ntypes (but not the cached ones). This is how it looks like:\n\n```go\nb.Handle(tb.OnQuery, func(q *tb.Query) {\n\turls := []string{\n\t\t\"http://photo.jpg\",\n\t\t\"http://photo2.jpg\",\n\t}\n\n\tresults := make(tb.Results, len(urls)) // []tb.Result\n\tfor i, url := range urls {\n\t\tresult := \u0026tb.PhotoResult{\n\t\t\tURL: url,\n\n\t\t\t// required for photos\n\t\t\tThumbURL: url,\n\t\t}\n\n\t\tresults[i] = result\n\t\tresults[i].SetResultID(strconv.Itoa(i)) // It's needed to set a unique string ID for each result\n\t}\n\n\terr := b.Answer(q, \u0026tb.QueryResponse{\n\t\tResults: results,\n\t\tCacheTime: 60, // a minute\n\t})\n\n\tif err != nil {\n\t\tfmt.Println(err)\n\t}\n})\n```\n\nThere's not much to talk about really. It also support some form of authentication\nthrough deep-linking. For that, use fields `SwitchPMText` and `SwitchPMParameter`\nof `QueryResponse`.\n\n# Contributing\n\n1. Fork it\n2. Clone it: `git clone https://github.com/tucnak/telebot`\n3. Create your feature branch: `git checkout -b my-new-feature`\n4. Make changes and add them: `git add .`\n5. Commit: `git commit -m 'Add some feature'`\n6. Push: `git push origin my-new-feature`\n7. Pull request\n\n# Donate\n\nI do coding for fun but I also try to search for interesting solutions and\noptimize them as much as possible.\nIf you feel like it's a good piece of software, I wouldn't mind a tip!\n\nBitcoin: `1DkfrFvSRqgBnBuxv9BzAz83dqur5zrdTH`\n\n# License\n\nTelebot is distributed under MIT.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffullpipe%2Ftelebot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffullpipe%2Ftelebot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffullpipe%2Ftelebot/lists"}