gogrammy

package module
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2026 License: MIT Imports: 10 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.

Installation

go get github.com/zzisler/gogrammy

Usage

package main

import (
    "context"
    "github.com/zzisler/gogrammy"
)

func main() {
    app, err := gogrammy.New("YOUR_TOKEN")
    if err != nil {
        panic(err)
    }

    app.Command("/start", func(c *gogrammy.Context) {
        c.Send(c.UserID(), "Привет!", nil)
    })

    app.Start(context.Background())
}

Methods

App
  • New(token, proxy?) — create bot instance
  • Start(ctx) — start bot
Commands
  • Command(cmd, handler) — any chat command
  • PrivateCommand(cmd, handler) — private chat only
  • GroupCommand(cmd, handler) — group/supergroup only
Events
  • On(eventType, handler) — listen to events: message, callback, join_request, my_chat_member, business_message
  • OnCallback(prefix, handler) — listen to callback with prefix
Messages
  • Send(chatID, text, params) — send a message, returns (*models.Message, error)
  • Edit(text, params) — edit current message
  • EditMessage(messageID, text, params) — edit specific message by ID
  • Delete() — delete current message
  • DeleteMessage(messageID) — delete specific message by ID
  • Forward(fromChatID, messageID) — forward specific message
  • Copy(fromChatID, messageID, params) — copy specific message
  • AnswerCallback(text?) — answer callback query
Media
  • SendPhoto(chatID, url, params) — send photo by URL
  • SendAudio(chatID, params) — send audio file or cached audio by file_id
// new file
c.SendAudio(c.UserID(), &gogrammy.AudioParams{
    Title:     "Track Title",
    Performer: "Artist",
    Filename:  "track.mp3",
    TrackData: data,
    CoverData: cover,
})

// cached (by Telegram file_id)
c.SendAudio(c.UserID(), &gogrammy.AudioParams{
    Title:     "Track Title",
    Performer: "Artist",
    FileID:    "BQACAgIAAxkB...",
})
Context helpers
  • c.UserID() — c.Update.Message.From.ID
  • c.FirstName() — c.Update.Message.From.FirstName
  • c.ChatID() — c.Update.Message.Chat.ID
  • c.Text() — c.Update.Message.Text
Admin
  • Ban(chatID, userID, params) — ban user
  • Unban(chatID, userID) — unban user
  • BanChat(chatID, senderChatID) — ban sender chat
  • UnbanChat(chatID, senderChatID) — unban sender chat
  • GetProfilePhoto(userID, params) — get user profile photos
Join Requests
  • ApproveJoin(chatID, userID) — approve join request
  • DeclineJoin(chatID, userID) — decline join request
Keyboards
  • Keyboard(rows...) — create inline keyboard
  • Row(buttons...) — create keyboard row
  • Button(text, data) — create inline button

License

MIT

Documentation

Index

Constants

View Source
const (
	HTML     = "HTML"
	Markdown = "Markdown"
)

Variables

This section is empty.

Functions

func Button

func Button(text string, data string) models.InlineKeyboardButton

Types

type App

type App struct {
	Bot      *bot.Bot
	Username string
}

func New

func New(token string, proxy ...string) (*App, error)

func (*App) Command

func (a *App) Command(cmd string, h Handler)

func (*App) GroupCommand

func (a *App) GroupCommand(cmd string, h Handler)

func (*App) On

func (a *App) On(eventType string, h Handler)

func (*App) OnCallback

func (a *App) OnCallback(prefix string, h Handler)

func (*App) PrivateCommand

func (a *App) PrivateCommand(cmd string, h Handler)

func (*App) Start

func (a *App) Start(ctx context.Context)

type AudioParams added in v0.1.2

type AudioParams struct {
	Title     string
	Performer string
	Filename  string
	FileID    string
	TrackData []byte
	CoverData []byte
}

type BanParams

type BanParams struct {
	UntilDate int
	RevokeMsg bool
}

type Context

type Context struct {
	Ctx    context.Context
	Bot    *bot.Bot
	Update *models.Update
}

func (*Context) AnswerCallback

func (c *Context) AnswerCallback(text ...string) (bool, error)

func (*Context) ApproveJoin

func (c *Context) ApproveJoin(chatID any, userID int64) (bool, error)

func (*Context) Ban

func (c *Context) Ban(chatID any, userID int64, params *BanParams) (bool, error)

func (*Context) BanChat

func (c *Context) BanChat(chatID any, senderChatID int64) (bool, error)

func (*Context) ChatID added in v0.1.2

func (c *Context) ChatID() int64

func (*Context) Copy

func (c *Context) Copy(fromChatID any, messageID int, params *MsgParams) (*models.MessageID, error)

func (*Context) DeclineJoin

func (c *Context) DeclineJoin(chatID any, userID int64) (bool, error)

func (*Context) Delete

func (c *Context) Delete() (bool, error)

func (*Context) DeleteMessage

func (c *Context) DeleteMessage(messageID int) (bool, error)

func (*Context) Edit

func (c *Context) Edit(text string, params *MsgParams) (*models.Message, error)

func (*Context) EditMessage

func (c *Context) EditMessage(messageID int, text string, params *MsgParams) (*models.Message, error)

func (*Context) FirstName added in v0.1.2

func (c *Context) FirstName() string

func (*Context) Forward

func (c *Context) Forward(fromChatID any, messageID int) (*models.Message, error)

func (*Context) GetProfilePhoto

func (c *Context) GetProfilePhoto(userID int64, params *ProfilePhotoParams) (*models.UserProfilePhotos, error)

func (*Context) Send

func (c *Context) Send(chatID any, text string, params *MsgParams) (*models.Message, error)

func (*Context) SendAudio

func (c *Context) SendAudio(chatID any, params *AudioParams) (*models.Message, error)

func (*Context) SendPhoto

func (c *Context) SendPhoto(chatID any, url string, params *PhotoParams) (*models.Message, error)

func (*Context) Text added in v0.1.2

func (c *Context) Text() string

func (*Context) Unban

func (c *Context) Unban(chatID any, userID int64) (bool, error)

func (*Context) UnbanChat

func (c *Context) UnbanChat(chatID any, senderChatID int64) (bool, error)

func (*Context) UserID added in v0.1.2

func (c *Context) UserID() int64

type Handler

type Handler func(c *Context)

type MsgParams

type MsgParams struct {
	ParseMode      string
	Reply          bool
	ReplyMarkup    [][]models.InlineKeyboardButton
	DisablePreview bool
}

type PhotoParams

type PhotoParams struct {
	Caption     string
	ParseMode   string
	Spoiler     bool
	ReplyMarkup [][]models.InlineKeyboardButton
}

type ProfilePhotoParams

type ProfilePhotoParams struct {
	Offset int
	Limit  int
}

Jump to

Keyboard shortcuts

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