message

package
v0.0.0-...-3581dc8 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

README

message package

This package contains core functionality for interacting with Telegram, managing updates and messages.

Handling updates

An Update is represent any input received. Normally only one of the field (not including the ID) will be populated with the infos received from Telegram. An UpdateType indicates what field is being populated ans is used on the robot package to specify to what update a command needs to reply on, in this context you can also use the sum operator '+' or the bitwise or operator '|' to include multiple types

Managing messages

Incoming and sent messages are represented as UpdateMessage wich are very similar to the Telegram representation but present some wrappers like Forward, Media and SystemNotification that holds a specific group of informations. Due to Telegram's limitation is only possible to edit a message sent by the bot itself (except for messages published in channels), but is still possible to delete any type of messages (sent in the last 24h). When editing a message, the edit will be synchronized, this means that if returned error is nil, the variable that is being used to edit a message will change accordingly. There is also the possibility to create a reference of the sent message thanks to the NewReference function. This struct is way lighter and is capable of both editing and deleting the associated message without the sync capability.

Outgoing messages are represented by different structs depending by the type of message that we are sending (Text for plain text messages, Photo for messages that contain picture, Sticker ...). Depending on the type of message you can use various methods like ClipInlineKeyboard to set some specific options. All messages implements the Any interface thanks to the Send method.

Echotron interoperability

Parr(B)ot and in particular this package makes an extensive use of the Echotron library. This means that sometimes user will need to deal with some echotron's data structure.

Normally the main logic of your bot when using Parr(B)ot is delegated to the package robot, but this package makes available functions that allows developer to use it without the need of other parrbot's packages but only using echotron (even though is still not recommended):

  • CastUpdate to allow conversion from an echotron.Update into an Update as is re-defined in this library
  • LoadAPI and to save the API TOKEN externally, this will make methods contained in this package like Send or the edits works.
  • API to retrieve the echotron.API it when needed.

Part of the Parr(B)ot framework.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func API

func API() echotron.API

API return the current api, useful for compatibility with not yet supported echotron functions calls

func LoadAPI

func LoadAPI(token string)

LoadAPI resets the api to a new value using given token. Keep in mind that both api and token will be already set douring robot.Start and if you don't want to use program's argument, you can use robot.Config.SetAPIToken intead. You are probably NOT going to need this function

func Log

func Log(chatID int64, any ...interface{})

Log is a useful function to show what values the data is carrying using JSON. Tips: Be careful to who you are sending the message or the end user could be a bit confused. If you are the developer use your own chatID

Types

type Animation

type Animation struct {
	File echotron.InputFile
	Opts *echotron.AnimationOptions
}

Animation message type

func (*Animation) ClipInlineKeyboard

func (message *Animation) ClipInlineKeyboard(kbd [][]echotron.InlineKeyboardButton) *Animation

ClipInlineKeyboard allows to quickly add or change an inline keyboard to the message Opts

func (*Animation) ClipKeyboard

func (message *Animation) ClipKeyboard(kbd echotron.ReplyKeyboardMarkup) *Animation

ClipKeyboard allows to quickly add or change the Opts.ReplyMarkup of the current message

func (*Animation) ForceReply

func (message *Animation) ForceReply(placeholder string, selective bool) *Animation

ForceReply allows to quickly force the user to reply to the current message when sent

func (Animation) Send

func (message Animation) Send(chatID int64) (res *UpdateMessage, err error)

Send the message to the specified user (by this method the stuct can be used a Any interface)

type Any

type Any interface {
	// Send the message to the specified user and return a pointer to the messa sent and an error
	Send(chatID int64) (*UpdateMessage, error)
}

Any rapresent any single message type with the exeption of MediaGroup

type Audio

type Audio struct {
	File echotron.InputFile
	Opts *echotron.AudioOptions
}

Audio message type

func (*Audio) ClipInlineKeyboard

func (message *Audio) ClipInlineKeyboard(kbd [][]echotron.InlineKeyboardButton) *Audio

ClipInlineKeyboard allows to quickly add or change an inline keyboard to the message Opts

func (*Audio) ClipKeyboard

func (message *Audio) ClipKeyboard(kbd echotron.ReplyKeyboardMarkup) *Audio

ClipKeyboard allows to quickly add or change the Opts.ReplyMarkup of the current message

func (*Audio) ForceReply

func (message *Audio) ForceReply(placeholder string, selective bool) *Audio

ForceReply allows to quickly force the user to reply to the current message when sent

func (Audio) Send

func (message Audio) Send(chatID int64) (res *UpdateMessage, err error)

Send the message to the specified user (by this method the stuct can be used a Any interface)

type CallbackQuery

type CallbackQuery struct {
	ID              string         `json:"id"`
	From            *echotron.User `json:"from"`
	Message         *UpdateMessage `json:"parrbot_message,omitempty"`
	InlineMessageID string         `json:"inline_message_id,omitempty"`
	ChatInstance    string         `json:"chat_instance,omitempty"`
	Data            string         `json:"data,omitempty"`
	GameShortName   string         `json:"game_short_name,omitempty"`
}

CallbackQuery is the Parr(b)ot rapresentation the echotron.CallbackQuery, the difference is that it have the custom *UpdateMessage instead of *echotron.Message type for Message field. CallbackQuery implements editable interface

func (CallbackQuery) Answer

func (callback CallbackQuery) Answer(opts *echotron.CallbackQueryOptions) error

Answer allows to reply to a given callback using given options

func (CallbackQuery) AnswerAlert

func (callback CallbackQuery) AnswerAlert(text string, cacheTime uint16) error

AnswerAlert allows to reply to a given callback with a _ notification. The notification may be cached client-side by final user for cacheTime seconds max: 3600s

func (CallbackQuery) AnswerToast

func (callback CallbackQuery) AnswerToast(text string, cacheTime uint16) error

AnswerToast allows to reply to a given callback with a _ notification. The notification may be cached client-side by final user for cacheTime seconds max: 3600s

func (CallbackQuery) Delete

func (callback CallbackQuery) Delete() error

Delete is a method that allows to delete the original message

func (CallbackQuery) EditCaption

func (callback CallbackQuery) EditCaption(opts *echotron.MessageCaptionOptions) error

EditCaption is a method that allows to edit the caption (and others options) ONLY for messages sent by the bot that contain media (like Photo or Document...)

func (CallbackQuery) EditInlineKeyboard

func (callback CallbackQuery) EditInlineKeyboard(keyboard [][]echotron.InlineKeyboardButton) error

EditInlineKeyboard is a method that allows to edit the InlineKeyboard ONLY for messages sent by the bot

func (CallbackQuery) EditLiveLocation

func (callback CallbackQuery) EditLiveLocation(latitude, longitude float64, opts *echotron.EditLocationOptions) error

EditLiveLocation is a method that allows to edit the Location (and others options) ONLY for messages sent by the bot that contain it (like Photo or Document...)

func (CallbackQuery) EditMedia

func (callback CallbackQuery) EditMedia(media echotron.InputMedia, opts *echotron.MessageReplyMarkup) error

EditMedia is a method that allows to edit the media (and others options) ONLY for messages sent by the bot that contain it

func (CallbackQuery) EditText

func (callback CallbackQuery) EditText(text string, opts *echotron.MessageTextOptions) error

EditText is a method that allows to edit the text (and others options) for textual messages (message.Text) sent by the bot

type Contact

type Contact struct {
	PhoneNumber, FirstName string
	Opts                   *echotron.ContactOptions
}

Contact message type

func (*Contact) ClipInlineKeyboard

func (message *Contact) ClipInlineKeyboard(kbd [][]echotron.InlineKeyboardButton) *Contact

ClipInlineKeyboard allows to quickly add or change an inline keyboard to the message Opts

func (*Contact) ClipKeyboard

func (message *Contact) ClipKeyboard(kbd echotron.ReplyKeyboardMarkup) *Contact

ClipKeyboard allows to quickly add or change the Opts.ReplyMarkup of the current message

func (*Contact) ForceReply

func (message *Contact) ForceReply(placeholder string, selective bool) *Contact

ForceReply allows to quickly force the user to reply to the current message when sent

func (Contact) Send

func (message Contact) Send(chatID int64) (res *UpdateMessage, err error)

Send the message to the specified user (by this method the stuct can be used a Any interface)

type Dice

type Dice struct {
	Emoji echotron.DiceEmoji
	Opts  *echotron.BaseOptions
}

Dice message type

func (*Dice) ClipInlineKeyboard

func (message *Dice) ClipInlineKeyboard(kbd [][]echotron.InlineKeyboardButton) *Dice

ClipInlineKeyboard allows to quickly add or change an inline keyboard to the message Opts

func (*Dice) ClipKeyboard

func (message *Dice) ClipKeyboard(kbd echotron.ReplyKeyboardMarkup) *Dice

ClipKeyboard allows to quickly add or change the Opts.ReplyMarkup of the current message

func (*Dice) ForceReply

func (message *Dice) ForceReply(placeholder string, selective bool) *Dice

ForceReply allows to quickly force the user to reply to the current message when sent

func (Dice) Send

func (message Dice) Send(chatID int64) (res *UpdateMessage, err error)

Send the message to the specified user (by this method the stuct can be used a Any interface)

type Document

type Document struct {
	File echotron.InputFile
	Opts *echotron.DocumentOptions
}

Document message type

func (*Document) ClipInlineKeyboard

func (message *Document) ClipInlineKeyboard(kbd [][]echotron.InlineKeyboardButton) *Document

ClipInlineKeyboard allows to quickly add or change an inline keyboard to the message Opts

func (*Document) ClipKeyboard

func (message *Document) ClipKeyboard(kbd echotron.ReplyKeyboardMarkup) *Document

ClipKeyboard allows to quickly add or change the Opts.ReplyMarkup of the current message

func (*Document) ForceReply

func (message *Document) ForceReply(placeholder string, selective bool) *Document

ForceReply allows to quickly force the user to reply to the current message when sent

func (Document) Send

func (message Document) Send(chatID int64) (res *UpdateMessage, err error)

Send the message to the specified user (by this method the stuct can be used a Any interface)

type EntityFilter

type EntityFilter func(entity echotron.MessageEntity) bool

EntityFilter is a function checks an entity, returning true if pass false otherwise

func FilterEntityByType

func FilterEntityByType(allowedTypes ...echotron.MessageEntityType) EntityFilter

FilterEntityByType generates an EntityFilter that will return true only if entity's type match at least one of the given ones

type FileID

type FileID string

FileID is the identifier of a sent or recived File of any kind

func GrabAnimationFileID

func GrabAnimationFileID(media *echotron.Animation) FileID

GrabAnimationFileID grabs the FileID from the given media

func GrabAudioFileID

func GrabAudioFileID(media *echotron.Audio) FileID

GrabAudioFileID grabs the FileID from the given media

func GrabDocumentFileID

func GrabDocumentFileID(media *echotron.Document) FileID

GrabDocumentFileID grabs the FileID from the given media

func GrabPhotoFileID

func GrabPhotoFileID(media *echotron.PhotoSize) FileID

GrabPhotoFileID grabs the FileID from the given media

func GrabStickerFileID

func GrabStickerFileID(media *echotron.Sticker) FileID

GrabStickerFileID grabs the FileID from the given media

func GrabVideoFileID

func GrabVideoFileID(media *echotron.Video) FileID

GrabVideoFileID grabs the FileID from the given media

func GrabVideoNoteFileID

func GrabVideoNoteFileID(media *echotron.VideoNote) FileID

GrabVideoNoteFileID grabs the FileID from the given media

func GrabVoiceFileID

func GrabVoiceFileID(media *echotron.Voice) FileID

GrabVoiceFileID grabs the FileID from the given media

func (FileID) FetchFile

func (id FileID) FetchFile() (content []byte, err error)

FetchFile fetch the file content from Telegram servers

func (FileID) RetrieveInfo

func (id FileID) RetrieveInfo() (file *echotron.File, err error)

RetrieveInfo retrieve the info of a particular file from Telegram servers

func (FileID) SaveFile

func (id FileID) SaveFile(directory string) (filePath string, content []byte, err error)

SaveFile downloads a file in the given directory at the same relative path specified by Telegram and returns the complete path where has been saved locally, it's content and error

type ForwardInfo

type ForwardInfo struct {
	From       *echotron.User `json:"forward_from,omitempty"`
	Chat       *echotron.Chat `json:"forward_from_chat,omitempty"`
	MessageID  int            `json:"forward_from_message_id,omitempty"`
	Signature  string         `json:"forward_signature,omitempty"`
	SenderName string         `json:"forward_sender_name,omitempty"`
	Date       int            `json:"forward_date,omitempty"`
	Automatic  bool           `json:"is_automatic_forward_date,omitempty"`
}

ForwardInfo countain all the infos of the original message that has been forwarded

type Game

type Game struct {
	GameShortName string
	Opts          *echotron.BaseOptions
}

Game message type

func (*Game) ClipInlineKeyboard

func (message *Game) ClipInlineKeyboard(kbd [][]echotron.InlineKeyboardButton) *Game

ClipInlineKeyboard allows to quickly add or change an inline keyboard to the message Opts

func (*Game) ClipKeyboard

func (message *Game) ClipKeyboard(kbd echotron.ReplyKeyboardMarkup) *Game

ClipKeyboard allows to quickly add or change the Opts.ReplyMarkup of the current message

func (*Game) ForceReply

func (message *Game) ForceReply(placeholder string, selective bool) *Game

ForceReply allows to quickly force the user to reply to the current message when sent

func (Game) Send

func (message Game) Send(chatID int64) (res *UpdateMessage, err error)

Send the message to the specified user (by this method the stuct can be used a Any interface)

type Location

type Location struct {
	Latitude, Longitude float64
	Opts                *echotron.LocationOptions
}

Location message type

func (*Location) ClipInlineKeyboard

func (message *Location) ClipInlineKeyboard(kbd [][]echotron.InlineKeyboardButton) *Location

ClipInlineKeyboard allows to quickly add or change an inline keyboard to the message Opts

func (*Location) ClipKeyboard

func (message *Location) ClipKeyboard(kbd echotron.ReplyKeyboardMarkup) *Location

ClipKeyboard allows to quickly add or change the Opts.ReplyMarkup of the current message

func (*Location) ForceReply

func (message *Location) ForceReply(placeholder string, selective bool) *Location

ForceReply allows to quickly force the user to reply to the current message when sent

func (Location) Send

func (message Location) Send(chatID int64) (res *UpdateMessage, err error)

Send the message to the specified user (by this method the stuct can be used a Any interface)

type MediaInfo

type MediaInfo struct {
	MediaGroupID    string                    `json:"media_group_id,omitempty"`
	Animation       *echotron.Animation       `json:"animation,omitempty"`
	Audio           *echotron.Audio           `json:"audio,omitempty"`
	Document        *echotron.Document        `json:"document,omitempty"`
	Photo           []*echotron.PhotoSize     `json:"photo,omitempty"`
	Sticker         *echotron.Sticker         `json:"sticker,omitempty"`
	Video           *echotron.Video           `json:"video,omitempty"`
	VideoNote       *echotron.VideoNote       `json:"video_note,omitempty"`
	Voice           *echotron.Voice           `json:"voice,omitempty"`
	Caption         string                    `json:"caption,omitempty"`
	CaptionEntities []*echotron.MessageEntity `json:"caption_entities,omitempty"`
	Contact         *echotron.Contact         `json:"contact,omitempty"`
	Dice            *echotron.Dice            `json:"dice,omitempty"`
	Game            *echotron.Game            `json:"game,omitempty"`
	Poll            *echotron.Poll            `json:"poll,omitempty"`
	Venue           *echotron.Venue           `json:"venue,omitempty"`
	Location        *echotron.Location        `json:"location,omitempty"`
}

MediaInfo countain all the infos about medias, Polls and so on contained into a message

func (MediaInfo) ExtractFileID

func (m MediaInfo) ExtractFileID() (id *FileID)

ExtractFileID try to extracts the FileID from the Info of a media

type Photo

type Photo struct {
	File echotron.InputFile
	Opts *echotron.PhotoOptions
}

Photo message type

func (*Photo) ClipInlineKeyboard

func (message *Photo) ClipInlineKeyboard(kbd [][]echotron.InlineKeyboardButton) *Photo

ClipInlineKeyboard allows to quickly add or change an inline keyboard to the message Opts

func (*Photo) ClipKeyboard

func (message *Photo) ClipKeyboard(kbd echotron.ReplyKeyboardMarkup) *Photo

ClipKeyboard allows to quickly add or change the Opts.ReplyMarkup of the current message

func (*Photo) ForceReply

func (message *Photo) ForceReply(placeholder string, selective bool) *Photo

ForceReply allows to quickly force the user to reply to the current message when sent

func (Photo) Send

func (message Photo) Send(chatID int64) (res *UpdateMessage, err error)

Send the message to the specified user (by this method the stuct can be used a Any interface)

type Poll

type Poll struct {
	Question string
	Options  []string
	Opts     *echotron.PollOptions
}

Poll message type

func (*Poll) ClipInlineKeyboard

func (message *Poll) ClipInlineKeyboard(kbd [][]echotron.InlineKeyboardButton) *Poll

ClipInlineKeyboard allows to quickly add or change an inline keyboard to the message Opts

func (*Poll) ClipKeyboard

func (message *Poll) ClipKeyboard(kbd echotron.ReplyKeyboardMarkup) *Poll

ClipKeyboard allows to quickly add or change the Opts.ReplyMarkup of the current message

func (*Poll) ForceReply

func (message *Poll) ForceReply(placeholder string, selective bool) *Poll

ForceReply allows to quickly force the user to reply to the current message when sent

func (Poll) Send

func (message Poll) Send(chatID int64) (res *UpdateMessage, err error)

Send the message to the specified user (by this method the stuct can be used a Any interface)

type Reference

type Reference struct {
	echotron.MessageIDOptions
	// contains filtered or unexported fields
}

Reference rapresent a reference to an existing message. You can use it to do the same actions (editing or deleting) but with a lighter structure that can used as a echotron.MessageIDOptions thanks to embedding

func NewReference

func NewReference(e editable) *Reference

NewReference creates a new Reference that is referencing the message contained inside an editable (UpdateMessage, CallbackQuery, Update, Reference)

func (Reference) ChatID

func (ref Reference) ChatID() int64

ChatID allows to get the ChatID in witch referenced message was sent

func (Reference) Delete

func (ref Reference) Delete() error

Delete the message that is being referenced

func (Reference) EditCaption

func (ref Reference) EditCaption(opts *echotron.MessageCaptionOptions) error

EditCaption allows to edit the caption (and other releated options) ONLY for referenced messages that contain media (like Photo or Document...)

func (Reference) EditInlineKeyboard

func (ref Reference) EditInlineKeyboard(keyboard [][]echotron.InlineKeyboardButton) error

EditInlineKeyboard allows to edit the inline keyboard of referenced messages

func (Reference) EditLiveLocation

func (ref Reference) EditLiveLocation(latitude, longitude float64, opts *echotron.EditLocationOptions) error

EditLiveLocation allows to edit the location (and other releated options) ONLY for referenced messages that contain it (like Photo or Document...)

func (Reference) EditMedia

func (ref Reference) EditMedia(media echotron.InputMedia, opts *echotron.MessageReplyMarkup) error

EditMedia allows to edit the media (and other releated options) ONLY for referenced messages that already contain it

func (Reference) EditText

func (ref Reference) EditText(text string, opts *echotron.MessageTextOptions) error

EditText allows to edit the text (and other releated options) of referenced textual messages

func (Reference) MessageID

func (ref Reference) MessageID() int

MessageID allows to get the messageID of the referenced message

type ResponseError

type ResponseError struct {
	From        string
	ErrorCode   int
	Description string
}

ResponseError is an error generated by a echotron / Telegram resonse

func (ResponseError) Error

func (err ResponseError) Error() string

Error returns a complete error description (by creating this method ResponseError is a error interface)

type Sticker

type Sticker struct {
	StickerID string
	Opts      *echotron.BaseOptions
}

Sticker message type

func (*Sticker) ClipInlineKeyboard

func (message *Sticker) ClipInlineKeyboard(kbd [][]echotron.InlineKeyboardButton) *Sticker

ClipInlineKeyboard allows to quickly add or change an inline keyboard to the message Opts

func (*Sticker) ClipKeyboard

func (message *Sticker) ClipKeyboard(kbd echotron.ReplyKeyboardMarkup) *Sticker

ClipKeyboard allows to quickly add or change the Opts.ReplyMarkup of the current message

func (*Sticker) ForceReply

func (message *Sticker) ForceReply(placeholder string, selective bool) *Sticker

ForceReply allows to quickly force the user to reply to the current message when sent

func (Sticker) Send

func (message Sticker) Send(chatID int64) (res *UpdateMessage, err error)

Send the message to the specified user (by this method the stuct can be used a Any interface)

type SystemNotificationInfo

type SystemNotificationInfo struct {
	NewChatMembers                []*echotron.User                        `json:"new_chat_members,omitempty"`
	LeftChatMember                *echotron.User                          `json:"left_chat_member,omitempty"`
	NewChatTitle                  string                                  `json:"new_chat_title,omitempty"`
	NewChatPhoto                  []*echotron.PhotoSize                   `json:"new_chat_photo,omitempty"`
	DeleteChatPhoto               bool                                    `json:"delete_chat_photo,omitempty"`
	GroupChatCreated              bool                                    `json:"group_chat_created,omitempty"`
	SupergroupChatCreated         bool                                    `json:"supergroup_chat_created,omitempty"`
	ChannelChatCreated            bool                                    `json:"channel_chat_created,omitempty"`
	MessageAutoDeleteTimerChanged *echotron.MessageAutoDeleteTimerChanged `json:"message_auto_delete_timer_changed,omitempty"`
	MigrateToChatID               int                                     `json:"migrate_to_chat_id,omitempty"`
	MigrateFromChatID             int                                     `json:"migrate_from_chat_id,omitempty"`
	ConnectedWebsite              string                                  `json:"connected_website,omitempty"`
	ProximityAlertTriggered       *echotron.ProximityAlertTriggered       `json:"proximity_alert_triggered,omitempty"`
	VideoChatScheduled            *echotron.VideoChatScheduled            `json:"video_chat_scheduled,omitempty"`
	VideoChatStarted              *echotron.VideoChatStarted              `json:"video_chat_started,omitempty"`
	VideoChatEnded                *echotron.VideoChatEnded                `json:"video_chat_ended,omitempty"`
	VideoChatParticipantsInvited  *echotron.VideoChatParticipantsInvited  `json:"video_chat_participants_invited,omitempty"`
	WebAppData                    *echotron.WebAppData                    `json:"web_app_data,omitempty"`
	PinnedMessage                 *UpdateMessage                          `json:"parrbot_pinned_message,omitempty"`
}

SystemNotificationInfo countain the infos of Telegram's generated message on particular events (part of UpdateMessage)

type Text

type Text struct {
	Text string
	Opts *echotron.MessageOptions
}

Text message type

func (*Text) ClipInlineKeyboard

func (message *Text) ClipInlineKeyboard(kbd [][]echotron.InlineKeyboardButton) *Text

ClipInlineKeyboard allows to quickly add or change an inline keyboard to the message Opts

func (*Text) ClipKeyboard

func (message *Text) ClipKeyboard(kbd echotron.ReplyKeyboardMarkup) *Text

ClipKeyboard allows to quickly add or change the Opts.ReplyMarkup of the current message

func (*Text) ForceReply

func (message *Text) ForceReply(placeholder string, selective bool) *Text

ForceReply allows to quickly force the user to reply to the current message when sent

func (Text) Send

func (message Text) Send(chatID int64) (res *UpdateMessage, err error)

Send the message to the specified user (by this method the stuct can be used a Any interface)

type Update

type Update struct {
	ID                 int                          `json:"update_id"`
	Message            *UpdateMessage               `json:"parrbot_message,omitempty"`
	EditedMessage      *UpdateMessage               `json:"parrbot_edited_message,omitempty"`
	ChannelPost        *UpdateMessage               `json:"parrbot_channel_post,omitempty"`
	EditedChannelPost  *UpdateMessage               `json:"parrbot_edited_channel_post,omitempty"`
	InlineQuery        *echotron.InlineQuery        `json:"inline_query,omitempty"`
	ChosenInlineResult *echotron.ChosenInlineResult `json:"chosen_inline_result,omitempty"`
	CallbackQuery      *CallbackQuery               `json:"parrbot_callback_query,omitempty"`
	ShippingQuery      *echotron.ShippingQuery      `json:"shipping_query,omitempty"`
	PreCheckoutQuery   *echotron.PreCheckoutQuery   `json:"pre_checkout_query,omitempty"`
	MyChatMember       *echotron.ChatMemberUpdated  `json:"my_chat_member,omitempty"`
	ChatMember         *echotron.ChatMemberUpdated  `json:"chat_member,omitempty"`
	ChatJoinRequest    *echotron.ChatJoinRequest    `json:"chat_join_request,omitempty"`
}

Update is the Parr(b)ot rapresentation the echotron.Update, the difference is that it have the custom UpdateMessage (declared on inside the "incoming.go" file of the same packages) instead of echotron.Message type. You can cast a echotron.Update to a Update using the CastUpdate function Update implements editable interface

func CastUpdate

func CastUpdate(original *echotron.Update) (update *Update)

CastUpdate transform an *echotron.Update into a *Update

func (Update) DeleteMessage

func (u Update) DeleteMessage() error

Deletes the original message contain in the update if present

func (Update) FromMessage

func (u Update) FromMessage() (msg *UpdateMessage)

FromMessage gets the original message contain in the update if present

type UpdateMessage

type UpdateMessage struct {
	// Normal Telegram / Echotron fields
	ID              int                            `json:"message_id"`
	From            *echotron.User                 `json:"from,omitempty"` // <nil> if channel
	SenderChat      *echotron.Chat                 `json:"sender_chat,omitempty"`
	Date            int                            `json:"date"`
	Chat            *echotron.Chat                 `json:"chat"`
	EditDate        int                            `json:"edit_date,omitempty"`
	AuthorSignature string                         `json:"author_signature,omitempty"`
	InlineKeyboard  *echotron.InlineKeyboardMarkup `json:"reply_markup,omitempty"` // it Changed the name: ReplyMarkup (too generic) -> InlineKeyboard
	ViaBot          *echotron.User                 `json:"via_bot,omitempty"`

	ReplyToMessage *UpdateMessage `json:"parrbot_reply_to_message,omitempty"`

	/* Custom wrappers of information about a specific incoming message type
	 * tips: Thanks to that if you want to check if a message for example
	 *       contains a media you can just check if message.Media != nil
	 */
	Forward            *ForwardInfo            `json:"parrbot_forward,omitempty"`
	Media              *MediaInfo              `json:"parrbot_media,omitempty"`
	SystemNotification *SystemNotificationInfo `json:"parrbot_system_notification,omitempty"`

	/* They countain normal text information or the onse of media caption
	 * when text is empty. Notice however how inside Media (of type *MediaInfo)
	 * there is still a capy of the media caption
	 */
	Text     string                    `json:"text,omitempty"`
	Entities []*echotron.MessageEntity `json:"entities,omitempty"`
}

UpdateMessage is the custom type for incoming or just sent message (of any type). It implements editable interface. Tips: Use the json- tags naming to refer to the official Telegram documentation available at: https://core.telegram.org/bots/api#message In the rare cases where the json string start with "parrbot_" then is not a copy-paste of the response

func (UpdateMessage) Delete

func (message UpdateMessage) Delete() error

Delete the given message on the original chat (given message will not sync)

func (*UpdateMessage) EditCaption

func (message *UpdateMessage) EditCaption(opts *echotron.MessageCaptionOptions) error

EditCaption is a method that allows to edit the caption (and others options) ONLY for messages sent by the bot that contain media (like Photo or Document...)

func (*UpdateMessage) EditInlineKeyboard

func (message *UpdateMessage) EditInlineKeyboard(keyboard [][]echotron.InlineKeyboardButton) error

EditInlineKeyboard is a method that allows to edit the InlineKeyboard ONLY for messages sent by the bot

func (*UpdateMessage) EditLiveLocation

func (message *UpdateMessage) EditLiveLocation(latitude, longitude float64, opts *echotron.EditLocationOptions) error

EditLiveLocation is a method that allows to edit the Location (and others options) ONLY for messages sent by the bot that contain it (like Photo or Document...)

func (*UpdateMessage) EditMedia

func (message *UpdateMessage) EditMedia(media echotron.InputMedia, opts *echotron.MessageReplyMarkup) error

EditMedia is a method that allows to edit the media (and others options) ONLY for messages sent by the bot that contain it

func (*UpdateMessage) EditText

func (message *UpdateMessage) EditText(text string, opts *echotron.MessageTextOptions) error

EditText is a method that allows to edit the text (and others options) for textual messages (message.Text) sent by the bot

func (UpdateMessage) ExtractEntities

func (message UpdateMessage) ExtractEntities(filter EntityFilter) (extracted []string)

ExtractEntities extracts the content of the Entities contained inside given message and filtered by given filter function

func (UpdateMessage) ExtractEntitiesOfType

func (message UpdateMessage) ExtractEntitiesOfType(allowedTypes ...echotron.MessageEntityType) []string

ExtractEntitiesOfType extracts the content of the Entities contained filtered by their type

type UpdateType

type UpdateType uint16

UpdateType represent a possible incoming Update types used on the "ReplyAt" Command inside the command list

const (
	MESSAGE              UpdateType = 1 << iota // 000000000001
	EDITED_MESSAGE                              // 000000000010
	CHANNEL_POST                                // 000000000100
	EDITED_CHANNEL_POST                         // 000000001000
	INLINE_QUERY                                // 000000010000
	CHOSEN_INLINE_RESULT                        // 000000100000
	CALLBACK_QUERY                              // 000001000000
	SHIPPING_QUERY                              // 000010000000
	PRE_CHECKOUT_QUERY                          // 000100000000
	MY_CHAT_MEMBER                              // 001000000000
	CHAT_MEMBER                                 // 010000000000
	CHAT_JOIN_REQUEST                           // 100000000000

	// ANY represents any possible UpdateType.
	ANY = (1 << iota) - 1 // 1111111111
)

These are all the possible types of Update. On the side the binary representation Each one can be used as a flag into the "ReplyAt" field of a Command on the command list. Tips: You can even sum them to specify that the command will be executed onreply at for example MESSAGE + CHANNEL_POST (normal written messages and channel posts. If you want all, you can use ANY

type Venue

type Venue struct {
	Latitude, Longitude float64
	Title, Address      string
	Opts                *echotron.VenueOptions
}

Venue message type

func (*Venue) ClipInlineKeyboard

func (message *Venue) ClipInlineKeyboard(kbd [][]echotron.InlineKeyboardButton) *Venue

ClipInlineKeyboard allows to quickly add or change an inline keyboard to the message Opts

func (*Venue) ClipKeyboard

func (message *Venue) ClipKeyboard(kbd echotron.ReplyKeyboardMarkup) *Venue

ClipKeyboard allows to quickly add or change the Opts.ReplyMarkup of the current message

func (*Venue) ForceReply

func (message *Venue) ForceReply(placeholder string, selective bool) *Venue

ForceReply allows to quickly force the user to reply to the current message when sent

func (Venue) Send

func (message Venue) Send(chatID int64) (res *UpdateMessage, err error)

Send the message to the specified user (by this method the stuct can be used a Any interface)

type Video

type Video struct {
	File echotron.InputFile
	Opts *echotron.VideoOptions
}

Video message type

func (*Video) ClipInlineKeyboard

func (message *Video) ClipInlineKeyboard(kbd [][]echotron.InlineKeyboardButton) *Video

ClipInlineKeyboard allows to quickly add or change an inline keyboard to the message Opts

func (*Video) ClipKeyboard

func (message *Video) ClipKeyboard(kbd echotron.ReplyKeyboardMarkup) *Video

ClipKeyboard allows to quickly add or change the Opts.ReplyMarkup of the current message

func (*Video) ForceReply

func (message *Video) ForceReply(placeholder string, selective bool) *Video

ForceReply allows to quickly force the user to reply to the current message when sent

func (Video) Send

func (message Video) Send(chatID int64) (res *UpdateMessage, err error)

Send the message to the specified user (by this method the stuct can be used a Any interface)

type VideoNote

type VideoNote struct {
	File echotron.InputFile
	Opts *echotron.VideoNoteOptions
}

VideoNote message type

func (*VideoNote) ClipInlineKeyboard

func (message *VideoNote) ClipInlineKeyboard(kbd [][]echotron.InlineKeyboardButton) *VideoNote

ClipInlineKeyboard allows to quickly add or change an inline keyboard to the message Opts

func (*VideoNote) ClipKeyboard

func (message *VideoNote) ClipKeyboard(kbd echotron.ReplyKeyboardMarkup) *VideoNote

ClipKeyboard allows to quickly add or change the Opts.ReplyMarkup of the current message

func (*VideoNote) ForceReply

func (message *VideoNote) ForceReply(placeholder string, selective bool) *VideoNote

ForceReply allows to quickly force the user to reply to the current message when sent

func (VideoNote) Send

func (message VideoNote) Send(chatID int64) (res *UpdateMessage, err error)

Send the message to the specified user (by this method the stuct can be used a Any interface)

type Voice

type Voice struct {
	File echotron.InputFile
	Opts *echotron.VoiceOptions
}

Voice message type

func (*Voice) ClipInlineKeyboard

func (message *Voice) ClipInlineKeyboard(kbd [][]echotron.InlineKeyboardButton) *Voice

ClipInlineKeyboard allows to quickly add or change an inline keyboard to the message Opts

func (*Voice) ClipKeyboard

func (message *Voice) ClipKeyboard(kbd echotron.ReplyKeyboardMarkup) *Voice

ClipKeyboard allows to quickly add or change the Opts.ReplyMarkup of the current message

func (*Voice) ForceReply

func (message *Voice) ForceReply(placeholder string, selective bool) *Voice

ForceReply allows to quickly force the user to reply to the current message when sent

func (Voice) Send

func (message Voice) Send(chatID int64) (res *UpdateMessage, err error)

Send the message to the specified user (by this method the stuct can be used a Any interface)

Jump to

Keyboard shortcuts

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