utils

package
v0.0.0-...-6dcbb19 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package utils provides utility methods for TGO.

Those utility methods provides a convenient way of construction Telegram methods parameters and other types.

Utilities by files: * api.go - low-level API of TGO * methods.go - Telegram methods parameters * types.go - types used in methods parameters * handler.go - handler and predicate helpers

This package is designed to be self-contained, and other packages should not depend on utilities.

Index

Constants

View Source
const (
	WebAppQueryID      = "query_id"
	WebAppUser         = "user"
	WebAppReceiver     = "receiver"
	WebAppChat         = "chat"
	WebAppStartParam   = "start_param"
	WebAppCanSendAfter = "can_send_after"
	WebAppAuthDate     = "auth_date"
	WebAppHash         = "hash"
)

Web app data query names

View Source
const WebAppSecret = "WebAppData"

WebAppSecret represents secret used to hash web app data

Variables

This section is empty.

Functions

func Animation

func Animation(id tgo.ChatID, animation tgo.InputFile) *tgo.SendAnimationParams

Animation creates tgo.SendAnimationParams with required parameters

func Audio

func Audio(id tgo.ChatID, audio tgo.InputFile) *tgo.SendAudioParams

Audio creates tgo.SendAudioParams with required parameters

func CallbackQuery

func CallbackQuery(queryID string) *tgo.AnswerCallbackQueryParams

CallbackQuery creates tgo.AnswerCallbackQueryParams with required parameters

func ChatAction

func ChatAction(id tgo.ChatID, action string) *tgo.SendChatActionParams

ChatAction creates tgo.SendChatActionParams with required parameters

func Contact

func Contact(id tgo.ChatID, phoneNumber, firstName string) *tgo.SendContactParams

Contact creates tgo.SendContactParams with required parameters

func ContactMessage

func ContactMessage(phoneNumber, firstName string) *tgo.InputContactMessageContent

ContactMessage creates tgo.InputContactMessageContent with required fields

func CopyMessage

func CopyMessage(id, fromID tgo.ChatID, messageID int) *tgo.CopyMessageParams

CopyMessage creates tgo.CopyMessageParams with required parameters

func Dice

func Dice(id tgo.ChatID, emoji string) *tgo.SendDiceParams

Dice creates tgo.SendDiceParams with required parameters Note: Emoji isn't required, but most likely you would what to specify it, you can use tgo.EmojiDice or etc.

func Document

func Document(id tgo.ChatID, document tgo.InputFile) *tgo.SendDocumentParams

Document creates tgo.SendDocumentParams with required parameters

func ErrorDataField

func ErrorDataField(sourceType, message, fieldName, dataHash string) *tgo.PassportElementErrorDataField

ErrorDataField creates tgo.PassportElementErrorDataField with required fields

func ErrorFile

func ErrorFile(sourceType, message, fileHash string) *tgo.PassportElementErrorFile

ErrorFile creates tgo.PassportElementErrorFile with required fields

func ErrorFiles

func ErrorFiles(sourceType, message string, fileHashes ...string) *tgo.PassportElementErrorFiles

ErrorFiles creates tgo.PassportElementErrorFiles with required fields

func ErrorFrontSide

func ErrorFrontSide(sourceType, message, fileHash string) *tgo.PassportElementErrorFrontSide

ErrorFrontSide creates tgo.PassportElementErrorFrontSide with required fields

func ErrorReverseSide

func ErrorReverseSide(sourceType, message, fileHash string) *tgo.PassportElementErrorReverseSide

ErrorReverseSide creates tgo.PassportElementErrorReverseSide with required fields

func ErrorSelfie

func ErrorSelfie(sourceType, message, fileHash string) *tgo.PassportElementErrorSelfie

ErrorSelfie creates tgo.PassportElementErrorSelfie with required fields

func ErrorTranslationFile

func ErrorTranslationFile(sourceType, message, fileHash string) *tgo.PassportElementErrorTranslationFile

ErrorTranslationFile creates tgo.PassportElementErrorTranslationFile with required fields

func ErrorTranslationFiles

func ErrorTranslationFiles(sourceType, message string, fileHashes ...string,
) *tgo.PassportElementErrorTranslationFiles

ErrorTranslationFiles creates tgo.PassportElementErrorTranslationFiles with required fields

func ErrorUnspecified

func ErrorUnspecified(sourceType, message, elementHash string) *tgo.PassportElementErrorUnspecified

ErrorUnspecified creates tgo.PassportElementErrorUnspecified with required fields

func File

func File(file api.NamedReader) tgo.InputFile

File creates tgo.InputFile from api.NamedReader

func FileByID

func FileByID(id string) tgo.InputFile

FileByID creates tgo.InputFile from file ID

func FileByURL

func FileByURL(url string) tgo.InputFile

FileByURL creates tgo.InputFile from URL

func Game

func Game(id int64, gameShortName string) *tgo.SendGameParams

Game creates tgo.SendGameParams with required parameters

func ID

func ID(id int64) tgo.ChatID

ID creates tgo.ChatID from user's identifier

func InlineKeyboard

func InlineKeyboard(rows ...[]tgo.InlineKeyboardButton) *tgo.InlineKeyboardMarkup

InlineKeyboard creates tgo.InlineKeyboardMarkup from slice of keyboard buttons

func InlineKeyboardButton

func InlineKeyboardButton(text string) tgo.InlineKeyboardButton

InlineKeyboardButton creates tgo.InlineKeyboardButton with required fields

func InlineKeyboardRow

func InlineKeyboardRow(buttons ...tgo.InlineKeyboardButton) []tgo.InlineKeyboardButton

InlineKeyboardRow creates slice of tgo.InlineKeyboardButton

func InlineQuery

func InlineQuery(queryID string, results ...tgo.InlineQueryResult) *tgo.AnswerInlineQueryParams

InlineQuery creates tgo.AnswerInlineQueryParams with required parameters

func Invoice

func Invoice(id tgo.ChatID, title, description, payload, providerToken, currency string,
	prices ...tgo.LabeledPrice,
) *tgo.SendInvoiceParams

Invoice creates tgo.SendInvoiceParams with required parameters

func InvoiceMessage

func InvoiceMessage(title, description, payload, providerToken, currency string, prices ...tgo.LabeledPrice,
) *tgo.InputInvoiceMessageContent

InvoiceMessage creates tgo.InputInvoiceMessageContent with required fields

func Keyboard

func Keyboard(rows ...[]tgo.KeyboardButton) *tgo.ReplyKeyboardMarkup

Keyboard creates tgo.ReplyKeyboardMarkup from slice of keyboard buttons

func KeyboardButton

func KeyboardButton(text string) tgo.KeyboardButton

KeyboardButton creates tgo.KeyboardButton with required fields

func KeyboardRow

func KeyboardRow(buttons ...tgo.KeyboardButton) []tgo.KeyboardButton

KeyboardRow creates slice of tgo.KeyboardButton

func LabeledPrice

func LabeledPrice(label string, amount int) tgo.LabeledPrice

LabeledPrice creates tgo.LabeledPrice with required parameters

func Location

func Location(id tgo.ChatID, latitude, longitude float64) *tgo.SendLocationParams

Location creates tgo.SendLocationParams with required parameters

func LocationMessage

func LocationMessage(latitude, longitude float64) *tgo.InputLocationMessageContent

LocationMessage creates tgo.InputLocationMessageContent with required fields

func MediaAnimation

func MediaAnimation(media tgo.InputFile) *tgo.InputMediaAnimation

MediaAnimation creates tgo.InputMediaAnimation with required fields

func MediaAudio

func MediaAudio(media tgo.InputFile) *tgo.InputMediaAudio

MediaAudio creates tgo.InputMediaAudio with required fields

func MediaDocument

func MediaDocument(media tgo.InputFile) *tgo.InputMediaDocument

MediaDocument creates tgo.InputMediaDocument with required fields

func MediaGroup

func MediaGroup(id tgo.ChatID, mediaGroups ...tgo.InputMedia) *tgo.SendMediaGroupParams

MediaGroup creates tgo.SendMediaGroupParams with required parameters

func MediaPhoto

func MediaPhoto(media tgo.InputFile) *tgo.InputMediaPhoto

MediaPhoto creates tgo.InputMediaPhoto with required fields

func MediaVideo

func MediaVideo(media tgo.InputFile) *tgo.InputMediaVideo

MediaVideo creates tgo.InputMediaVideo with required fields

func Message

func Message(id tgo.ChatID, text string) *tgo.SendMessageParams

Message creates tgo.SendMessageParams with required parameters

func MessageEntities

func MessageEntities(entityCollections ...MessageEntityCollection) (string, []tgo.MessageEntity)

MessageEntities coverts entity collections into text and slice of tgo.MessageEntity associated with that text

func MessageWithEntities

func MessageWithEntities(id tgo.ChatID, entityCollections ...MessageEntityCollection) *tgo.SendMessageParams

MessageWithEntities creates tgo.SendMessageParams with required parameters and parsed entities

func Messagef

func Messagef(id tgo.ChatID, format string, args ...interface{}) *tgo.SendMessageParams

Messagef creates tgo.SendMessageParams with required parameters and provided format

func NameReader

func NameReader(reader io.Reader, name string) ta.NamedReader

NameReader "names" io.Reader and returns valid api.NamedReader

func ParseCommand

func ParseCommand(text string) (string, []string)

ParseCommand returns command and its arguments if any

func Photo

func Photo(id tgo.ChatID, photo tgo.InputFile) *tgo.SendPhotoParams

Photo creates tgo.SendPhotoParams with required parameters

func Poll

func Poll(id tgo.ChatID, question string, options ...string) *tgo.SendPollParams

Poll creates tgo.SendPollParams with required parameters

func PollTypeAny

func PollTypeAny() *tgo.KeyboardButtonPollType

PollTypeAny creates tgo.KeyboardButtonPollType with any type

func PollTypeQuiz

func PollTypeQuiz() *tgo.KeyboardButtonPollType

PollTypeQuiz creates tgo.KeyboardButtonPollType with type quiz

func PollTypeRegular

func PollTypeRegular() *tgo.KeyboardButtonPollType

PollTypeRegular creates tgo.KeyboardButtonPollType with type regular

func PreCheckoutQuery

func PreCheckoutQuery(queryID string, ok bool) *tgo.AnswerPreCheckoutQueryParams

PreCheckoutQuery creates tgo.AnswerPreCheckoutQueryParams with required parameters

func ResultArticle

func ResultArticle(id, title string, inputMessageContent tgo.InputMessageContent,
) *tgo.InlineQueryResultArticle

ResultArticle creates tgo.InlineQueryResultArticle with required fields

func ResultAudio

func ResultAudio(id, audioURL, title string) *tgo.InlineQueryResultAudio

ResultAudio creates tgo.InlineQueryResultAudio with required fields

func ResultCachedAudio

func ResultCachedAudio(id, audioFileID string) *tgo.InlineQueryResultCachedAudio

ResultCachedAudio creates tgo.InlineQueryResultCachedAudio with required fields

func ResultCachedDocument

func ResultCachedDocument(id, title, documentFileID string) *tgo.InlineQueryResultCachedDocument

ResultCachedDocument creates tgo.InlineQueryResultCachedDocument with required fields

func ResultCachedGif

func ResultCachedGif(id, gifFileID string) *tgo.InlineQueryResultCachedGif

ResultCachedGif creates tgo.InlineQueryResultCachedGif with required fields

func ResultCachedMpeg4Gif

func ResultCachedMpeg4Gif(id, mpeg4FileID string) *tgo.InlineQueryResultCachedMpeg4Gif

ResultCachedMpeg4Gif creates tgo.InlineQueryResultCachedMpeg4Gif with required fields

func ResultCachedPhoto

func ResultCachedPhoto(id, photoFileID string) *tgo.InlineQueryResultCachedPhoto

ResultCachedPhoto creates tgo.InlineQueryResultCachedPhoto with required fields

func ResultCachedSticker

func ResultCachedSticker(id, stickerFileID string) *tgo.InlineQueryResultCachedSticker

ResultCachedSticker creates tgo.InlineQueryResultCachedSticker with required fields

func ResultCachedVideo

func ResultCachedVideo(id, videoFileID, title string) *tgo.InlineQueryResultCachedVideo

ResultCachedVideo creates tgo.InlineQueryResultCachedVideo with required fields

func ResultCachedVoice

func ResultCachedVoice(id, voiceFileID, title string) *tgo.InlineQueryResultCachedVoice

ResultCachedVoice creates tgo.InlineQueryResultCachedVoice with required fields

func ResultContact

func ResultContact(id, phoneNumber, firstName string) *tgo.InlineQueryResultContact

ResultContact creates tgo.InlineQueryResultContact with required fields

func ResultDocument

func ResultDocument(id, title, documentURL, mimeType string) *tgo.InlineQueryResultDocument

ResultDocument creates tgo.InlineQueryResultDocument with required fields

func ResultGame

func ResultGame(id, gameShortName string) *tgo.InlineQueryResultGame

ResultGame creates tgo.InlineQueryResultGame with required fields

func ResultGif

func ResultGif(id, gifURL, thumbURL string) *tgo.InlineQueryResultGif

ResultGif creates tgo.InlineQueryResultGif with required fields

func ResultLocation

func ResultLocation(id string, latitude, longitude float64, title string) *tgo.InlineQueryResultLocation

ResultLocation creates tgo.InlineQueryResultLocation with required fields

func ResultMpeg4Gif

func ResultMpeg4Gif(id, mpeg4URL, thumbURL string) *tgo.InlineQueryResultMpeg4Gif

ResultMpeg4Gif creates tgo.InlineQueryResultMpeg4Gif with required fields

func ResultPhoto

func ResultPhoto(id, photoURL, thumbURL string) *tgo.InlineQueryResultPhoto

ResultPhoto creates tgo.InlineQueryResultPhoto with required fields

func ResultVenue

func ResultVenue(id string, latitude, longitude float64, title, address string,
) *tgo.InlineQueryResultVenue

ResultVenue creates tgo.InlineQueryResultVenue with required fields

func ResultVideo

func ResultVideo(id, videoURL, mimeType, thumbURL, title string) *tgo.InlineQueryResultVideo

ResultVideo creates tgo.InlineQueryResultVideo with required fields

func ResultVoice

func ResultVoice(id, voiceURL, title string) *tgo.InlineQueryResultVoice

ResultVoice creates tgo.InlineQueryResultVoice with required fields

func ScopeAllChatAdministrators

func ScopeAllChatAdministrators() *tgo.BotCommandScopeAllChatAdministrators

ScopeAllChatAdministrators creates tgo.BotCommandScopeAllChatAdministrators with required fields

func ScopeAllGroupChats

func ScopeAllGroupChats() *tgo.BotCommandScopeAllGroupChats

ScopeAllGroupChats creates tgo.BotCommandScopeAllGroupChats with required fields

func ScopeAllPrivateChats

func ScopeAllPrivateChats() *tgo.BotCommandScopeAllPrivateChats

ScopeAllPrivateChats creates tgo.BotCommandScopeAllPrivateChats with required fields

func ScopeChat

func ScopeChat(chatID tgo.ChatID) *tgo.BotCommandScopeChat

ScopeChat creates tgo.BotCommandScopeChat with required fields

func ScopeChatAdministrators

func ScopeChatAdministrators(chatID tgo.ChatID) *tgo.BotCommandScopeChatAdministrators

ScopeChatAdministrators creates tgo.BotCommandScopeChatAdministrators with required fields

func ScopeChatMember

func ScopeChatMember(chatID tgo.ChatID, userID int64) *tgo.BotCommandScopeChatMember

ScopeChatMember creates tgo.BotCommandScopeChatMember with required fields

func ScopeDefault

func ScopeDefault() *tgo.BotCommandScopeDefault

ScopeDefault creates tgo.BotCommandScopeDefault with required fields

func ShippingOption

func ShippingOption(id, title string, prices ...tgo.LabeledPrice) tgo.ShippingOption

ShippingOption creates tgo.ShippingOption with required parameters

func ShippingQuery

func ShippingQuery(queryID string, ok bool, options ...tgo.ShippingOption) *tgo.AnswerShippingQueryParams

ShippingQuery creates tgo.AnswerShippingQueryParams with required parameters

func Sticker

func Sticker(id tgo.ChatID, sticker tgo.InputFile) *tgo.SendStickerParams

Sticker creates tgo.SendStickerParams with required parameters

func TextMessage

func TextMessage(messageText string) *tgo.InputTextMessageContent

TextMessage creates tgo.InputTextMessageContent with required fields

func UpdateProcessor

func UpdateProcessor(updates <-chan tgo.Update, buffer uint, processor func(update tgo.Update) tgo.Update,
) <-chan tgo.Update

UpdateProcessor allows you to process updates and still use updates chan. New updates chan will be closed when the original chan is closed. Warning: Deep copy of update is passed, tgo.Update's Clone() method can panic, please read its comment.

func Username

func Username(username string) tgo.ChatID

Username creates tgo.ChatID from username

func ValidateWebAppData

func ValidateWebAppData(token string, data string) (url.Values, error)

ValidateWebAppData validates the integrity of value provided by `window.Telegram.WebApp.initData` from web app and returns url.Values containing all fields that were provided

func Venue

func Venue(id tgo.ChatID, latitude, longitude float64, title, address string) *tgo.SendVenueParams

Venue creates tgo.SendVenueParams with required parameters

func VenueMessage

func VenueMessage(latitude, longitude float64, title, address string) *tgo.InputVenueMessageContent

VenueMessage creates tgo.InputVenueMessageContent with required fields

func Video

func Video(id tgo.ChatID, video tgo.InputFile) *tgo.SendVideoParams

Video creates tgo.SendVideoParams with required parameters

func VideoNote

func VideoNote(id tgo.ChatID, videoNote tgo.InputFile) *tgo.SendVideoNoteParams

VideoNote creates tgo.SendVideoNoteParams with required parameters

func Voice

func Voice(id tgo.ChatID, voice tgo.InputFile) *tgo.SendVoiceParams

Voice creates tgo.SendVoiceParams with required parameters

func WebAppQuery

func WebAppQuery(queryID string, result tgo.InlineQueryResult) *tgo.AnswerWebAppQueryParams

WebAppQuery creates tgo.AnswerWebAppQueryParams with required parameters

Types

type MessageEntityCollection

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

MessageEntityCollection represents text and slice of tgo.MessageEntity associated with it

func Entity

func Entity(text string) MessageEntityCollection

Entity creates new MessageEntityCollection with provided text and no entities

func Entityf

func Entityf(format string, args ...interface{}) MessageEntityCollection

Entityf creates new MessageEntityCollection with the provided format and args and no entities

func (MessageEntityCollection) Bold

Bold assigns bold entity and returns new collection

func (MessageEntityCollection) BotCommand

BotCommand assigns bot command entity and returns new collection

func (MessageEntityCollection) Cashtag

Cashtag assigns cashtag entity and returns new collection

func (MessageEntityCollection) Code

Code assigns code entity and returns new collection

func (MessageEntityCollection) CustomEmoji

CustomEmoji assigns custom emoji entity and returns new collection

func (MessageEntityCollection) Email

Email assigns email entity and returns new collection

func (MessageEntityCollection) Entities

func (c MessageEntityCollection) Entities() []tgo.MessageEntity

Entities returns message entities associated with collection

func (MessageEntityCollection) Hashtag

Hashtag assigns hashtag entity and returns new collection

func (MessageEntityCollection) Italic

Italic assigns italic entity and returns new collection

func (MessageEntityCollection) Mention

Mention assigns mention entity and returns new collection

func (MessageEntityCollection) PhoneNumber

PhoneNumber assigns phone number entity and returns new collection

func (MessageEntityCollection) Pre

Pre assigns pre entity with language and returns new collection

func (MessageEntityCollection) SetOffset

func (c MessageEntityCollection) SetOffset(offset int)

SetOffset sets offset for all entities

func (MessageEntityCollection) Spoiler

Spoiler assigns spoiler entity and returns new collection

func (MessageEntityCollection) Strikethrough

Strikethrough assigns strikethrough entity and returns new collection

func (MessageEntityCollection) Text

Text returns text associated with collection

TextLink assigns text link entity with URL and returns new collection

func (MessageEntityCollection) TextMention

TextMention assigns text mention entity with user and returns new collection

func (MessageEntityCollection) TextMentionWithID

func (c MessageEntityCollection) TextMentionWithID(userID int64) MessageEntityCollection

TextMentionWithID assigns text mention entity with just user ID and returns new collection

func (MessageEntityCollection) URL

URL assigns url entity and returns new collection

func (MessageEntityCollection) Underline

Underline assigns underline entity and returns new collection

Jump to

Keyboard shortcuts

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