botkit

package module
v0.0.0-...-1586b62 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RetryQuery = &Query{Kind: RetryQueryKind}

Functions

This section is empty.

Types

type Audio

type Audio struct {
	BaseMedia
	Duration  int
	Performer string
	Title     string
}

func NewAudio

func NewAudio(file MediaSource) *Audio

type BaseMedia

type BaseMedia struct {
	File    MediaSource
	Thumb   MediaSource
	Caption string
}

type Bot

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

func NewBot

func NewBot(token string, opts ...BotOption) (*Bot, error)

func (*Bot) Close

func (bot *Bot) Close() error

func (*Bot) DownloadFile

func (bot *Bot) DownloadFile(fileID string) (io.ReadCloser, error)

func (*Bot) GetChat

func (bot *Bot) GetChat(chatID int64) Chat

func (*Bot) Run

func (bot *Bot) Run()

type BotOption

type BotOption func(*BotOptions)

func WithAPIEndpoint

func WithAPIEndpoint(apiEndpoint string) BotOption

func WithCommand

func WithCommand(cmd string, callback any) BotOption

func WithDefaultMessageHandler

func WithDefaultMessageHandler(h func(context.Context, string) error) BotOption

func WithDialog

func WithDialog(name string, h DialogHandler) BotOption

func WithDialogTTL

func WithDialogTTL(ttl time.Duration) BotOption

func WithLogger

func WithLogger(logger *slog.Logger) BotOption

func WithOffset

func WithOffset(offset int) BotOption

func WithRedisDSN

func WithRedisDSN(redisDSN string) BotOption

func WithTimeout

func WithTimeout(timeout int) BotOption

type BotOptions

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

type Chat

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

func (Chat) GetCache

func (chat Chat) GetCache() (razcache.Cache, error)

func (Chat) GetID

func (chat Chat) GetID() int64

func (Chat) SendMedia

func (chat Chat) SendMedia(media ...Media) error

func (Chat) SendMessage

func (chat Chat) SendMessage(format string, args ...any) error

func (Chat) SendSticker

func (chat Chat) SendSticker(stickerSet string, num int) error

func (Chat) UploadFile

func (chat Chat) UploadFile(name string, r io.Reader) error

func (Chat) UploadFileFromURL

func (chat Chat) UploadFileFromURL(url string) error

type CommandResponse

type CommandResponse func(*Context) error

func ReplyMedia

func ReplyMedia(media ...Media) CommandResponse

func ReplySticker

func ReplySticker(stickerSet string, num int) CommandResponse

func SendMedia

func SendMedia(media ...Media) CommandResponse

func SendMessage

func SendMessage(format string, args ...any) CommandResponse

func SendReply

func SendReply(format string, args ...any) CommandResponse

func SendSticker

func SendSticker(stickerSet string, num int) CommandResponse

func StartDialog

func StartDialog(name string) CommandResponse

func UploadFile

func UploadFile(name string, r io.Reader) CommandResponse

func UploadFileFromURL

func UploadFileFromURL(url string) CommandResponse

type Context

type Context struct {
	context.Context
	// contains filtered or unexported fields
}

func (*Context) DownloadFile

func (ctx *Context) DownloadFile(fileID string) (io.ReadCloser, error)

func (*Context) GetChat

func (ctx *Context) GetChat() Chat

func (*Context) GetChatCache

func (ctx *Context) GetChatCache() (razcache.Cache, error)

func (*Context) GetChatID

func (ctx *Context) GetChatID() int64

func (*Context) GetTaggedUserCache

func (ctx *Context) GetTaggedUserCache(num int) (razcache.Cache, error)

func (*Context) GetTaggedUserCount

func (ctx *Context) GetTaggedUserCount() int

func (*Context) GetUserCache

func (ctx *Context) GetUserCache() (razcache.Cache, error)

func (*Context) ReplyMedia

func (ctx *Context) ReplyMedia(media ...Media) error

func (*Context) ReplySticker

func (ctx *Context) ReplySticker(stickerSet string, num int) error

func (*Context) SendMedia

func (ctx *Context) SendMedia(media ...Media) error

func (*Context) SendMessage

func (ctx *Context) SendMessage(format string, args ...any) error

func (*Context) SendReply

func (ctx *Context) SendReply(format string, args ...any) error

func (*Context) SendSticker

func (ctx *Context) SendSticker(stickerSet string, num int) error

func (*Context) StartDialog

func (ctx *Context) StartDialog(name string) error

func (*Context) UploadFile

func (ctx *Context) UploadFile(name string, r io.Reader) error

func (*Context) UploadFileFromURL

func (ctx *Context) UploadFileFromURL(url string) error

type Dialog

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

func (*Dialog) LastQuery

func (dlg *Dialog) LastQuery() *Query

func (*Dialog) LastQueryName

func (dlg *Dialog) LastQueryName() string

func (*Dialog) LastUserChoices

func (dlg *Dialog) LastUserChoices() ([]int, bool)

func (*Dialog) LastUserResponse

func (dlg *Dialog) LastUserResponse() (string, bool)

func (*Dialog) Query

func (dlg *Dialog) Query(queryName string) *Query

func (*Dialog) UserChoices

func (dlg *Dialog) UserChoices(queryName string) (results []int, ok bool)

func (*Dialog) UserResponse

func (dlg *Dialog) UserResponse(queryName string) (string, bool)

type DialogBuilder

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

func NewDialogBuilder

func NewDialogBuilder() *DialogBuilder

func (*DialogBuilder) AddFileInputQuery

func (db *DialogBuilder) AddFileInputQuery(text string, validator func(io.Reader) error) *DialogBuilder

func (*DialogBuilder) AddMultiChoiceQuery

func (db *DialogBuilder) AddMultiChoiceQuery(text string, validator func(choices []int) error, choices ...string) *DialogBuilder

func (*DialogBuilder) AddSingleChoiceQuery

func (db *DialogBuilder) AddSingleChoiceQuery(text string, validator func(choice int) error, choices ...string) *DialogBuilder

func (*DialogBuilder) AddTextInputQuery

func (db *DialogBuilder) AddTextInputQuery(text string, validator func(resp string) error) *DialogBuilder

func (*DialogBuilder) Build

func (db *DialogBuilder) Build() DialogHandler

func (*DialogBuilder) SetFinalizer

func (db *DialogBuilder) SetFinalizer(finalizer func(ctx *Context, responses []any)) *DialogBuilder

type DialogHandler

type DialogHandler func(*Context, *Dialog) *Query

type Media

type Media interface {
	// contains filtered or unexported methods
}

type MediaSource

type MediaSource interface {
	// contains filtered or unexported methods
}

func FileSource

func FileSource(name string, r io.Reader) MediaSource

func URLSource

func URLSource(url string) MediaSource

type Photo

type Photo struct {
	BaseMedia
}

func NewPhoto

func NewPhoto(file MediaSource) *Photo

type Query

type Query struct {
	Name      string    `json:"name"`
	Kind      QueryKind `json:"kind"`
	Text      string    `json:"text"`
	Choices   []string  `json:"choices,omitempty"`
	MessageID int       `json:"message_id,omitempty"`
}

func NewFileInputQuery

func NewFileInputQuery(name, text string) *Query

func NewMultiChoiceQuery

func NewMultiChoiceQuery(name, text string, choices ...string) *Query

func NewSingleChoiceQuery

func NewSingleChoiceQuery(name, text string, choices ...string) *Query

func NewTextInputQuery

func NewTextInputQuery(name, text string) *Query

type QueryKind

type QueryKind int
const (
	TextInputQueryKind QueryKind = iota
	SingleChoiceQueryKind
	MultiChoiceQueryKind
	FileInputQueryKind
	RetryQueryKind
)

func (QueryKind) HasChoiceResponse

func (qk QueryKind) HasChoiceResponse() bool

func (QueryKind) HasTextResponse

func (qk QueryKind) HasTextResponse() bool

type Video

type Video struct {
	BaseMedia
	Duration          int
	SupportsStreaming bool
}

func NewVideo

func NewVideo(file MediaSource) *Video

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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