readers

package
v1.21.1 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AskGenericMessageReplyWithValidation

func AskGenericMessageReplyWithValidation(ctx context.Context,
	conversation BotConversation,
	message tgbotapi.Chattable,
	bs buttons.ButtonSet,
	validator BotUpdateValidator,
	repeatOriginalOnIncorrect bool) (*tgbotapi.Update, bool, error)

AskGenericMessageReplyWithValidation continuously asks a user for reply until reply passes validation functor

func RequestUserContact

func RequestUserContact(ctx context.Context, conversation BotConversation, message string, buttonText string, messageOnIncorrect string, finalMessage string) (tgbotapi.Contact, bool, error)

RequestUserContact requests user to share it's contact.

Types

type BotConversation

type BotConversation interface {
	ChatID() int64         // get current chatID
	ConversationID() int64 // get conversation object ID

	GetUpdateFromUser(ctx context.Context) (*tgbotapi.Update, bool) // read update from a user (will hang until a user sends new mupdate, or conversation is closed)
	GetFile(fileID string) ([]byte, error)                          // get file from Telegram server
	GetFileInfo(fileID string) (tgbotapi.File, error)               // get file info from Telegram server

	NewPhotoShare(photoFileID string, caption string) tgbotapi.PhotoConfig                      // create a message with a Photo (should be uploaded to the telegram an caption)
	NewPhotoUpload(fileData []byte, caption string) tgbotapi.PhotoConfig                        // create a message with a Photo that uploads to the telegram an caption
	NewDocumentUpload(fileData []byte, caption string, filename string) tgbotapi.DocumentConfig // create a message with a Document that uploads to the telegram an caption
	NewMessage(text string) tgbotapi.MessageConfig                                              // Create a new Text message with HTML parsing
	NewMessagef(text string, args ...interface{}) tgbotapi.MessageConfig                        // Create a new Text message with HTML parsing from text and parameters

	SendGeneralMessage(msg tgbotapi.Chattable) (int, error)                         // send general message to a user. This method is not safe, so use it as less as possible
	SendGeneralMessageWithKeyboardRemoveOnExit(msg tgbotapi.Chattable) (int, error) // send general message and ask conversation object to remove reply markup from this message in case of cancel event. the remove will be applied only to the latest message
	SendText(text string) (int, error)                                              // send text with HTML parsing
	SendTextf(text string, args ...interface{}) (int, error)                        // send text and parameters with HTML parsing
	ReplyWithText(text string, messageID int) (int, error)                          // reply with text message to the existing message
	AnswerButton(callbackQueryID string) error                                      // record answer to an inline button press
	DeleteMessage(messageID int) error                                              // delete an existing message

	RemoveReplyMarkup(messageID int) error                                                                 // remove reply markup from the existing message
	EditReplyMarkup(messageID int, markup tgbotapi.InlineKeyboardMarkup) error                             // replace reply markup in the existing message
	EditMessageText(messageID int, text string) error                                                      // replace text in the existing message
	EditMessageTextAndInlineMarkup(messageID int, text string, markup tgbotapi.InlineKeyboardMarkup) error // replace both text and reply markup in the existing message

	GlobalKeyboard() interface{} // get global keybard for the conversation user
}

BotConversation implements interface for reading and writing messages from the bot side

type BotUpdateValidator

type BotUpdateValidator func(update *tgbotapi.Update) (bool, string)

BotUpdateValidator validates an update recieved from a user. If the update does not pass the criteria, the validator can return a string with the clarification

type CalendarMode

type CalendarMode int
const (
	YearMode CalendarMode = iota
	MonthMode
	DayMode
)

type InputTextValidation

type InputTextValidation func(text string) bool // predicat that accepts only valid strings

InputTextValidation is a type for function that validates messaged recieved from a user

type ListItem

type ListItem struct {
	Text string
	Data string
}

ListItem is a struct with wisible text and inner data

type UserImageAndDataReply

type UserImageAndDataReply struct {
	Exit  bool
	Data  string
	Image []tgbotapi.PhotoSize
}

UserImageAndDataReply contains image input from a user

func GetImage

func GetImage(ctx context.Context, conversation BotConversation, text string, navigation buttons.ButtonSet, textOnIncorrect string) (UserImageAndDataReply, error)

GetImage asks a user to send image

type UserIndexDataReply added in v0.16.4

type UserIndexDataReply struct {
	Index int
	Data  string
	Exit  bool
}

UserIndexDataReply contains information about selected index (-1 if nothing selected)

func SelectIndexFromList added in v0.16.4

func SelectIndexFromList(
	ctx context.Context,
	conversation BotConversation,
	text string,
	items []string,
	pageSize int,
	navigation buttons.ButtonSet,
	prevPageText string,
	nextPageText string,
	filterText string,
	removeFilterText string) (UserIndexDataReply, error)

SelectIndexFromList asks a user to select one item from the list of strings and returns selected index

type UserSelectedIndecesReply added in v0.17.1

type UserSelectedIndecesReply struct {
	Indeces []int
	Data    string
	Exit    bool
}

SelectItemFromList asks a user to select one or more items from the list of strings and returns indeces of selected items

func MultySelectIndecesFromList added in v0.17.1

func MultySelectIndecesFromList(
	ctx context.Context,
	conversation BotConversation,
	text string,
	items []string,
	selectedIndeces []int,
	pageSize int,
	selectedText string,
	removeSelectedText string,
	navigation buttons.ButtonSet,
	prevPageText string,
	nextPageText string,
	filterText string,
	removeFilterText string) (UserSelectedIndecesReply, error)

MultySelectIndecesFromList returns indeces of selected items from list.

type UserSelectedListReply

type UserSelectedListReply struct {
	Items []ListItem
	Data  string
	Exit  bool
}

UserSelectedListReply contains a list of user-selected items

func MultySelectItemFromList

func MultySelectItemFromList(
	ctx context.Context,
	conversation BotConversation,
	text string,
	items []ListItem,
	selectedItems []ListItem,
	pageSize int,
	selectedText string,
	removeSelectedText string,
	navigation buttons.ButtonSet,
	prevPageText string,
	nextPageText string,
	filterText string,
	removeFilterText string) (UserSelectedListReply, error)

MultySelectItemFromList asks a user to select several items from the list

type UserTextAndDataReply

type UserTextAndDataReply struct {
	MessageID       int
	CallbackQueryID string
	Text            string
	Data            string
	Exit            bool
}

UserTextAndDataReply handles simplified information from the update

func AskOnlyButtonReply

func AskOnlyButtonReply(ctx context.Context, conversation BotConversation, message tgbotapi.Chattable, bs buttons.ButtonSet, messageOnText string) (UserTextAndDataReply, error)

AskOnlyButtonReply sends message to a user and accepts only buttons

func AskReplyEmail

func AskReplyEmail(ctx context.Context, conversation BotConversation, message string, bs buttons.ButtonSet, messageOnIncorrectInput string) (UserTextAndDataReply, error)

AskReplyEmail asks user to enter a vaid email address

func AskTextMessageReplyWithValidation

func AskTextMessageReplyWithValidation(ctx context.Context,
	conversation BotConversation,
	message string, bs buttons.ButtonSet,
	validator InputTextValidation, messageOnIncorrect string) (UserTextAndDataReply, error)

AskTextMessageReplyWithValidation is a complex conversation that keep asking a question to user until they give information that pass the validation or press a button

func ParseUserTextAndDataReply

func ParseUserTextAndDataReply(update *tgbotapi.Update, exit bool) UserTextAndDataReply

ParseUserTextAndDataReply parses text message and button data from the user's input

func ParseUserTextDataAndErrorReply

func ParseUserTextDataAndErrorReply(update *tgbotapi.Update, exit bool, err error) (UserTextAndDataReply, error)

ParseUserTextDataAndErrorReply creates pair (UserTextAndDataReply, error) from triple (update *tgbotapi.Update, exit bool, err error)

func ReadRawTextAndDataResult

func ReadRawTextAndDataResult(ctx context.Context, conversation BotConversation) UserTextAndDataReply

ReadRawTextAndDataResult waits for an update fro a user, and parses the update to UserTextAndDataReply struct

func SelectItemFromList

func SelectItemFromList(
	ctx context.Context,
	conversation BotConversation,
	text string,
	items []ListItem,
	pageSize int,
	navigation buttons.ButtonSet,
	prevPageText string,
	nextPageText string,
	filterText string,
	removeFilterText string) (UserTextAndDataReply, error)

SelectItemFromList asks user to select an item from the list

type UserTimeAndDataReply

type UserTimeAndDataReply struct {
	MessageID       int
	CallbackQueryID string
	Time            time.Time
	Data            string
	Exit            bool
}

UserTimeAndDataReply handles user input a Time (or Date)

func AskReplyCalendarDate

func AskReplyCalendarDate(ctx context.Context, conversation BotConversation,
	text string,
	minDate time.Time,
	maxDate time.Time,
	currentDate time.Time,
	calendarMode CalendarMode,
	navigation buttons.ButtonSet,
	months [12]string,
	weekDays [7]string,
	prevPageText string,
	nextPageText string,
	location *time.Location) (UserTimeAndDataReply, error)

func AskReplyCalendarDateWithAvailability added in v0.16.3

func AskReplyCalendarDateWithAvailability(ctx context.Context, conversation BotConversation,
	text string,
	minDate time.Time,
	maxDate time.Time,
	currentDate time.Time,
	calendarMode CalendarMode,
	navigation buttons.ButtonSet,
	months [12]string,
	weekDays [7]string,
	prevPageText string,
	nextPageText string,
	isDateAvailable func(day time.Time) bool,
	location *time.Location) (UserTimeAndDataReply, error)

AskReplyCalendarDateWithAvailability asks a user to select date between minDate and maxDate in calendar widget

func AskReplyCalendarDateWithAvailableList added in v0.16.3

func AskReplyCalendarDateWithAvailableList(ctx context.Context, conversation BotConversation,
	text string,
	minDate time.Time,
	maxDate time.Time,
	currentDate time.Time,
	calendarMode CalendarMode,
	navigation buttons.ButtonSet,
	months [12]string,
	weekDays [7]string,
	prevPageText string,
	nextPageText string,
	availableDates []time.Time,
	location *time.Location) (UserTimeAndDataReply, error)

func AskReplyCalendarDateWithUnavailableList added in v0.16.3

func AskReplyCalendarDateWithUnavailableList(ctx context.Context, conversation BotConversation,
	text string,
	minDate time.Time,
	maxDate time.Time,
	currentDate time.Time,
	calendarMode CalendarMode,
	navigation buttons.ButtonSet,
	months [12]string,
	weekDays [7]string,
	prevPageText string,
	nextPageText string,
	unavailableDates []time.Time,
	location *time.Location) (UserTimeAndDataReply, error)

func AskReplyDate

func AskReplyDate(ctx context.Context, conversation BotConversation, message string, bs buttons.ButtonSet, messageOnIncorrectInput string, location *time.Location) (UserTimeAndDataReply, error)

AskReplyDate asks a user to enter date in format dd.mm.yyyy

Jump to

Keyboard shortcuts

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