telegoutil

package
v0.31.2 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2024 License: MIT Imports: 12 Imported by: 16

Documentation

Overview

Package telegoutil provides utility methods for Telego.

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

Utilities by files: * api.go - low-level API of Telego * 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 (
	LoginWidgetID        = "id"
	LoginWidgetFirstName = "first_name"
	LoginWidgetLastName  = "last_name"
	LoginWidgetUsername  = "username"
	LoginWidgetPhotoURL  = "photo_url"
	LoginWidgetAuthDate  = "auth_date"
	LoginWidgetHash      = "hash"
)

Login widget 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 telego.ChatID, animation telego.InputFile) *telego.SendAnimationParams

Animation creates telego.SendAnimationParams with required parameters

func Audio

Audio creates telego.SendAudioParams with required parameters

func CallbackQuery

func CallbackQuery(queryID string) *telego.AnswerCallbackQueryParams

CallbackQuery creates telego.AnswerCallbackQueryParams with required parameters

func ChatAction

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

ChatAction creates telego.SendChatActionParams with required parameters

func Contact

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

Contact creates telego.SendContactParams with required parameters

func ContactMessage

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

ContactMessage creates telego.InputContactMessageContent with required fields

func CopyMessage

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

CopyMessage creates telego.CopyMessageParams with required parameters

func Delete

func Delete(id telego.ChatID, messageID int) *telego.DeleteMessageParams

Delete creates telego.DeleteMessageParams with required parameters

func Dice

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

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

func Document

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

Document creates telego.SendDocumentParams with required parameters

func DownloadFile

func DownloadFile(url string) ([]byte, error)

DownloadFile returns downloaded file bytes or error

func ErrorDataField

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

ErrorDataField creates telego.PassportElementErrorDataField with required fields

func ErrorFile

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

ErrorFile creates telego.PassportElementErrorFile with required fields

func ErrorFiles

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

ErrorFiles creates telego.PassportElementErrorFiles with required fields

func ErrorFrontSide

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

ErrorFrontSide creates telego.PassportElementErrorFrontSide with required fields

func ErrorReverseSide

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

ErrorReverseSide creates telego.PassportElementErrorReverseSide with required fields

func ErrorSelfie

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

ErrorSelfie creates telego.PassportElementErrorSelfie with required fields

func ErrorTranslationFile

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

ErrorTranslationFile creates telego.PassportElementErrorTranslationFile with required fields

func ErrorTranslationFiles

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

ErrorTranslationFiles creates telego.PassportElementErrorTranslationFiles with required fields

func ErrorUnspecified

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

ErrorUnspecified creates telego.PassportElementErrorUnspecified with required fields

func File

func File(file ta.NamedReader) telego.InputFile

File creates telego.InputFile from telegoapi.NamedReader

func FileFromID

func FileFromID(id string) telego.InputFile

FileFromID creates telego.InputFile from file ID

func FileFromURL

func FileFromURL(url string) telego.InputFile

FileFromURL creates telego.InputFile from URL

func ForceReply

func ForceReply() *telego.ForceReply

ForceReply creates telego.ForceReply with required fields

func Game

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

Game creates telego.SendGameParams with required parameters

func ID

func ID(id int64) telego.ChatID

ID creates telego.ChatID from user's identifier

func InlineKeyboard

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

InlineKeyboard creates telego.InlineKeyboardMarkup from slice of keyboard buttons rows

func InlineKeyboardButton

func InlineKeyboardButton(text string) telego.InlineKeyboardButton

InlineKeyboardButton creates telego.InlineKeyboardButton with required fields

func InlineKeyboardCols

func InlineKeyboardCols(cols int, buttons ...telego.InlineKeyboardButton) [][]telego.InlineKeyboardButton

InlineKeyboardCols creates a grid of buttons containing specified number of columns

func InlineKeyboardGrid

func InlineKeyboardGrid(buttons [][]telego.InlineKeyboardButton) *telego.InlineKeyboardMarkup

InlineKeyboardGrid creates a telego.InlineKeyboardMarkup from grid of buttons

func InlineKeyboardRow

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

InlineKeyboardRow creates a slice of telego.InlineKeyboardButton

func InlineKeyboardRows

func InlineKeyboardRows(rows int, buttons ...telego.InlineKeyboardButton) [][]telego.InlineKeyboardButton

InlineKeyboardRows creates a grid of buttons containing specified number of rows

func InlineQuery

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

InlineQuery creates telego.AnswerInlineQueryParams with required parameters

func Invoice

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

Invoice creates telego.SendInvoiceParams with required parameters

func InvoiceMessage

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

InvoiceMessage creates telego.InputInvoiceMessageContent with required fields

func Keyboard

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

Keyboard creates telego.ReplyKeyboardMarkup from slice of keyboard buttons

func KeyboardButton

func KeyboardButton(text string) telego.KeyboardButton

KeyboardButton creates telego.KeyboardButton with required fields

func KeyboardCols

func KeyboardCols(cols int, buttons ...telego.KeyboardButton) [][]telego.KeyboardButton

KeyboardCols creates a grid of buttons containing specified number of columns

func KeyboardGrid

func KeyboardGrid(buttons [][]telego.KeyboardButton) *telego.ReplyKeyboardMarkup

KeyboardGrid creates a telego.ReplyKeyboardMarkup from grid of buttons

func KeyboardRow

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

KeyboardRow creates a slice of telego.KeyboardButton

func KeyboardRows

func KeyboardRows(rows int, buttons ...telego.KeyboardButton) [][]telego.KeyboardButton

KeyboardRows creates a grid of buttons containing specified number of rows

func LabeledPrice

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

LabeledPrice creates telego.LabeledPrice with required parameters

func Location

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

Location creates telego.SendLocationParams with required parameters

func LocationMessage

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

LocationMessage creates telego.InputLocationMessageContent with required fields

func MediaAnimation

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

MediaAnimation creates telego.InputMediaAnimation with required fields

func MediaAudio

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

MediaAudio creates telego.InputMediaAudio with required fields

func MediaDocument

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

MediaDocument creates telego.InputMediaDocument with required fields

func MediaGroup

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

MediaGroup creates telego.SendMediaGroupParams with required parameters

func MediaPhoto

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

MediaPhoto creates telego.InputMediaPhoto with required fields

func MediaVideo

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

MediaVideo creates telego.InputMediaVideo with required fields

func Message

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

Message creates telego.SendMessageParams with required parameters

func MessageEntities

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

MessageEntities converts entity collections into the text and slice of telego.MessageEntity associated with text Note: Entity length is not trimmed as described in docs on purpose, Telegram still handles all entities perfectly fine, but trimming their length actually limits what can be sent

func MessageWithEntities

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

MessageWithEntities creates telego.SendMessageParams with required parameters and parsed entities

func Messagef

func Messagef(id telego.ChatID, format string, args ...any) *telego.SendMessageParams

Messagef creates telego.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 telegoapi.NamedReader

func ParseCommand

func ParseCommand(text string) (cmd string, username string, args []string)

ParseCommand returns command, bot username and its arguments if any

func ParseCommandPayload

func ParseCommandPayload(text string) (cmd string, username string, payload string)

ParseCommandPayload returns command, bot username and its payload if any

func Photo

Photo creates telego.SendPhotoParams with required parameters

func Poll

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

Poll creates telego.SendPollParams with required parameters

func PollOption

func PollOption(text string) telego.InputPollOption

PollOption creates telego.InputPollOption with required parameters

func PollTypeAny

func PollTypeAny() *telego.KeyboardButtonPollType

PollTypeAny creates telego.KeyboardButtonPollType with any type

func PollTypeQuiz

func PollTypeQuiz() *telego.KeyboardButtonPollType

PollTypeQuiz creates telego.KeyboardButtonPollType with type quiz

func PollTypeRegular

func PollTypeRegular() *telego.KeyboardButtonPollType

PollTypeRegular creates telego.KeyboardButtonPollType with type regular

func PreCheckoutQuery

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

PreCheckoutQuery creates telego.AnswerPreCheckoutQueryParams with required parameters

func ReplyKeyboardRemove

func ReplyKeyboardRemove() *telego.ReplyKeyboardRemove

ReplyKeyboardRemove creates telego.ReplyKeyboardRemove with required fields

func ResultArticle

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

ResultArticle creates telego.InlineQueryResultArticle with required fields

func ResultAudio

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

ResultAudio creates telego.InlineQueryResultAudio with required fields

func ResultCachedAudio

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

ResultCachedAudio creates telego.InlineQueryResultCachedAudio with required fields

func ResultCachedDocument

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

ResultCachedDocument creates telego.InlineQueryResultCachedDocument with required fields

func ResultCachedGif

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

ResultCachedGif creates telego.InlineQueryResultCachedGif with required fields

func ResultCachedMpeg4Gif

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

ResultCachedMpeg4Gif creates telego.InlineQueryResultCachedMpeg4Gif with required fields

func ResultCachedPhoto

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

ResultCachedPhoto creates telego.InlineQueryResultCachedPhoto with required fields

func ResultCachedSticker

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

ResultCachedSticker creates telego.InlineQueryResultCachedSticker with required fields

func ResultCachedVideo

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

ResultCachedVideo creates telego.InlineQueryResultCachedVideo with required fields

func ResultCachedVoice

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

ResultCachedVoice creates telego.InlineQueryResultCachedVoice with required fields

func ResultContact

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

ResultContact creates telego.InlineQueryResultContact with required fields

func ResultDocument

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

ResultDocument creates telego.InlineQueryResultDocument with required fields

func ResultGame

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

ResultGame creates telego.InlineQueryResultGame with required fields

func ResultGif

func ResultGif(id, gifURL, thumbnailURL string) *telego.InlineQueryResultGif

ResultGif creates telego.InlineQueryResultGif with required fields

func ResultLocation

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

ResultLocation creates telego.InlineQueryResultLocation with required fields

func ResultMpeg4Gif

func ResultMpeg4Gif(id, mpeg4URL, thumbnailURL string) *telego.InlineQueryResultMpeg4Gif

ResultMpeg4Gif creates telego.InlineQueryResultMpeg4Gif with required fields

func ResultPhoto

func ResultPhoto(id, photoURL, thumbnailURL string) *telego.InlineQueryResultPhoto

ResultPhoto creates telego.InlineQueryResultPhoto with required fields

func ResultVenue

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

ResultVenue creates telego.InlineQueryResultVenue with required fields

func ResultVideo

func ResultVideo(id, videoURL, mimeType, thumbnailURL, title string) *telego.InlineQueryResultVideo

ResultVideo creates telego.InlineQueryResultVideo with required fields

func ResultVoice

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

ResultVoice creates telego.InlineQueryResultVoice with required fields

func ScopeAllChatAdministrators

func ScopeAllChatAdministrators() *telego.BotCommandScopeAllChatAdministrators

ScopeAllChatAdministrators creates telego.BotCommandScopeAllChatAdministrators with required fields

func ScopeAllGroupChats

func ScopeAllGroupChats() *telego.BotCommandScopeAllGroupChats

ScopeAllGroupChats creates telego.BotCommandScopeAllGroupChats with required fields

func ScopeAllPrivateChats

func ScopeAllPrivateChats() *telego.BotCommandScopeAllPrivateChats

ScopeAllPrivateChats creates telego.BotCommandScopeAllPrivateChats with required fields

func ScopeChat

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

ScopeChat creates telego.BotCommandScopeChat with required fields

func ScopeChatAdministrators

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

ScopeChatAdministrators creates telego.BotCommandScopeChatAdministrators with required fields

func ScopeChatMember

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

ScopeChatMember creates telego.BotCommandScopeChatMember with required fields

func ScopeDefault

func ScopeDefault() *telego.BotCommandScopeDefault

ScopeDefault creates telego.BotCommandScopeDefault with required fields

func ShippingOption

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

ShippingOption creates telego.ShippingOption with required parameters

func ShippingQuery

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

ShippingQuery creates telego.AnswerShippingQueryParams with required parameters

func Sticker

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

Sticker creates telego.SendStickerParams with required parameters

func TextMessage

func TextMessage(messageText string) *telego.InputTextMessageContent

TextMessage creates telego.InputTextMessageContent with required fields

func UTF16TextLen

func UTF16TextLen(text string) int

UTF16TextLen returns length of a UTF-16 text Credit: https://core.telegram.org/api/entities#computing-entity-length

func UpdateProcessor

func UpdateProcessor(updates <-chan telego.Update, buffer uint, processor func(update telego.Update) telego.Update,
) <-chan telego.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, telego.Update.Clone method can panic, please read its comment.

func Username

func Username(username string) telego.ChatID

Username creates telego.ChatID from username

func ValidateLoginWidgetData

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

ValidateLoginWidgetData validates the integrity of value provided by Telegram Login Widget and returns url.Values containing all fields that were provided More info: https://core.telegram.org/widgets/login#checking-authorization

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 More info: https://core.telegram.org/bots/webapps#validating-data-received-via-the-mini-app

func Venue

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

Venue creates telego.SendVenueParams with required parameters

func VenueMessage

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

VenueMessage creates telego.InputVenueMessageContent with required fields

func Video

Video creates telego.SendVideoParams with required parameters

func VideoNote

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

VideoNote creates telego.SendVideoNoteParams with required parameters

func Voice

Voice creates telego.SendVoiceParams with required parameters

func WebAppInfo

func WebAppInfo(url string) *telego.WebAppInfo

WebAppInfo creates telego.WebAppInfo with required fields

func WebAppQuery

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

WebAppQuery creates telego.AnswerWebAppQueryParams with required parameters

func Webhook

func Webhook(url string) *telego.SetWebhookParams

Webhook creates telego.SetWebhookParams with required parameters

Types

type MessageEntityCollection

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

MessageEntityCollection represents text and slice of telego.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 ...any) MessageEntityCollection

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

func (MessageEntityCollection) Blockquote

Blockquote assigns blockquote entity and returns new collection

func (MessageEntityCollection) Bold

Bold assigns bold entity and returns a new collection

func (MessageEntityCollection) BotCommand

BotCommand assigns bot command entity and returns a new collection

func (MessageEntityCollection) Cashtag

Cashtag assigns cashtag entity and returns a new collection

func (MessageEntityCollection) Code

Code assigns code entity and returns new collection

func (MessageEntityCollection) CustomEmoji

CustomEmoji assigns custom emoji entity and returns a new collection

func (MessageEntityCollection) Email

Email assigns email entity and returns a new collection

func (MessageEntityCollection) Entities

Entities return message entities associated with a collection

func (MessageEntityCollection) ExpandableBlockquote

func (c MessageEntityCollection) ExpandableBlockquote() MessageEntityCollection

ExpandableBlockquote assigns expandable blockquote entity and returns new collection

func (MessageEntityCollection) Hashtag

Hashtag assigns hashtag entity and returns a new collection

func (MessageEntityCollection) Italic

Italic assigns italic entity and returns a new collection

func (MessageEntityCollection) Mention

Mention assigns mention entity and returns new collection

func (MessageEntityCollection) PhoneNumber

PhoneNumber assigns phone number entity and returns a new collection

func (MessageEntityCollection) Pre

Pre assigns pre entity with language and returns a 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 a new collection

func (MessageEntityCollection) Text

Text returns text associated with a collection

TextLink assigns text link entity with URL and returns a 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 a new collection

func (MessageEntityCollection) URL

URL assigns url entity and returns a 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