telegram

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// default
	CmdStart = "/start"
	CmdStop  = "/stop"
	CmdHelp  = "/help"
	CmdAbout = "/about"

	// debug
	CmdID = "/id"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Bot

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

Bot represents the telegram bot

func NewBot

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

func NewBotWithTelegram

func NewBotWithTelegram(botState Cards, bot Telebot, botMetrics BotMetrics, opts ...BotOption) (*Bot, error)

func (*Bot) Run

func (b *Bot) Run(ctx context.Context) error

Run runs the but, starting all goroutines

type BotMetrics

type BotMetrics interface {
	IncTelegramCommands(cmd string)
	IncTelegramEventsIncoming(eventType string)
	IncTelegramEventsOutgoing(eventType string)
	RegisterHandler(path string, handler *http.ServeMux)
}

type BotOption

type BotOption func(b *Bot) error

BotOption passed to NewBot to change the default instance.

func WithAllowlist

func WithAllowlist(ids ...int) BotOption

func WithLogger

func WithLogger(l log.Logger) BotOption

WithLogger sets the logger for the Bot as an option.

func WithMetrics

func WithMetrics(m BotMetrics) BotOption

func WithRevision

func WithRevision(s string) BotOption

func WithStartTime

func WithStartTime(t time.Time) BotOption

type Cards

type Cards interface {
	ListCards(ctx context.Context, query string) ([]fabdb.Card, error)
	GetCard(ctx context.Context, identifier string) (fabdb.Card, error)
}

type Telebot

type Telebot interface {
	Start()
	Stop()
	Send(to telebot.Recipient, what interface{}, options ...interface{}) (*telebot.Message, error)
	Answer(query *telebot.Query, resp *telebot.QueryResponse) error
	Handle(endpoint interface{}, handler interface{})
}

Jump to

Keyboard shortcuts

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