telegram

package
v0.0.0-...-7a1e2d1 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: MIT Imports: 11 Imported by: ? modules, 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.

Documentation

Overview

Package telegram 提供 Telegram Bot 消息操作的统一封装 所有 Bot 消息发送/编辑/删除操作必须通过此包调用,禁止直接调用原始 API

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnswerCallback

func AnswerCallback(ctx context.Context, b *bot.Bot, callbackID string) (bool, error)

AnswerCallback 响应内联按钮回调 (无提示)

func AnswerCallbackWithAlert

func AnswerCallbackWithAlert(ctx context.Context, b *bot.Bot, callbackID string, text string) (bool, error)

AnswerCallbackWithAlert 响应内联按钮回调 (弹窗提示)

func AnswerCallbackWithText

func AnswerCallbackWithText(ctx context.Context, b *bot.Bot, callbackID string, text string) (bool, error)

AnswerCallbackWithText 响应内联按钮回调 (Toast 提示)

func BackButton

func BackButton(callbackData string) models.InlineKeyboardButton

BackButton 返回按钮 (通用)

func BuildGrid

func BuildGrid(items []string, columns int, prefix string) *models.InlineKeyboardMarkup

BuildGrid 基于列表数据动态生成网格键盘 items: 按钮文本列表 columns: 每行列数 prefix: callback_data 前缀,最终格式为 prefix_index

func Button

func Button(text, callbackData string) models.InlineKeyboardButton

Button 创建普通回调按钮

func CancelButton

func CancelButton() models.InlineKeyboardButton

CancelButton 取消按钮 (通用)

func DeleteMessage

func DeleteMessage(ctx context.Context, b *bot.Bot, chatID int64, messageID int) (bool, error)

DeleteMessage 删除消息

func EditError

func EditError(ctx context.Context, b *bot.Bot, chatID int64, messageID int, errCode string)

EditError 编辑消息为友好错误提示

func EditInlineMessage

func EditInlineMessage(ctx context.Context, b *bot.Bot, inlineMessageID string, text string)

EditInlineMessage 编辑 inline 模式消息文本 (HTML 格式) 用于编辑通过 inline query 发送的消息,使用 InlineMessageID 而非 ChatID+MessageID

func EditInlineMessageWithKeyboard

func EditInlineMessageWithKeyboard(ctx context.Context, b *bot.Bot, inlineMessageID string, text string, keyboard *models.InlineKeyboardMarkup)

EditInlineMessageWithKeyboard 编辑 inline 模式消息文本并更新键盘 (HTML 格式)

func EditMessage

func EditMessage(ctx context.Context, b *bot.Bot, chatID int64, messageID int, text string) (*models.Message, error)

EditMessage 编辑消息文本 (HTML 格式)

func EditMessageWithKeyboard

func EditMessageWithKeyboard(ctx context.Context, b *bot.Bot, chatID int64, messageID int, text string, keyboard *models.InlineKeyboardMarkup) (*models.Message, error)

EditMessageWithKeyboard 编辑消息文本并更新内联键盘 (HTML 格式)

func MainMenuButton() models.InlineKeyboardButton

MainMenuButton 主菜单按钮 (通用)

func SendError

func SendError(ctx context.Context, b *bot.Bot, chatID int64, errCode string)

SendError 发送友好错误提示

func SendMessage

func SendMessage(ctx context.Context, b *bot.Bot, chatID int64, text string) (*models.Message, error)

SendMessage 发送纯文本消息 (HTML 格式)

func SendMessageWithKeyboard

func SendMessageWithKeyboard(ctx context.Context, b *bot.Bot, chatID int64, text string, keyboard *models.InlineKeyboardMarkup) (*models.Message, error)

SendMessageWithKeyboard 发送带内联键盘的消息 (HTML 格式)

func SendPhoto

func SendPhoto(ctx context.Context, b *bot.Bot, chatID int64, photo *models.InputFileString, caption string, keyboard *models.InlineKeyboardMarkup) (*models.Message, error)

SendPhoto 发送图片消息

func SendPhotoBytes

func SendPhotoBytes(ctx context.Context, b *bot.Bot, chatID int64, photoData []byte, filename string, caption string, keyboard *models.InlineKeyboardMarkup) (*models.Message, error)

SendPhotoBytes 发送图片消息 (字节流)

func SwitchInlineButton

func SwitchInlineButton(text, query string) models.InlineKeyboardButton

SwitchInlineButton 创建选择聊天内联查询按钮 注意: 同 SwitchInlineCurrentChatButton,空字符串需要零宽空格 workaround

func SwitchInlineCurrentChatButton

func SwitchInlineCurrentChatButton(text, query string) models.InlineKeyboardButton

SwitchInlineCurrentChatButton 创建当前聊天内联查询按钮 注意: go-telegram/bot 的 SwitchInlineQueryCurrentChat 字段使用 omitempty, 空字符串会被 JSON 序列化丢弃导致按钮无效。使用零宽空格作为 workaround。

func URLButton

func URLButton(text, url string) models.InlineKeyboardButton

URLButton 创建 URL 链接按钮

Types

type InlineKeyboardBuilder

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

InlineKeyboardBuilder 内联键盘构建器,支持链式调用

func NewInlineKeyboard

func NewInlineKeyboard() *InlineKeyboardBuilder

NewInlineKeyboard 创建内联键盘构建器

func (*InlineKeyboardBuilder) Build

Build 构建内联键盘

func (*InlineKeyboardBuilder) Row

Row 添加一行按钮

type Session

type Session struct {
	Module string                 `json:"module"` // 当前模块 (Wallet/Transfer/Exchange 等)
	Step   string                 `json:"step"`   // 当前步骤
	Data   map[string]interface{} `json:"data"`   // 临时数据
}

Session 用户会话数据

type SessionService

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

SessionService Redis 会话管理服务

func NewSessionService

func NewSessionService(rdb *redis.Client) *SessionService

NewSessionService 创建会话管理服务

func (*SessionService) Clear

func (s *SessionService) Clear(ctx context.Context, userID int64) error

Clear 清除用户会话

func (*SessionService) Get

func (s *SessionService) Get(ctx context.Context, userID int64) *Session

Get 获取用户当前会话 如果不存在返回空闲状态会话

func (*SessionService) GetData

func (s *SessionService) GetData(ctx context.Context, userID int64, key string) (interface{}, bool)

GetData 获取临时数据

func (*SessionService) GetDataFloat

func (s *SessionService) GetDataFloat(ctx context.Context, userID int64, key string) float64

GetDataFloat 获取临时数据为浮点数

func (*SessionService) GetDataString

func (s *SessionService) GetDataString(ctx context.Context, userID int64, key string) string

GetDataString 获取临时数据为字符串

func (*SessionService) GetStep

func (s *SessionService) GetStep(ctx context.Context, userID int64) (module, step string)

GetStep 获取当前步骤

func (*SessionService) IsIdle

func (s *SessionService) IsIdle(ctx context.Context, userID int64) bool

IsIdle 判断用户是否处于空闲状态 (无进行中的会话)

func (*SessionService) SetData

func (s *SessionService) SetData(ctx context.Context, userID int64, key string, value interface{}) error

SetData 存储临时数据

func (*SessionService) SetStep

func (s *SessionService) SetStep(ctx context.Context, userID int64, module, step string) error

SetStep 设置当前会话步骤

func (*SessionService) SetStepWithData

func (s *SessionService) SetStepWithData(ctx context.Context, userID int64, module, step string, data map[string]interface{}) error

SetStepWithData 设置步骤同时写入数据

Jump to

Keyboard shortcuts

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