tbcomctl

package module
v4.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2022 License: MIT Imports: 19 Imported by: 0

README

===================================
Common Controls Library for Telebot
===================================

Library provides common controls to use with Telebot_ library.

Controls:

* Picklist - add inline keyboard to bots messages.
* Post Buttons - add buttons to your channel posts.
* Rating - rating buttons for channel posts.
* Keyboard - a convenient way to create a keyboard.
* Input - ask user for input and process the answer in OnText.

Abstractions:

* Form (combines other controls into a pipeline, see examples_)

Utilities:

* Subscription - check if user is subscribed to the channels of interest.
* Middleware - some helpful middleware functions.
* Helper functions for logging, etc.

Breaking Changes in V4
======================

Controls now operate on Interfaces defined in `interface.go` rather than functions.
There's a new convenience structure TVC which can be used to wrap the functions when updating to v4.

See examples_ for usage.

Installation
============

For Telebot_ v3::
  
  go get github.com/rusq/tbcomctl/v4

For Telebot_ v2::
  
  go get github.com/rusq/tbcomctl
  // or
  go get github.com/rusq/tbcomctl/v2

v2 is not actively developed, but you're more than welcome to submit your PRs.

Usage
=====
For usage - see examples_.



.. _Telebot: https://github.com/tucnak/telebot
.. _examples: examples

Documentation

Overview

Package tbcomctl provides common controls for telegram bots.

Index

Constants

View Source
const (
	MsgUnexpected  = "🤯 (500) Unexpected error occurred."
	MsgRetry       = "Incorrect choice."
	MsgChooseVal   = "Choose the value from the list:"
	MsgOK          = "✅"
	MsgVoteCounted = "✅ Vote counted."
	MsgSubCheck    = "? Check subscription >>"
	MsgSubNoSub    = "❌ You're not subscribed to one or more of the required channels."
)
View Source
const (
	// FallbackLang is the default fallback language.
	FallbackLang = "en-US"
)
View Source
const (
	None = "<none>"
)

Variables

View Source
var (
	// ErrRetry should be returned by CallbackFunc if the retry should be performed.
	ErrRetry = &Error{Type: TErrRetry, Msg: "retry", Alert: true}
	// ErrNoChange should be returned if the user picked the same value as before, and no update needed.
	ErrNoChange = &Error{Type: TErrNoChange, Msg: "no change"}
	// BackPressed is a special type of error indicating that callback handler should call the previous handler.
	BackPressed = errors.New("back") //lint:ignore ST1012 it is what it is
)
View Source
var ErrAlreadyVoted = errors.New("already voted")

Functions

func ButtonMarkup

func ButtonMarkup(c tb.Context, values []string, maxRowButtons int, cbFn func(c tb.Context) error) *tb.ReplyMarkup

ButtonMarkup returns the button markup for the message. It creates handlers for all the buttons assigning the cbFn callback function to each of them. Values must be unique. maxRowButtons is maximum number of buttons in a row.

func ButtonPatternMarkup

func ButtonPatternMarkup(c tb.Context, values []string, pattern []uint, cbFn tb.HandlerFunc) (*tb.ReplyMarkup, error)

func ChatInfo

func ChatInfo(ch *tb.Chat) string

ChatInfo returns the chat info.

func NewControllerChain deprecated

func NewControllerChain(first Controller, cc ...Controller) tb.HandlerFunc

NewControllerChain returns the controller chain.

Deprecated: use NewForm instead. NewControllerChain will be removed in the next versions.

func NewInputError

func NewInputError(msg string) error

NewInputError returns an input error with msg.

func NoDebugLogger

func NoDebugLogger()

NoDebugLogger switches off debug messages.

func NoLogging

func NoLogging()

NoLogging switches off default logging, if you're brave.

func Nvlstring

func Nvlstring(s string, ss ...string) string

Nvlstring returns the first non-empty string from the list.

func Printer

func Printer(lang string, fallback ...string) *message.Printer

Printer returns the Message Printer for the desired lang. If the lang is not valid, the fallback languages will be used, if set.

func PrinterContext

func PrinterContext(c tb.Context, fallback ...string) *message.Printer

PrinterContext returns the Message Printer set to the language of the sender. It is a convenience wrapper around Printer.

func PrivateOnly

func PrivateOnly(fn tb.HandlerFunc) tb.HandlerFunc

PrivateOnly is the middleware that restricts the handler to only private messages.

func PrivateOnlyMsg

func PrivateOnlyMsg(msg string, fn tb.HandlerFunc) tb.HandlerFunc

PrivateOnlyMsg returns the handler that will reject non-private messages (eg. sent in groups) with i18n formatted message.

func Sdump

func Sdump(m interface{}) string

Sdump dumps the structure.

func SenderInfo

func SenderInfo(c tb.Context) string

SenderInfo is the convenience function to log the sender info in the context.

func SetDebugLogger

func SetDebugLogger(l Logger)

SetDebugLogger sets the debug logger which is used to output debug messages, if you must. By default, debug logging is disabled.

func SetLogger

func SetLogger(l Logger)

SetLogger sets the current logger.

func Userinfo

func Userinfo(u *tb.User) string

Userinfo returns the user info.

func WithController

func WithController(ctx context.Context, ctrl Controller) context.Context

WithController adds the controller to the context.

Types

type BtnLabel

type BtnLabel string

type Button

type Button struct {
	Name  string `json:"n"`
	Value int    `json:"v"`
}

Button is the control button.

func (*Button) String

func (b *Button) String() string

type Callbacker

type Callbacker interface {
	// Callback should process the handler's callback.
	// TODO: describe supported error return values.
	Callback(ctx context.Context, c tb.Context) error
}

Callbacker defines the interface for the callback function.

type Controller

type Controller interface {
	// Handler is the controller's message handler.
	Handler(c tb.Context) error
	// Name returns the name of the control assigned to it on creation.  When
	// Controller is a part of a form, one can call Form.Controller(name) method
	// to get the controller.
	Name() string
	// SetNext sets the next handler, when control is part of a form.
	SetNext(Controller)
	// SetPrev sets the previous handler.
	SetPrev(Controller)
	// SetForm assigns the form to the controller, this will allow controller to
	// address other controls in a form by name.
	SetForm(*Form)
	// Form returns the form associated with the controller.
	Form() *Form
	// Value returns the value stored in the controller for the recipient.
	Value(recipient string) (string, bool)
	// OutgoingID should return the value of the outgoing message ID for the
	// user and true if the message is present or false otherwise.
	OutgoingID(recipient string) (int, bool)
}

Controller is the interface that some common controls implement. Controllers can be chained together. Controller is everything that can interact with user, i.e. a message that waits for the user input, or a picklist that presents the user with a set of buttons. Caller may want to create a custom controller to include in the form.

func ControllerFromCtx

func ControllerFromCtx(ctx context.Context) (Controller, bool)

ControllerFromCtx returns the controller from the context.

type ErrType

type ErrType int

ErrType is the type of error returned by the callback functions.

const (
	TErrNoChange ErrType = iota // there has been no change to the selection
	TErrRetry                   // error of this type will ask user to retry the selection or input
	TInputError                 // tell user that there was an input error (user-error)
)

type Error

type Error struct {
	Alert bool
	Msg   string
	Type  ErrType
}

Error is the type of error returned by the input-processing callback functions

func (*Error) Error

func (e *Error) Error() string

type ErrorHandler

type ErrorHandler interface {
	// OnError should process the error.
	OnError(ctx context.Context, c tb.Context, err error)
}

ErrorHandler is an optional interface for some controls, that the caller might implement so that errors occurred while handling the Callback could be handled by the caller as well.

type Form

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

Form is an abstraction that presents controllers in a way of a form. It can be viewed as an interactive form that user might fill in. Each of the controllers records the value that was entered, or selected, by the user. At any stage, caller may call the Data member function providing User ID as an argument, and that will return all the values in a mapping between the controller name and the user input that will contain all the values, entered by the user so far.

func NewForm

func NewForm(ctrls ...Controller) *Form

NewForm creates a new Form from a set of Controllers. The Controllers will be called in the same order they will appear in the argument list. Controllers must all have a unique name (within a form), otherwise NewForm will panic.

func (*Form) Controller

func (fm *Form) Controller(name string) (Controller, bool)

Controller returns the Form Controller by it's name.

func (*Form) Data

func (fm *Form) Data(r tb.Recipient) map[string]string

Data returns form data for the recipient.

func (*Form) Handler

func (fm *Form) Handler(c tb.Context) error

Handler is the form handler. It calls the handler of the first controller in the chain.

func (*Form) OnTextMiddleware

func (fm *Form) OnTextMiddleware(onText tb.HandlerFunc) tb.HandlerFunc

OnTextMiddleware returns the middleware for the OnText handler.

var f Form
tb.Handle(OnText, f.OnTextMiddleware(/*other handlers*/))

func (*Form) SetOverwrite

func (fm *Form) SetOverwrite(b bool) *Form

SetOverwrite sets the overwrite flag on all controllers within the form.

func (*Form) SetRemoveButtons

func (fm *Form) SetRemoveButtons(b bool) *Form

SetRemoveButtons sets the remove buttons flag on all controllers within the form.

func (*Form) Value

func (fm *Form) Value(ctrlName, recipient string) (string, bool)

Value returns the form control value for recipient by name

type HandleContextFunc

type HandleContextFunc func(ctx context.Context, c tb.Context) error

HandleContextFunc is the callback function that is being called within controller callbacks. It should return the errors specific to controller requirements for the input to be processed.

type Input

type Input struct {

	// UniqName is the unique name of the field (used to create pipelines, not
	// shown to the user)
	UniqName string
	// contains filtered or unexported fields
}

func NewInput

func NewInput(name string, tc TextCallbacker, opts ...InputOption) *Input

NewInput text creates a new text input, optionally chaining with the `next` handler. One must use Handle as a handler for bot endpoint, and then hook the OnText to OnTextMw. TextCallbacker.Text should produce the text that user initially sees, TextCallbacker.Callback is the function that should process the user input. It should return an InputError if the user input is not accepted, and in this case the user is offered to retry the input. It can format the return error with fmt.Errorf, as this is what will be presented to the user.

func NewInputText

func NewInputText(name string, text string, onTextFn HandleContextFunc, opts ...InputOption) *Input

NewIntputText is the shortcut to create the Input instance with static text. onTextFn should return InputError if the user input is not valid.

func (*Input) Form

func (cc *Input) Form() *Form

Form returns the form.

func (*Input) Handler

func (ip *Input) Handler(c tb.Context) error

func (*Input) Name

func (cc *Input) Name() string

Name returns the controller name.

func (*Input) OnTextMw

func (ip *Input) OnTextMw(fn tb.HandlerFunc) tb.HandlerFunc

OnTextMw returns the middleware that should wrap the OnText handler. It will process the message only if control awaits for this particular user input.

func (*Input) OutgoingID

func (cc *Input) OutgoingID(recipient string) (int, bool)

OutgoingID returns the controller's outgoing message ID for the user.

func (*Input) SetForm

func (cc *Input) SetForm(fm *Form)

SetForm links the controller to the form.

func (*Input) SetNext

func (cc *Input) SetNext(ctrl Controller)

SetNext sets next controller in the chain.

func (*Input) SetPrev

func (cc *Input) SetPrev(ctrl Controller)

SetPrev sets the previous controller in the chain.

func (*Input) SetValue

func (cc *Input) SetValue(recipient string, value string)

SetValue sets the Controller value.

func (*Input) Value

func (cc *Input) Value(recipient string) (string, bool)

Value returns the Controller value for the recipient.

type InputOption

type InputOption func(*Input)

func IOptNoReply

func IOptNoReply(b bool) InputOption

func IOptPrivateOnly

func IOptPrivateOnly(b bool) InputOption

func IOptValueResolver added in v4.0.1

func IOptValueResolver(fn ValueResolver) InputOption

type KbdOption

type KbdOption func(k *Keyboard)

func KbdOptButtonsInRow

func KbdOptButtonsInRow(n int) KbdOption

type Keyboard

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

func NewKeyboard

func NewKeyboard(cmds KeyboardCommands, opts ...KbdOption) *Keyboard

func (*Keyboard) Form

func (cc *Keyboard) Form() *Form

Form returns the form.

func (*Keyboard) InitForLanguages

func (k *Keyboard) InitForLanguages(b *tb.Bot, lang ...string)

InitForLanguages initialises handlers for languages listed.

func (*Keyboard) Markup

func (k *Keyboard) Markup(b *tb.Bot, lang string) *tb.ReplyMarkup

Markup returns the markup to be sent to user.

func (*Keyboard) Name

func (cc *Keyboard) Name() string

Name returns the controller name.

func (*Keyboard) OutgoingID

func (cc *Keyboard) OutgoingID(recipient string) (int, bool)

OutgoingID returns the controller's outgoing message ID for the user.

func (*Keyboard) SetForm

func (cc *Keyboard) SetForm(fm *Form)

SetForm links the controller to the form.

func (*Keyboard) SetNext

func (cc *Keyboard) SetNext(ctrl Controller)

SetNext sets next controller in the chain.

func (*Keyboard) SetPrev

func (cc *Keyboard) SetPrev(ctrl Controller)

SetPrev sets the previous controller in the chain.

func (*Keyboard) SetValue

func (cc *Keyboard) SetValue(recipient string, value string)

SetValue sets the Controller value.

func (*Keyboard) Value

func (cc *Keyboard) Value(recipient string) (string, bool)

Value returns the Controller value for the recipient.

type KeyboardCmd

type KeyboardCmd struct {
	Label   BtnLabel
	Handler tb.HandlerFunc
}

type KeyboardCommands

type KeyboardCommands []KeyboardCmd

type Logger

type Logger interface {
	Print(v ...interface{})
	Println(v ...interface{})
	Printf(format string, a ...interface{})
}

Logger is the interface for logging.

func GetLogger

func GetLogger() Logger

GetLogger returns current logger.

type Message

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

Message is the controller that sends a message. It can be used to send a confirmation message at the end of the Form.

func NewMessage

func NewMessage(name string, tx Texter, sendOpts ...interface{}) *Message

NewMessage creates new Message Controller. One must pass Bot instance, name of the controller, text function that returns the desired message and optionally any sendOpts that will be supplied to telebot.Bot.Send.

func NewMessageText

func NewMessageText(name, text string, sendOpts ...interface{}) *Message

NewMessageText is a convenience wrapper for NewMessage with a fixed text.

func (*Message) Form

func (cc *Message) Form() *Form

Form returns the form.

func (*Message) Handler

func (m *Message) Handler(c tb.Context) error

Handler is the Message controller's message handler.

func (*Message) Name

func (cc *Message) Name() string

Name returns the controller name.

func (*Message) OutgoingID

func (cc *Message) OutgoingID(recipient string) (int, bool)

OutgoingID returns the controller's outgoing message ID for the user.

func (*Message) SetForm

func (cc *Message) SetForm(fm *Form)

SetForm links the controller to the form.

func (*Message) SetNext

func (cc *Message) SetNext(ctrl Controller)

SetNext sets next controller in the chain.

func (*Message) SetPrev

func (cc *Message) SetPrev(ctrl Controller)

SetPrev sets the previous controller in the chain.

func (*Message) SetValue

func (cc *Message) SetValue(recipient string, value string)

SetValue sets the Controller value.

func (*Message) Value

func (cc *Message) Value(recipient string) (string, bool)

Value returns the Controller value for the recipient.

type PBOption

type PBOption func(*PostButtons)

func PBOptMaxButtons

func PBOptMaxButtons(n int) PBOption

type Picklist

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

func NewPicklist

func NewPicklist(name string, tvc TextValueCallbacker, opts ...PicklistOption) *Picklist

NewPicklist creates a new picklist.

func (*Picklist) Form

func (cc *Picklist) Form() *Form

Form returns the form.

func (*Picklist) Handler

func (p *Picklist) Handler(c tb.Context) error

Handler is a handler function to use with telebot.Handle.

func (*Picklist) Name

func (cc *Picklist) Name() string

Name returns the controller name.

func (*Picklist) OutgoingID

func (cc *Picklist) OutgoingID(recipient string) (int, bool)

OutgoingID returns the controller's outgoing message ID for the user.

func (*Picklist) SetForm

func (cc *Picklist) SetForm(fm *Form)

SetForm links the controller to the form.

func (Picklist) SetMaxButtons

func (b Picklist) SetMaxButtons(n int)

func (*Picklist) SetNext

func (cc *Picklist) SetNext(ctrl Controller)

SetNext sets next controller in the chain.

func (*Picklist) SetPrev

func (cc *Picklist) SetPrev(ctrl Controller)

SetPrev sets the previous controller in the chain.

func (*Picklist) SetValue

func (cc *Picklist) SetValue(recipient string, value string)

SetValue sets the Controller value.

func (*Picklist) Value

func (cc *Picklist) Value(recipient string) (string, bool)

Value returns the Controller value for the recipient.

type PicklistOption

type PicklistOption func(p *Picklist)

func PickOptBtnBack

func PickOptBtnBack(texter Texter) PicklistOption

func PickOptBtnPattern

func PickOptBtnPattern(pattern []uint) PicklistOption

PickOptBtnPattern sets the inline markup button pattern. Each unsigned integer in the pattern represents the number of buttons shown on each of the rows.

Example:

pattern: []uint{1, 2, 3}
will produce the following markup for the picklist choices

+-------------------+
| Picklist text     |
+-------------------+
|     button 1      |
+---------+---------+
| button 2| button 3|
+------+--+---+-----+
| btn4 | btn5 | btn6|
+------+------+-----+

func PickOptDefaultSendOptions

func PickOptDefaultSendOptions(opts *tb.SendOptions) PicklistOption

PickOptDefaultSendOptions allows to set the default send options

func PickOptErrHandler

func PickOptErrHandler(h ErrorHandler) PicklistOption

func PickOptFallbackLang

func PickOptFallbackLang(lang string) PicklistOption

func PickOptMaxInlineButtons

func PickOptMaxInlineButtons(n int) PicklistOption

func PickOptNoUpdate

func PickOptNoUpdate(b bool) PicklistOption

PickOptNoUpdate sets the No Update option. If No Update is set, the text is not updated once the user makes their choice.

func PickOptOverwrite

func PickOptOverwrite(b bool) PicklistOption

func PickOptPrivateOnly

func PickOptPrivateOnly(b bool) PicklistOption

func PickOptRemoveButtons

func PickOptRemoveButtons(b bool) PicklistOption

PickOptRemoveButtons set the Remove Buttons option. If Remove Buttons is set, the inline buttons will be removed once the user make the choice.

type PostButtons

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

func NewPostButtons

func NewPostButtons(callbackFn func(c tb.Context) error, opts ...PBOption) *PostButtons

NewPostButtons creates an instance of PostButtons. The callbackFunction is the function that will be assigned and called for each button press, so it should handle all possible values.

func (*PostButtons) Markup

func (pb *PostButtons) Markup(c tb.Context, labels []string, pattern ...uint) (*tb.ReplyMarkup, error)

Markup returns the markup with buttons labeled with labels.

func (PostButtons) SetMaxButtons

func (b PostButtons) SetMaxButtons(n int)

type RBOption

type RBOption func(*Rating)

func RBOptShowPostRating

func RBOptShowPostRating(b bool) RBOption

RBOptShowPostRating enables counter of total upvotes/downvotes.

func RBOptShowVoteCounter

func RBOptShowVoteCounter(b bool) RBOption

RBOptShowVoteCounter enables post rating between up/down vote buttons

type Rating

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

Rating is a struct for attaching post rating.

func NewRating

func NewRating(fn RatingFunc, opts ...RBOption) *Rating

func (*Rating) Form

func (cc *Rating) Form() *Form

Form returns the form.

func (*Rating) Markup

func (rb *Rating) Markup(b *tb.Bot, btns [2]Button) *tb.ReplyMarkup

func (*Rating) Name

func (cc *Rating) Name() string

Name returns the controller name.

func (*Rating) OutgoingID

func (cc *Rating) OutgoingID(recipient string) (int, bool)

OutgoingID returns the controller's outgoing message ID for the user.

func (*Rating) SetForm

func (cc *Rating) SetForm(fm *Form)

SetForm links the controller to the form.

func (*Rating) SetNext

func (cc *Rating) SetNext(ctrl Controller)

SetNext sets next controller in the chain.

func (*Rating) SetPrev

func (cc *Rating) SetPrev(ctrl Controller)

SetPrev sets the previous controller in the chain.

func (*Rating) SetValue

func (cc *Rating) SetValue(recipient string, value string)

SetValue sets the Controller value.

func (*Rating) Value

func (cc *Rating) Value(recipient string) (string, bool)

Value returns the Controller value for the recipient.

type RatingFunc

type RatingFunc func(tb.Editable, *tb.User, int) ([2]Button, error)

RatingFunc is the function called by callback, given the message, user and the button index it should update the records and return the new buttons with updated values for the posting, it must maintain count of votes inhouse.

type RatingType

type RatingType int

type SCOption

type SCOption func(sc *SubChecker)

func SCOptFallbackLang

func SCOptFallbackLang(lang string) SCOption

func SCOptShowList

func SCOptShowList(b bool) SCOption

type StoredMessage

type StoredMessage struct {
	MessageID string
	ChatID    int64
}

StoredMessage represents the stored message in the database.

func (StoredMessage) MessageSig

func (m StoredMessage) MessageSig() (string, int64)

type SubChecker

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

SubChecker is controller to check the chat subscription.

func NewSubChecker

func NewSubChecker(name string, t Texter, chats []int64, opts ...SCOption) *SubChecker

NewSubChecker creates new subscription checker that checks the subscription on the desired channels. Boter must be added to channels for this to work.

func (*SubChecker) Form

func (cc *SubChecker) Form() *Form

Form returns the form.

func (*SubChecker) Handler

func (sc *SubChecker) Handler(c tb.Context) error

func (*SubChecker) Name

func (cc *SubChecker) Name() string

Name returns the controller name.

func (*SubChecker) OutgoingID

func (cc *SubChecker) OutgoingID(recipient string) (int, bool)

OutgoingID returns the controller's outgoing message ID for the user.

func (*SubChecker) SetForm

func (cc *SubChecker) SetForm(fm *Form)

SetForm links the controller to the form.

func (*SubChecker) SetNext

func (cc *SubChecker) SetNext(ctrl Controller)

SetNext sets next controller in the chain.

func (*SubChecker) SetPrev

func (cc *SubChecker) SetPrev(ctrl Controller)

SetPrev sets the previous controller in the chain.

func (*SubChecker) SetValue

func (cc *SubChecker) SetValue(recipient string, value string)

SetValue sets the Controller value.

func (*SubChecker) Value

func (cc *SubChecker) Value(recipient string) (string, bool)

Value returns the Controller value for the recipient.

type TVC

type TVC struct {
	TextFn   func(context.Context, tb.Context) (string, error)
	ValuesFn func(context.Context, tb.Context) ([]string, error)
	CBfn     HandleContextFunc

	ErrorFn func(ctx context.Context, c tb.Context, err error)
}

TVC is an implementation of TextValuerCallbacker.

func NewStaticTVC

func NewStaticTVC(text string, values []string, callbackFn HandleContextFunc) *TVC

NewStaticTVC is a convenience constructor for TVC (TextValueCallbacker) with static text and values.

func (*TVC) Callback

func (t *TVC) Callback(ctx context.Context, c tb.Context) error

func (*TVC) OnError

func (t *TVC) OnError(ctx context.Context, c tb.Context, err error) error

func (*TVC) Text

func (t *TVC) Text(ctx context.Context, c tb.Context) (string, error)

Text callse the TextFn with contexts. ctx is legacy from the times when there was not telebot.Context.

func (*TVC) Values

func (t *TVC) Values(ctx context.Context, c tb.Context) ([]string, error)

func (*TVC) WithCallbackFn

func (t *TVC) WithCallbackFn(fn HandleContextFunc) *TVC

WithCallbackFn sets the callback function to fn.

func (*TVC) WithErrorFn

func (t *TVC) WithErrorFn(fn func(ctx context.Context, c tb.Context, err error)) *TVC

WithErrorFn sets the error handling function to fn.

func (*TVC) WithTextFn

func (t *TVC) WithTextFn(fn func(context.Context, tb.Context) (string, error)) *TVC

WithTextFn sets the text function to fn.

func (*TVC) WithValuesFn

func (t *TVC) WithValuesFn(fn func(context.Context, tb.Context) ([]string, error)) *TVC

WithValuesFn sets the value function to fn.

type TextCallbacker

type TextCallbacker interface {
	Texter
	Callbacker
}

TextCallbacker combines Texter and Callbacker interfaces.

type TextValueCallbacker

type TextValueCallbacker interface {
	Texter
	Valuer
	Callbacker
}

TextValueCallbacker combines Texter, Valuer and Callbacker interfaces.

type TextValuer

type TextValuer interface {
	Texter
	Valuer
}

TextValuer combines Texter and Valuer interfaces.

type Texter

type Texter interface {
	// Text should return the message that is presented to the user and an error.
	Text(ctx context.Context, c tb.Context) (string, error)
}

Texter is the interface that contains only the method to return the Message Text.

func NewTexter

func NewTexter(msg string) Texter

NewTexter wraps the msg returning a Texter.

type ValueResolver added in v4.0.1

type ValueResolver func(*tb.Message) (string, error)

type Valuer

type Valuer interface {
	// Values should return a list of strings to present as choices to the user and an error.
	// TODO describe supported error return values.
	Values(ctx context.Context, c tb.Context) ([]string, error)
}

Valuer is the interface

Directories

Path Synopsis
examples
internal

Jump to

Keyboard shortcuts

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