telegram

package
v0.13.2 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidToken = errors.New("token is invalid")

Functions

This section is empty.

Types

type Bot added in v0.13.2

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

func NewBotWithHandler added in v0.13.2

func NewBotWithHandler(h Handler) *Bot

NewBotWithHandler create a telegram bot with specified handler.

func (*Bot) AnswerCallbackQuery added in v0.13.2

func (b *Bot) AnswerCallbackQuery(ctx context.Context, callbackQueryID, text string) error

AnswerCallbackQuery make an answerCallbackQuery api request.

func (*Bot) EditMessage added in v0.13.2

func (b *Bot) EditMessage(ctx context.Context, chatID, messageID int, text string, inlineKeyboards [][]InlineKeyboardButton) (*Message, error)

EditMessage make an editMessageText api request.

func (*Bot) GetFile added in v0.13.2

func (b *Bot) GetFile(ctx context.Context, fileID string) (*File, error)

GetFile get download info of File by fileID from Telegram.

func (*Bot) GetUpdates added in v0.13.2

func (b *Bot) GetUpdates(ctx context.Context, offset int) ([]Update, error)

GetUpdates make a getUpdates api request.

func (*Bot) SendReplyMessage added in v0.13.2

func (b *Bot) SendReplyMessage(ctx context.Context, chatID, replyID int, text string) (*Message, error)

SendReplyMessage make a sendMessage api request.

func (*Bot) Start added in v0.13.2

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

Start start an infinity call of getUpdates from Telegram, call r.MessageHandle while get new message updates.

type CallbackQuery added in v0.13.2

type CallbackQuery struct {
	ID              string   `json:"id"`
	From            User     `json:"from"`
	Message         *Message `json:"message"`
	InlineMessageID string   `json:"inline_message_id"`
	ChatInstance    string   `json:"chat_instance"`
	Data            string   `json:"data"`
	GameShortName   string   `json:"game_short_name"`
}

type Chat

type Chat struct {
	ID        int    `json:"id"`
	Title     string `json:"title"`
	Type      string `json:"type"`
	FirstName string `json:"first_name"`
	LastName  string `json:"last_name"`
}

type File

type File struct {
	FileID       string `json:"file_id"`
	FileUniqueID string `json:"file_unique_id"`
	FileSize     int64  `json:"file_size"`
	FilePath     string `json:"file_path"`
}

type Handler

type Handler interface {
	BotToken(ctx context.Context) string
	MessageHandle(ctx context.Context, bot *Bot, message Message, blobs map[string][]byte) error
	CallbackQueryHandle(ctx context.Context, bot *Bot, callbackQuery CallbackQuery) error
}

type InlineKeyboardButton added in v0.13.2

type InlineKeyboardButton struct {
	Text         string `json:"text"`
	CallbackData string `json:"callback_data"`
}

type Message

type Message struct {
	MessageID    int         `json:"message_id"`
	From         User        `json:"from"`
	Date         int         `json:"date"`
	Text         *string     `json:"text"`
	Chat         *Chat       `json:"chat"`
	MediaGroupID *string     `json:"media_group_id"`
	Photo        []PhotoSize `json:"photo"`
	Caption      *string     `json:"caption"`
}

func (Message) GetMaxPhotoFileID

func (m Message) GetMaxPhotoFileID() string

type PhotoSize

type PhotoSize struct {
	FileID       string `json:"file_id"`
	FileUniqueID string `json:"file_unique_id"`
	FileSize     int64  `json:"file_size"`
	Width        int    `json:"width"`
	Height       int    `json:"height"`
}

type Update

type Update struct {
	UpdateID      int            `json:"update_id"`
	Message       *Message       `json:"message"`
	CallbackQuery *CallbackQuery `json:"callback_query"`
}

type User

type User struct {
	ID int `json:"id"`
}

Jump to

Keyboard shortcuts

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