message.go 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package telegram
  2. import "fmt"
  3. type Message struct {
  4. MessageID int64 `json:"message_id"` // MessageID is a unique message identifier inside this chat
  5. From User `json:"from"` // From is a sender, empty for messages sent to channels;
  6. Date int `json:"date"` // Date of the message was sent in Unix time
  7. Text *string `json:"text"` // Text is for text messages, the actual UTF-8 text of the message, 0-4096 characters;
  8. Chat *Chat `json:"chat"` // Chat is the conversation the message belongs to
  9. ForwardFromChat *Chat `json:"forward_from_chat"` // ForwardFromChat for messages forwarded from channels, information about the original channel;
  10. ForwardFromMessageID int64 `json:"forward_from_message_id"` // ForwardFromMessageID for messages forwarded from channels, identifier of the original message in the channel;
  11. MediaGroupID *string `json:"media_group_id"` // MediaGroupID is the unique identifier of a media message group this message belongs to;
  12. Photo []PhotoSize `json:"photo"` // Photo message is a photo, available sizes of the photo;
  13. Caption *string `json:"caption"` // Caption for the animation, audio, document, photo, video or voice, 0-1024 characters;
  14. Entities []MessageEntity `json:"entities"` // Entities are for text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text;
  15. CaptionEntities []MessageEntity `json:"caption_entities"` // CaptionEntities are for messages with a caption, special entities like usernames, URLs, bot commands, etc. that appear in the caption;
  16. Document *Document `json:"document"` // Document message is a general file, information about the file;
  17. Video *Video `json:"video"` // Video message is a video, information about the video;
  18. VideoNote *VideoNote `json:"video_note"` // VideoNote message is a video note, information about the video message;
  19. Voice *Voice `json:"voice"` // Voice message is a voice message, information about the file;
  20. Audio *Audio `json:"audio"` // Audio message is an audio file, information about the file;
  21. 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;
  22. }
  23. func (m Message) GetMaxPhotoFileID() string {
  24. var fileSize int64
  25. var photoSize PhotoSize
  26. for _, p := range m.Photo {
  27. if p.FileSize > fileSize {
  28. photoSize = p
  29. }
  30. }
  31. return photoSize.FileID
  32. }
  33. func (m Message) GetMessageLink() string {
  34. if m.ForwardFromChat != nil && m.ForwardFromChat.Type == Channel {
  35. return fmt.Sprintf("https://t.me/%s/%d", m.ForwardFromChat.UserName, m.ForwardFromMessageID)
  36. }
  37. return ""
  38. }
  39. func (m Message) IsSupported() bool {
  40. return m.Text != nil || m.Caption != nil || m.Document != nil || m.Photo != nil || m.Video != nil ||
  41. m.Voice != nil || m.VideoNote != nil || m.Audio != nil || m.Animation != nil
  42. }