handlers

package
v1.15.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoCallbackMessage = errors.New("callback data doesn't have message id")
View Source
var ErrPrecheckoutQueryEmpty = errors.New("precheckout query is empty")
View Source
var ErrUpdateNotSupported = errors.New("update is not valid for this handler")
View Source
var ErrValidationFailed = fmt.Errorf("validation failed")

Functions

func ChatID

func ChatID(upd *telegram.Update) types.ChatID

func NewCallbackFilterFromSpec

func NewCallbackFilterFromSpec(s *spec.CallbackTrigger) (types.EventFilter, error)

func NewContextFilter

func NewContextFilter(base types.EventFilter, cp types.ContextProvider, val string) types.EventFilter

func NewMessageFilterFromSpec

func NewMessageFilterFromSpec(s *spec.MessageTrigger) (types.EventFilter, error)

Types

type CallbackFilter

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

CallbackFilter check update callback data.

func (*CallbackFilter) Check

func (h *CallbackFilter) Check(ctx context.Context, update *telegram.Update) (bool, error)

type CallbackReply

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

CallbackReply send callback message reply.

func NewCallbackReply

func NewCallbackReply(sp types.StateProvider, secrets types.Secrets, text string, alert bool) *CallbackReply

NewCallbackReply creates new callback reply handler.

func (*CallbackReply) Handle

func (h *CallbackReply) Handle(ctx context.Context, upd *telegram.Update,
	bot *telegram.BotAPI,
) error

type Check added in v1.10.0

type Check string

Check is a type for message validator checks.

const (
	CheckNotEmpty Check = "not_empty"
	CheckIsInt    Check = "is_int"
	CheckIsFloat  Check = "is_float"
	CheckIsBool   Check = "is_bool"
)

func ParseCheckString added in v1.10.0

func ParseCheckString(str string) (Check, error)

type ContextFilter

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

func (*ContextFilter) Check

func (h *ContextFilter) Check(ctx context.Context, update *telegram.Update) (bool, error)

type DeleteContextHandler

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

func NewContextDeleter

func NewContextDeleter(cp types.ContextProvider, val string, log zerolog.Logger) *DeleteContextHandler

func (*DeleteContextHandler) Handle

type InlineButton

type InlineButton struct {
	Text     string
	URL      string
	Callback string
}

type InlineKeyboard added in v1.1.0

type InlineKeyboard [][]InlineButton

type InvoiceConfig added in v1.2.0

type InvoiceConfig struct {
	Title       string
	Description string
	Payload     string
	Currency    string
	Prices      []InvoicePrice
}

type InvoicePrice added in v1.2.0

type InvoicePrice struct {
	Label  string
	Amount string
}

type MessageDelete added in v1.1.0

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

func NewMessageDelete added in v1.1.0

func NewMessageDelete(logger zerolog.Logger) *MessageDelete

func (*MessageDelete) Handle added in v1.1.0

func (d *MessageDelete) Handle(ctx context.Context, upd *telegram.Update, api *telegram.BotAPI) error

type MessageEdit added in v1.1.0

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

func NewMessageEdit added in v1.1.0

func NewMessageEdit(caption string, template Template, keyboard InlineKeyboard,
	sp types.StateProvider, secrets types.Secrets, logger zerolog.Logger,
) *MessageEdit

func (*MessageEdit) Handle added in v1.1.0

func (h *MessageEdit) Handle(ctx context.Context, upd *telegram.Update, api *telegram.BotAPI) error

type MessageFilter

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

MessageFilter checks update by message criteria.

func (*MessageFilter) Check

func (h *MessageFilter) Check(ctx context.Context, update *telegram.Update) (bool, error)

type MessageModifier

type MessageModifier func(*telegram.MessageConfig)

MessageModifier apply custom modifications to telegram message reply.

func MessageWithInlineKeyboard added in v1.1.0

func MessageWithInlineKeyboard(keyboard InlineKeyboard) MessageModifier

MessageWithInlineKeyboard creates new message modifier to add custom inline keyboard to message.

func MessageWithKeyboard

func MessageWithKeyboard(keyboard [][]string) MessageModifier

MessageWithKeyboard creates new message modifier to add custom keyboard to message.

func MessageWithParseMode

func MessageWithParseMode(mode string) MessageModifier

MessageWithParseMode creates new message modifier to set custom parse mode for message.

type MessageReply

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

MessageReply handler processes telegram updates and reply message to them.

func NewMessageReply

func NewMessageReply(
	bot *telegram.BotAPI,
	sp types.StateProvider, secrets types.Secrets,
	template Template, logger zerolog.Logger, modifiers ...MessageModifier,
) *MessageReply

NewMessageReply from repliers funcs.

func (*MessageReply) Call added in v1.7.0

func (h *MessageReply) Call(ctx context.Context, req api.Request) error

func (*MessageReply) Handle

func (h *MessageReply) Handle(ctx context.Context, upd *telegram.Update, _ *telegram.BotAPI) error

type PreCheckout added in v1.2.0

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

func NewPreCheckout added in v1.2.0

func NewPreCheckout(ok bool, err string, logger zerolog.Logger) *PreCheckout

func (*PreCheckout) Handle added in v1.2.0

func (h *PreCheckout) Handle(ctx context.Context, upd *telegram.Update, api *telegram.BotAPI) error

type ReplyDocument added in v1.3.0

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

ReplyDocument sends document file to chat.

func NewReplyDocument added in v1.3.0

func NewReplyDocument(key, name string, assets types.Assets,
	logger zerolog.Logger,
) *ReplyDocument

NewReplyDocument creates new ReplyDocument handler using file by key.

func (*ReplyDocument) Handle added in v1.3.0

func (h *ReplyDocument) Handle(ctx context.Context, upd *telegram.Update,
	api *telegram.BotAPI,
) error

type ReplyImage added in v1.1.0

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

ReplyImage sends image to chat.

func NewReplyImageFile added in v1.1.0

func NewReplyImageFile(key, name string, assets types.Assets,
	logger zerolog.Logger) *ReplyImage

NewReplyImageFile creates new ReplyImage handler using image from key.

func (*ReplyImage) Handle added in v1.1.0

func (h *ReplyImage) Handle(ctx context.Context, upd *telegram.Update,
	api *telegram.BotAPI) error

type SendInvoice added in v1.2.0

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

func NewSendInvoice added in v1.2.0

func NewSendInvoice(providers types.PaymentProviders, sp types.StateProvider, secrets types.Secrets,
	providerName string, config InvoiceConfig, logger zerolog.Logger,
) *SendInvoice

func (*SendInvoice) Handle added in v1.2.0

func (h *SendInvoice) Handle(ctx context.Context, upd *telegram.Update, api *telegram.BotAPI) error

type SetContextHandler

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

func NewContextSetter

func NewContextSetter(cp types.ContextProvider, value string, log zerolog.Logger) *SetContextHandler

func (*SetContextHandler) Handle

func (h *SetContextHandler) Handle(ctx context.Context, upd *telegram.Update, api *telegram.BotAPI) error

type StateHandler

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

func NewStateHandlerFromSpec

func NewStateHandlerFromSpec(provider types.StateProvider, s *spec.State, log zerolog.Logger) *StateHandler

func (*StateHandler) Handle

func (h *StateHandler) Handle(ctx context.Context, update *telegram.Update, _ *telegram.BotAPI) error

type Template added in v1.6.0

type Template interface {
	Format(ctx *templateContext) (string, error)
}

func NewDefaultTemplate added in v1.6.0

func NewDefaultTemplate(src string) (Template, error)

func NewGoTemplate added in v1.6.0

func NewGoTemplate(src string) (Template, error)

func NewNoTemplate added in v1.6.0

func NewNoTemplate(src string) (Template, error)

type Templater added in v1.6.0

type Templater func(string) (Template, error)

type Validator added in v1.10.0

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

Validator is a struct for message validation.

func NewValidator added in v1.10.0

func NewValidator(logger zerolog.Logger, errMessage string, checks ...Check) *Validator

NewValidator is a constructor for Validator. It accepts a list of checks to perform and an error message to send if validation fails.

func (*Validator) Handle added in v1.10.0

func (v *Validator) Handle(ctx context.Context, upd *telegram.Update, api *telegram.BotAPI) error

type Webhook

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

Webhook handler sends HTTP request to the specified URL.

func NewWebhook

func NewWebhook(url *url.URL, cli *http.Client,
	method string, headers map[string]string,
	data map[string]string, sp types.StateProvider,
	secrets types.Secrets, log zerolog.Logger,
) *Webhook

func (*Webhook) Handle

func (h *Webhook) Handle(ctx context.Context, upd *telegram.Update, _ *telegram.BotAPI) error

type WebhookPayload added in v1.3.0

type WebhookPayload struct {
	Data map[string]string `json:"data"`
	Meta struct {
		ChatID    int64     `json:"chat_id"`
		Timestamp time.Time `json:"timestamp"`
	} `json:"meta"`
}

Jump to

Keyboard shortcuts

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