telegram

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bot

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

Bot is a Telegram bot using go-telegram-bot-api and long polling.

func NewBot

func NewBot(token string, timeout int) (bot *Bot, err error)

func (*Bot) Client

func (b *Bot) Client() *tgbotapi.BotAPI

Client returns the Telegram client.

func (*Bot) Off

func (b *Bot) Off(updateType UpdateType, handler *UpdateHandler)

Off unregisters a handler for a specific update type.

func (*Bot) On

func (b *Bot) On(updateType UpdateType, handler UpdateCallback, filters ...UpdateFilter) *UpdateHandler

On registers a handler for a specific update type.

func (*Bot) Start

func (b *Bot) Start(ctx context.Context, offset int)

Start starts polling for updates.

func (*Bot) Use

func (b *Bot) Use(handler UpdateCallback)

Use adds a middleware to the bot.

func (*Bot) Wait

func (b *Bot) Wait()

Wait waits for all handlers to finish after closing context.

type ChatType

type ChatType string
const (
	ChatTypePrivate    ChatType = "private"
	ChatTypeGroup      ChatType = "group"
	ChatTypeSuperGroup ChatType = "supergroup"
	ChatTypeChannel    ChatType = "channel"
)

type UpdateCallback

type UpdateCallback func(ctx UpdateContext) error

UpdateCallback is a function that handles an update.

type UpdateContext

type UpdateContext struct {
	*WrappedUpdate
	// contains filtered or unexported fields
}

func NewUpdateContext

func NewUpdateContext(bot *Bot, update *WrappedUpdate, ctx context.Context) UpdateContext

NewUpdateContext creates a new update context.

func (UpdateContext) Client

func (ctx UpdateContext) Client() *tgbotapi.BotAPI

Client returns the Telegram client.

func (UpdateContext) Context

func (ctx UpdateContext) Context() context.Context

Context returns the context of the update.

func (UpdateContext) StopPropagation

func (ctx UpdateContext) StopPropagation()

StopPropagation stops the propagation of the update to the next handlers.

type UpdateFilter

type UpdateFilter func(update *WrappedUpdate) (bool, error)

func AnyFilter

func AnyFilter(filters ...UpdateFilter) UpdateFilter

AnyFilter combines multiple filters into one, which returns true if any of the filters return true.

func FilterByChatType

func FilterByChatType(t ChatType) UpdateFilter

FilterByChatType returns a filter that filters updates by chat type.

func FilterByCommand

func FilterByCommand(command string) UpdateFilter

FilterByCommand returns a filter that filters updates by command.

type UpdateHandler

type UpdateHandler struct {
	ID       uuid.UUID
	Callback UpdateCallback
	Filters  []UpdateFilter
}

func NewUpdateHandler

func NewUpdateHandler(handler UpdateCallback, filters ...UpdateFilter) *UpdateHandler

func (*UpdateHandler) ApplyFilters

func (h *UpdateHandler) ApplyFilters(update *WrappedUpdate) (bool, error)

ApplyFilters applies all filters to the update.

type UpdateType

type UpdateType int
const (
	UpdateTypeMessage UpdateType = iota
	UpdateTypeEditedMessage
	UpdateTypeChannelPost
	UpdateTypeEditedChannelPost
	UpdateTypeInlineQuery
	UpdateTypeChosenInlineResult
	UpdateTypeCallbackQuery
	UpdateTypeShippingQuery
	UpdateTypePreCheckoutQuery
	UpdateTypePoll
	UpdateTypePollAnswer
	UpdateTypeMyChatMember
	UpdateTypeChatMember
	UpdateTypeChatJoinRequest
)

func (UpdateType) String

func (u UpdateType) String() string

String returns the string representation of the update type.

type WrappedUpdate

type WrappedUpdate struct {
	// Update is the original update.
	tgbotapi.Update

	// Type is the type of the update.
	Type UpdateType
}

func NewWrappedUpdate

func NewWrappedUpdate(update tgbotapi.Update) (wrappedUpdate *WrappedUpdate)

NewWrappedUpdate creates a new wrapped update.

func (*WrappedUpdate) String

func (w *WrappedUpdate) String() string

String returns the string representation of the wrapped update.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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