gogrammy

package module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 7 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README


gogrammy

A simple and clean Telegram bot wrapper for Go, inspired by Grammy.

A fluent builder-API wrapper over go-telegram/bot — no more bulky &Param{} structs.

⭐ gogrammy is officially listed in Telegram's library docs — core.telegram.org/bots/samples#go

// before (go-telegram/bot directly)
b.SendMessage(ctx, &bot.SendMessageParams{
    ChatID:    userID,
    Text:      "Hello!",
    ParseMode: models.ParseModeHTML,
})

// with gogrammy
ctx.SendText(userID, "Hello!").
    ParseMode(models.ParseModeHTML).
    Do(ctx.Ctx)

Why gogrammy

  • Builders instead of param structs. Every content type (text, photo, video, document, audio, voice, video note) has its own builder with a chainable API. Your IDE's autocomplete only shows what's actually valid for that type.
  • One Context type for everything. No juggling between Client and Context — sending, editing, and keyboards all live in one place.
  • Event-based routing. Command, On, OnCallback — register handlers without writing your own dispatcher, built on top of go-telegram/bot.
  • Nothing reinvented. gogrammy doesn't replace the HTTP client or the Telegram API layer — it uses the stable go-telegram/bot under the hood and adds a convenience layer on top.

Install

go get github.com/zzisler/gogrammy@latest

Quick start

package main

import (
    "context"
    "os"

    "github.com/zzisler/gogrammy"
)

func main() {
    ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
	defer cancel()

    b, err := gogrammy.New(os.Getenv("BOT_TOKEN"))
    if err != nil {
        panic(err)
    }

    b.Command("/start", func(c *gogrammy.Context) {
        userID := c.Update.Message.From.ID
        c.SendText(userID, "Hi! I'm a gogrammy bot 👋").Do(c.Ctx)
    })

    b.Start(ctx)
}

More examples in examples/.

What's included

Category Methods
Sending SendText, SendPhoto, SendVideo, SendDocument, SendAudio, SendVoice, SendVideoNote
Editing EditText, EditCaption, EditMedia
Deleting DeleteMessage
Keyboards NewInlineKeyboard, NewReplyKeyboard, RemoveKeyboard
Join requests ApproveJoin, DeclineJoin
Other SendChatAction, AnswerCallback
Routing Command, On, OnCallback, Start

Full method reference with all optional parameters and examples: API.md.

Working with files

Every media builder accepts a source in four ways:

ctx.SendPhoto(userID).FileID("AAA...")        // file already on Telegram's servers
ctx.SendPhoto(userID).FileURL("https://...")  // direct link
ctx.SendPhoto(userID).FilePath("./photo.png") // upload from disk
ctx.SendPhoto(userID).FileBytes(buf)          // loading bytes from memory

Keyboards

Inline keyboard — attached to a specific message, sends a callback_query on tap:

kb := ctx.NewInlineKeyboard().
    Text("Button 1", "btn1").
    Row().
    URL("Website", "https://example.com").
    Build()

ctx.SendText(userID, "Choose:").ReplyMarkup(kb).Do(ctx.Ctx)

Reply keyboard — replaces the user's system keyboard, taps come back as regular text messages:

kb := ctx.NewReplyKeyboard().
    Text("Menu").
    Row().
    Text("Help").
    Resize().
    Build()

ctx.SendText(userID, "Choose:").ReplyMarkup(kb).Do(ctx.Ctx)

Removing a reply keyboard:

ctx.SendText(userID, "Keyboard removed").ReplyMarkup(ctx.RemoveKeyboard()).Do(ctx.Ctx)

Status

Actively developed. Core functionality (sending/editing/deleting all content types, keyboards, routing, join requests) is implemented and tested against a live bot. Feedback and issues are welcome.

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bot added in v1.1.0

type Bot struct {
	// contains filtered or unexported fields
}

func New

func New(token string, opts ...ClientOption) (*Bot, error)

func (*Bot) API added in v1.1.0

func (b *Bot) API() *bot.Bot

func (*Bot) Command added in v1.1.0

func (b *Bot) Command(cmd string, h Handler)

func (*Bot) On added in v1.1.0

func (b *Bot) On(eventType string, h Handler)

func (*Bot) OnCallback added in v1.1.0

func (b *Bot) OnCallback(prefix string, h Handler)

func (*Bot) Start added in v1.1.0

func (b *Bot) Start(ctx context.Context)

type ClientOption added in v1.0.0

type ClientOption func(*clientConfig)

func WithMiddlewares added in v1.1.0

func WithMiddlewares(mws ...bot.Middleware) ClientOption

func WithProxy added in v1.0.0

func WithProxy(proxyURL string) ClientOption

type Context

type Context struct {
	Update *models.Update
	Ctx    context.Context
	// contains filtered or unexported fields
}

func (*Context) API added in v1.1.0

func (c *Context) API() *bot.Bot

func (*Context) AnswerCallback

func (c *Context) AnswerCallback() *builder.AnswerCallbackBuilder

func (*Context) ApproveJoin

func (c *Context) ApproveJoin(chatID, userID int64) *builder.ApproveJoinBuilder

func (*Context) ChatID added in v0.1.2

func (c *Context) ChatID() int64

func (*Context) DeclineJoin

func (c *Context) DeclineJoin(chatID, userID int64) *builder.DeclineJoinBuilder

func (*Context) DeleteMessage

func (c *Context) DeleteMessage(userID int64, messageID int) *builder.DeleteBuilder

func (*Context) EditCaption added in v1.0.0

func (c *Context) EditCaption(userID int64, messageID int, caption string) *builder.EditCaptionBuilder

func (*Context) EditMessageMedia added in v1.0.0

func (c *Context) EditMessageMedia(userID int64, messageID int) *builder.EditMediaBuilder

func (*Context) EditText added in v1.0.0

func (c *Context) EditText(userID int64, messageID int, text string) *builder.EditTextBuilder

func (*Context) NewInlineKeyboard added in v1.0.0

func (c *Context) NewInlineKeyboard() *builder.InlineKeyboardBuilder

func (*Context) NewReplyKeyboard added in v1.0.0

func (c *Context) NewReplyKeyboard() *builder.ReplyKeyboardBuilder

func (*Context) RemoveKeyboard added in v1.0.0

func (c *Context) RemoveKeyboard() models.ReplyKeyboardRemove

func (*Context) SendAudio

func (c *Context) SendAudio(userID int64) *builder.AudioBuilder

func (*Context) SendChatAction added in v1.0.0

func (c *Context) SendChatAction(userID int64, action models.ChatAction) *builder.ChatActionBuilder

func (*Context) SendDocument added in v1.0.0

func (c *Context) SendDocument(userID int64) *builder.DocumentBuilder

func (*Context) SendPhoto

func (c *Context) SendPhoto(userID int64) *builder.PhotoBuilder

func (*Context) SendText added in v1.0.0

func (c *Context) SendText(userID int64, text string) *builder.TextBuilder

func (*Context) SendVideo added in v1.0.0

func (c *Context) SendVideo(userID int64) *builder.VideoBuilder

func (*Context) SendVideoNote added in v1.0.0

func (c *Context) SendVideoNote(userID int64) *builder.VideoNoteBuilder

func (*Context) SendVoice added in v1.0.0

func (c *Context) SendVoice(userID int64) *builder.VoiceBuilder

func (*Context) UserID added in v0.1.2

func (c *Context) UserID() int64

type Handler

type Handler func(*Context)

Directories

Path Synopsis
examples
command_handler command
edit_message command
keyboard command
send_photo command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL