telegram

package
v0.14.3 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Private    = "private"
	Group      = "group"
	SuperGroup = "supergroup"
	Channel    = "channel"
)
View Source
const (
	Mention       = "mention"       //  “mention” (@username)
	Hashtag       = "hashtag"       //  “hashtag” (#hashtag)
	CashTag       = "cashtag"       //  “cashtag” ($USD)
	BotCommand    = "bot_command"   //  “bot_command” (/start@jobs_bot)
	URL           = "url"           //  “url” (https://telegram.org)
	Email         = "email"         //  “email” (do-not-reply@telegram.org)
	PhoneNumber   = "phone_number"  //  “phone_number” (+1-212-555-0123)
	Bold          = "bold"          //  “bold” (bold text)
	Italic        = "italic"        //  “italic” (italic text)
	Underline     = "underline"     //  “underline” (underlined text)
	Strikethrough = "strikethrough" //  “strikethrough” (strikethrough text)
	Code          = "code"          //  “code” (monowidth string)
	Pre           = "pre"           //  “pre” (monowidth block)
	TextLink      = "text_link"     //  “text_link” (for clickable text URLs)
	TextMention   = "text_mention"  //  “text_mention” (for users without usernames)
)

Variables

View Source
var ErrInvalidToken = errors.New("token is invalid")

Functions

This section is empty.

Types

type Animation added in v0.14.0

type Animation struct {
	FileID       string     `json:"file_id"`        // FileID is the identifier for this file, which can be used to download or reuse the file
	FileUniqueID string     `json:"file_unique_id"` // FileUniqueID is the unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file.
	Width        int        `json:"width"`          // Width video width as defined by sender
	Height       int        `json:"height"`         // Height video height as defined by sender
	Duration     int        `json:"duration"`       // Duration of the video in seconds as defined by sender
	Thumbnail    *PhotoSize `json:"thumb"`          // Thumbnail animation thumbnail as defined by sender
	FileName     string     `json:"file_name"`      // FileName original animation filename as defined by sender
	MimeType     string     `json:"mime_type"`      // MimeType of the file as defined by sender
	FileSize     int        `json:"file_size"`
}

Animation represents an animation file.

type Attachment added in v0.14.0

type Attachment struct {
	FileName string
	MimeType string
	FileSize int64
	Data     []byte
}

func (Attachment) GetMimeType added in v0.14.0

func (b Attachment) GetMimeType() string

type Audio added in v0.14.0

type Audio struct {
	FileID       string     `json:"file_id"`        // FileID is an identifier for this file, which can be used to download or reuse the file
	FileUniqueID string     `json:"file_unique_id"` // FileUniqueID is the unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file.
	Duration     int        `json:"duration"`       // Duration of the audio in seconds as defined by sender
	Performer    string     `json:"performer"`      // Performer of the audio as defined by sender or by audio tags
	Title        string     `json:"title"`          // Title of the audio as defined by sender or by audio tags
	FileName     string     `json:"file_name"`      // FileName is the original filename as defined by sender
	MimeType     string     `json:"mime_type"`      // MimeType of the file as defined by sender
	FileSize     int        `json:"file_size"`      // FileSize file size
	Thumbnail    *PhotoSize `json:"thumb"`          // Thumbnail is the album cover to which the music file belongs
}

Audio represents an audio file to be treated as music by the Telegram clients.

type Bot added in v0.13.2

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

func NewBotWithHandler added in v0.13.2

func NewBotWithHandler(h Handler) *Bot

NewBotWithHandler create a telegram bot with specified handler.

func (*Bot) AnswerCallbackQuery added in v0.13.2

func (b *Bot) AnswerCallbackQuery(ctx context.Context, callbackQueryID, text string) error

AnswerCallbackQuery make an answerCallbackQuery api request.

func (*Bot) EditMessage added in v0.13.2

func (b *Bot) EditMessage(ctx context.Context, chatID, messageID int, text string, inlineKeyboards [][]InlineKeyboardButton) (*Message, error)

EditMessage make an editMessageText api request.

func (*Bot) GetFile added in v0.13.2

func (b *Bot) GetFile(ctx context.Context, fileID string) (*File, error)

GetFile get download info of File by fileID from Telegram.

func (*Bot) GetUpdates added in v0.13.2

func (b *Bot) GetUpdates(ctx context.Context, offset int) ([]Update, error)

GetUpdates make a getUpdates api request.

func (*Bot) SendReplyMessage added in v0.13.2

func (b *Bot) SendReplyMessage(ctx context.Context, chatID, replyID int, text string) (*Message, error)

SendReplyMessage make a sendMessage api request.

func (*Bot) Start added in v0.13.2

func (b *Bot) Start(ctx context.Context)

Start start an infinity call of getUpdates from Telegram, call r.MessageHandle while get new message updates.

type CallbackQuery added in v0.13.2

type CallbackQuery struct {
	ID              string   `json:"id"`
	From            User     `json:"from"`
	Message         *Message `json:"message"`
	InlineMessageID string   `json:"inline_message_id"`
	ChatInstance    string   `json:"chat_instance"`
	Data            string   `json:"data"`
	GameShortName   string   `json:"game_short_name"`
}

type Chat

type Chat struct {
	ID        int      `json:"id"`
	Title     string   `json:"title"`      // Title for supergroups, channels and group chats
	Type      ChatType `json:"type"`       // Type of chat, can be either “private”, “group”, “supergroup” or “channel”
	FirstName string   `json:"first_name"` // FirstName of the other party in a private chat
	LastName  string   `json:"last_name"`  // LastName of the other party in a private chat
	UserName  string   `json:"username"`   // UserName for private chats, supergroups and channels if available
}

type ChatType added in v0.14.0

type ChatType string

type Document added in v0.14.0

type Document struct {
	FileID       string     `json:"file_id"`        // FileID is an identifier for this file, which can be used to download or reuse the file
	FileUniqueID string     `json:"file_unique_id"` // FileUniqueID is the unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file.
	Thumbnail    *PhotoSize `json:"thumb"`          // Thumbnail document thumbnail as defined by sender
	FileName     string     `json:"file_name"`      // FileName original filename as defined by sender
	MimeType     string     `json:"mime_type"`      // MimeType  of the file as defined by sender
	FileSize     int        `json:"file_size"`
}

Document represents a general file.

type File

type File struct {
	FileID       string `json:"file_id"`
	FileUniqueID string `json:"file_unique_id"`
	FileSize     int64  `json:"file_size"`
	FilePath     string `json:"file_path"`
}

type Handler

type Handler interface {
	BotToken(ctx context.Context) string
	MessageHandle(ctx context.Context, bot *Bot, message Message, attachments []Attachment) error
	CallbackQueryHandle(ctx context.Context, bot *Bot, callbackQuery CallbackQuery) error
}

type InlineKeyboardButton added in v0.13.2

type InlineKeyboardButton struct {
	Text         string `json:"text"`
	CallbackData string `json:"callback_data"`
}

type Message

type Message struct {
	MessageID            int             `json:"message_id"`              // MessageID is a unique message identifier inside this chat
	From                 User            `json:"from"`                    // From is a sender, empty for messages sent to channels;
	Date                 int             `json:"date"`                    // Date of the message was sent in Unix time
	Text                 *string         `json:"text"`                    // Text is for text messages, the actual UTF-8 text of the message, 0-4096 characters;
	Chat                 *Chat           `json:"chat"`                    // Chat is the conversation the message belongs to
	ForwardFromChat      *Chat           `json:"forward_from_chat"`       // ForwardFromChat for messages forwarded from channels, information about the original channel;
	ForwardFromMessageID int             `json:"forward_from_message_id"` // ForwardFromMessageID for messages forwarded from channels, identifier of the original message in the channel;
	MediaGroupID         *string         `json:"media_group_id"`          // MediaGroupID is the unique identifier of a media message group this message belongs to;
	Photo                []PhotoSize     `json:"photo"`                   // Photo message is a photo, available sizes of the photo;
	Caption              *string         `json:"caption"`                 // Caption for the animation, audio, document, photo, video or voice, 0-1024 characters;
	Entities             []MessageEntity `json:"entities"`                // Entities are for text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text;
	CaptionEntities      []MessageEntity `json:"caption_entities"`
	Document             *Document       `json:"document"`   // Document message is a general file, information about the file;
	Video                *Video          `json:"video"`      // Video message is a video, information about the video;
	VideoNote            *VideoNote      `json:"video_note"` // VideoNote message is a video note, information about the video message;
	Voice                *Voice          `json:"voice"`      // Voice message is a voice message, information about the file;
	Audio                *Audio          `json:"audio"`      // Audio message is an audio file, information about the file;
	Animation            *Animation      `json:"animation"`  // Animation message is an animation, information about the animation. For backward compatibility, when this field is set, the document field will also be set;
}

func (Message) GetMaxPhotoFileID

func (m Message) GetMaxPhotoFileID() string
func (m Message) GetMessageLink() string

func (Message) IsSupported added in v0.14.0

func (m Message) IsSupported() bool

type MessageEntity added in v0.14.0

type MessageEntity struct {
	Type     MessageEntityType `json:"type"`   // Type of the entity.
	Offset   int               `json:"offset"` // Offset in UTF-16 code units to the start of the entity
	Length   int               `json:"length"`
	URL      string            `json:"url"`      // URL for “text_link” only, url that will be opened after user taps on the text
	User     *User             `json:"user"`     // User for “text_mention” only, the mentioned user
	Language string            `json:"language"` // Language for “pre” only, the programming language of the entity text
}

MessageEntity represents one special entity in a text message.

type MessageEntityType added in v0.14.0

type MessageEntityType string

type PhotoSize

type PhotoSize struct {
	FileID       string `json:"file_id"`
	FileUniqueID string `json:"file_unique_id"`
	FileSize     int64  `json:"file_size"`
	Width        int    `json:"width"`
	Height       int    `json:"height"`
}

type Update

type Update struct {
	UpdateID      int            `json:"update_id"`
	Message       *Message       `json:"message"`
	CallbackQuery *CallbackQuery `json:"callback_query"`
}

type User

type User struct {
	ID int `json:"id"`
}

type Video added in v0.14.0

type Video struct {
	FileID       string     `json:"file_id"`        // FileID identifier for this file, which can be used to download or reuse
	FileUniqueID string     `json:"file_unique_id"` // FileUniqueID is the unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file.
	Width        int        `json:"width"`          // Width video width as defined by sender
	Height       int        `json:"height"`         // Height video height as defined by sender
	Duration     int        `json:"duration"`       // Duration of the video in seconds as defined by sender
	Thumbnail    *PhotoSize `json:"thumb"`          // Thumbnail video thumbnail
	FileName     string     `json:"file_name"`      // FileName is the original filename as defined by sender
	MimeType     string     `json:"mime_type"`      // MimeType of a file as defined by sender
	FileSize     int        `json:"file_size"`
}

Video represents a video file.

type VideoNote added in v0.14.0

type VideoNote struct {
	FileID       string     `json:"file_id"`         // FileID identifier for this file, which can be used to download or reuse the file
	FileUniqueID string     `json:"file_unique_id"`  // FileUniqueID is the unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file.
	Length       int        `json:"length"`          // Length video width and height (diameter of the video message) as defined by sender
	Duration     int        `json:"duration"`        // Duration of the video in seconds as defined by sender
	Thumbnail    *PhotoSize `json:"thumb,omitempty"` // Thumbnail video thumbnail
	FileSize     int        `json:"file_size"`
}

VideoNote object represents a video message.

type Voice added in v0.14.0

type Voice struct {
	FileID       string `json:"file_id"`        // FileID identifier for this file, which can be used to download or reuse the file
	FileUniqueID string `json:"file_unique_id"` // FileUniqueID is the unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file.
	Duration     int    `json:"duration"`       // Duration of the audio in seconds as defined by sender
	MimeType     string `json:"mime_type"`      // MimeType of the file as defined by sender
	FileSize     int    `json:"file_size"`
}

Voice represents a voice note.

Jump to

Keyboard shortcuts

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