dispatch

package
v0.0.0-...-45605f7 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: Apache-2.0 Imports: 17 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 represents generic Telegram bot state and event dispatcher.

func NewBot

func NewBot(raw *tg.Client) *Bot

NewBot creates new bot.

func (*Bot) OnBotCallbackQuery

func (b *Bot) OnBotCallbackQuery(ctx context.Context, e tg.Entities, u *tg.UpdateBotCallbackQuery) error

func (*Bot) OnBotInlineQuery

func (b *Bot) OnBotInlineQuery(ctx context.Context, e tg.Entities, u *tg.UpdateBotInlineQuery) error

func (*Bot) OnButton

func (b *Bot) OnButton(handler ButtonHandler) *Bot

OnButton sets button handler.

func (*Bot) OnInline

func (b *Bot) OnInline(handler InlineHandler) *Bot

OnInline sets inline query handler.

func (*Bot) OnMessage

func (b *Bot) OnMessage(handler MessageHandler) *Bot

OnMessage sets message handler.

func (*Bot) OnNewChannelMessage

func (b *Bot) OnNewChannelMessage(ctx context.Context, e tg.Entities, u *tg.UpdateNewChannelMessage) (rerr error)

func (*Bot) OnNewMessage

func (b *Bot) OnNewMessage(ctx context.Context, e tg.Entities, u *tg.UpdateNewMessage) (rerr error)

func (*Bot) Register

func (b *Bot) Register(dispatcher tg.UpdateDispatcher) *Bot

Register sets handlers using given dispatcher.

func (*Bot) WithGitHub

func (b *Bot) WithGitHub(client *github.Client) *Bot

func (*Bot) WithSender

func (b *Bot) WithSender(sender *message.Sender) *Bot

WithSender sets message sender to use.

func (*Bot) WithTracerProvider

func (b *Bot) WithTracerProvider(provider trace.TracerProvider) *Bot

type Button

type Button struct {
	QueryID int64
	Input   *tg.InputUser
	Data    []byte

	User *tg.User
	// contains filtered or unexported fields
}

func (Button) Logger

func (e Button) Logger() *zap.Logger

Logger returns associated lg.

func (Button) RPC

func (e Button) RPC() *tg.Client

RPC returns Telegram RPC client.

func (Button) Sender

func (e Button) Sender() *message.Sender

Sender returns *message.Sender

type ButtonHandler

type ButtonHandler interface {
	OnButton(ctx context.Context, e Button) error
}

type ButtonHandlerFunc

type ButtonHandlerFunc func(ctx context.Context, e Button) error

ButtonHandlerFunc is a functional adapter for Handler.

func (ButtonHandlerFunc) OnButton

func (h ButtonHandlerFunc) OnButton(ctx context.Context, e Button) error

OnButton implements ButtonHandler.

type InlineHandler

type InlineHandler interface {
	OnInline(ctx context.Context, e InlineQuery) error
}

InlineHandler is a simple inline query event handler.

type InlineHandlerFunc

type InlineHandlerFunc func(ctx context.Context, e InlineQuery) error

InlineHandlerFunc is a functional adapter for Handler.

func (InlineHandlerFunc) OnInline

func (h InlineHandlerFunc) OnInline(ctx context.Context, e InlineQuery) error

OnInline implements InlineHandler.

type InlineQuery

type InlineQuery struct {
	QueryID  int64
	Query    string
	Offset   string
	Enquirer *tg.InputUser
	// contains filtered or unexported fields
}

InlineQuery represents inline query event.

func (InlineQuery) Geo

func (e InlineQuery) Geo() (*tg.GeoPoint, bool)

Geo returns GeoPoint object and true if query has attached geo point. False and nil otherwise.

func (InlineQuery) Logger

func (e InlineQuery) Logger() *zap.Logger

Logger returns associated lg.

func (InlineQuery) RPC

func (e InlineQuery) RPC() *tg.Client

RPC returns Telegram RPC client.

func (InlineQuery) Reply

func (e InlineQuery) Reply() *inline.ResultBuilder

Reply returns result builder.

func (InlineQuery) Sender

func (e InlineQuery) Sender() *message.Sender

Sender returns *message.Sender

func (InlineQuery) User

func (e InlineQuery) User() (*tg.User, bool)

User returns User object if available. False and nil otherwise.

type LoggedDispatcher

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

LoggedDispatcher is update logging middleware.

func NewLoggedDispatcher

func NewLoggedDispatcher(next telegram.UpdateHandler, log *zap.Logger, traceProvider trace.TracerProvider) LoggedDispatcher

NewLoggedDispatcher creates new update logging middleware.

func (LoggedDispatcher) Handle

Handle implements telegram.UpdateHandler.

type MessageEvent

type MessageEvent struct {
	Peer    tg.InputPeerClass
	Message *tg.Message
	// contains filtered or unexported fields
}

MessageEvent represents message event.

func (MessageEvent) Channel

func (e MessageEvent) Channel() (*tg.Channel, bool)

Channel returns Channel object and true if message got from channel. False and nil otherwise.

func (MessageEvent) Chat

func (e MessageEvent) Chat() (*tg.Chat, bool)

Chat returns Chat object and true if message got from chat. False and nil otherwise.

func (MessageEvent) Logger

func (e MessageEvent) Logger() *zap.Logger

Logger returns associated lg.

func (MessageEvent) MessageFrom

func (e MessageEvent) MessageFrom() (u *tg.User, _ bool)

MessageFrom returns user whom send the messag and true, if `from` field was present in event.

func (MessageEvent) RPC

func (e MessageEvent) RPC() *tg.Client

RPC returns Telegram RPC client.

func (MessageEvent) Reply

func (e MessageEvent) Reply() *message.Builder

Reply creates new message builder to reply.

func (MessageEvent) Sender

func (e MessageEvent) Sender() *message.Sender

Sender returns *message.Sender

func (MessageEvent) TypingAction

func (e MessageEvent) TypingAction() *message.TypingActionBuilder

func (MessageEvent) User

func (e MessageEvent) User() (*tg.User, bool)

User returns User object and true if message got from user. False and nil otherwise.

func (MessageEvent) WithReply

func (e MessageEvent) WithReply(ctx context.Context, cb func(reply *tg.Message) error) error

WithReply calls given callback if current message event is a reply message.

type MessageHandler

type MessageHandler interface {
	OnMessage(ctx context.Context, e MessageEvent) error
}

MessageHandler is a simple message event handler.

type MessageHandlerFunc

type MessageHandlerFunc func(ctx context.Context, e MessageEvent) error

MessageHandlerFunc is a functional adapter for Handler.

func (MessageHandlerFunc) OnMessage

func (h MessageHandlerFunc) OnMessage(ctx context.Context, e MessageEvent) error

OnMessage implements MessageHandler.

type MessageMux

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

MessageMux is message event router.

func NewMessageMux

func NewMessageMux() *MessageMux

NewMessageMux creates new MessageMux.

func (*MessageMux) Handle

func (m *MessageMux) Handle(prefix, description string, handler MessageHandler)

Handle adds given prefix and handler to the mux.

func (*MessageMux) HandleFunc

func (m *MessageMux) HandleFunc(prefix, description string, handler func(ctx context.Context, e MessageEvent) error)

HandleFunc adds given prefix and handler to the mux.

func (*MessageMux) OnMessage

func (m *MessageMux) OnMessage(ctx context.Context, e MessageEvent) error

OnMessage implements MessageHandler.

func (*MessageMux) RegisterCommands

func (m *MessageMux) RegisterCommands(ctx context.Context, raw *tg.Client) error

RegisterCommands registers all mux commands using https://core.telegram.org/method/bots.setBotCommands.

func (*MessageMux) SetFallback

func (m *MessageMux) SetFallback(h MessageHandler)

SetFallback sets fallback handler, if mux is unable to find a command handler.

func (*MessageMux) SetFallbackFunc

func (m *MessageMux) SetFallbackFunc(h func(ctx context.Context, e MessageEvent) error)

SetFallbackFunc sets fallback handler, if mux is unable to find a command handler.

func (*MessageMux) WithTracerProvider

func (m *MessageMux) WithTracerProvider(provider trace.TracerProvider) *MessageMux

Jump to

Keyboard shortcuts

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