-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from roskee/update-message-entity
updated message entity with some additional fields. Urgent needs!!!
- Loading branch information
Showing
5 changed files
with
299 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
package entity | ||
|
||
// Chat represents a chat. | ||
type Chat struct { | ||
// ID is a unique identifier for this chat. | ||
// | ||
// It is a required field | ||
ID int64 `json:"id,omitempty"` | ||
// Type is the type of chat, can be either “private”, “group”, “supergroup” or “channel”. | ||
// | ||
// It is a required field | ||
Type string `json:"type,omitempty"` | ||
// Title is the title for groups, super-groups and channels. | ||
Title string `json:"title,omitempty"` | ||
// Username is the username, for private chats, supergroups and channels if available. | ||
Username string `json:"username,omitempty"` | ||
// FirstName is the first name of the other party in a private chat. | ||
FirstName string `json:"first_name,omitempty"` | ||
// LastName is the last name of the other party in a private chat. | ||
LastName string `json:"last_name,omitempty"` | ||
// IsForum is true, if the supergroup chat is a forum (has topics enabled). | ||
IsForum bool `json:"is_forum,omitempty"` | ||
// Photo is the chat photo. Returned only in GetChat. | ||
Photo *ChatPhoto `json:"photo,omitempty"` | ||
// ActiveUsernames is if non-empty, the list of all active chat usernames; | ||
// for private chats, supergroups and channels. | ||
// Returned only in GetChat. | ||
ActiveUsernames []string `json:"active_usernames,omitempty"` | ||
// EmojiStatusCustomEmojiID is the custom emoji identifier of emoji status of the | ||
// other party in a private chat. | ||
// Returned only in GetChat. | ||
EmojiStatusCustomEmojiID string `json:"emoji_status_custom_emoji_id,omitempty"` | ||
// Bio is the bio of the other party in a private chat. | ||
// Returned only in GetChat | ||
Bio string `json:"bio,omitempty"` | ||
// HasPrivateForwards is true, if privacy settings of the other party in the private chat | ||
// allows to use tg://user?id=<user_id> links only in chats with the user. | ||
// Returned only in GetChat. | ||
HasPrivateForwards bool `json:"has_private_forwards,omitempty"` | ||
// HasRestrictedVoiceAndVideoMessages is true, if the privacy settings of the other party | ||
// restrict sending voice and video note messages in the private chat. | ||
// Returned only in GetChat. | ||
HasRestrictedVoiceAndVideoMessages bool `json:"has_restricted_voice_and_video_messages,omitempty"` | ||
// JoinToSendMessages is true, if users need to join the supergroup before they can send messages. | ||
// Returned only in getChat. | ||
JoinToSendMessages bool `json:"join_to_send_messages,omitempty"` | ||
// JoinByRequest is true, if all users directly joining the supergroup need to be approved by | ||
// supergroup administrators. | ||
// Returned only in getChat. | ||
JoinByRequest bool `json:"join_by_request,omitempty"` | ||
// Description is the description, for groups, supergroups and channel chats. | ||
// Returned only in getChat. | ||
Description string `json:"description,omitempty"` | ||
// InviteLink is the primary invite link, for groups, supergroups and channel chats. | ||
// Returned only in getChat. | ||
InviteLink string `json:"invite_link,omitempty"` | ||
// PinnedMessage is the most recent pinned message (by sending date). | ||
// Returned only in getChat. | ||
PinnedMessage *Message `json:"pinned_message,omitempty"` | ||
// Permissions is the default chat member permissions, for groups and supergroups. | ||
// Returned only in getChat. | ||
Permissions *ChatPermissions `json:"permissions,omitempty"` | ||
// SlowModeDelay is for supergroups, the minimum allowed delay between consecutive | ||
// messages sent by each unpriviledged user; in seconds. | ||
// Returned only in GetChat. | ||
SlowModeDelay int64 `json:"slow_mode_delay,omitempty"` | ||
// MessageAutoDeleteTime is the time after which all messages sent | ||
// to the chat will be automatically deleted; in seconds. | ||
// Returned only in GetChat. | ||
MessageAutoDeleteTime int64 `json:"message_auto_delete_time,omitempty"` | ||
// HasProtectedContent is true, if messages from the chat can't be forwarded to other chats. | ||
// Returned only in GetChat. | ||
HasProtectedContent bool `json:"has_protected_content,omitempty"` | ||
// StickerSetName is, for supergroups, name of group sticker set. | ||
// Returned only in GetChat. | ||
StickerSetName string `json:"sticker_set_name,omitempty"` | ||
// CanSetStickerSet is true, if the bot can change the group sticker set. | ||
// Returned only in GetChat. | ||
CanSetStickerSet bool `json:"can_set_sticker_set"` | ||
// LinkedChatID is the unique identifier for the linked chat. | ||
// Returned only in GetChat. | ||
LinkedChatID string `json:"linked_chat_id"` | ||
// Location is, for supergroups, the location to which the supergroup is connected. | ||
// Returned only in GetChat. | ||
Location *ChatLocation `json:"location,omitempty"` | ||
} | ||
|
||
// ChatPhoto represents a chat photo. | ||
type ChatPhoto struct { | ||
// SmallFileID is the file identifier of small (160*160) chat photo. | ||
SmallFileID string `json:"small_file_id,omitempty"` | ||
// SmallFileUniqueID is the unique file identifier of small (160x160) chat photo, | ||
// which is supposed to be the same over time and for different bots. | ||
// Can't be used to download or reuse the file. | ||
SmallFileUniqueID string `json:"small_file_unique_id,omitempty"` | ||
// BigFileID is the file identifier of big (640x640) chat photo. | ||
BigFileID string `json:"big_file_id,omitempty"` | ||
// BigFileUniqueID is the unique file identifier of big (640x640) chat photo, | ||
// which is supposed to be the same over time and for different bots. | ||
// Can't be used to download or reuse the file. | ||
BigFileUniqueID string `json:"big_file_unique_id,omitempty"` | ||
} | ||
|
||
// ChatPermissions describes actions that a non-administrator user is allowed to take in a chat. | ||
type ChatPermissions struct { | ||
// CanSendMessages is true, if the user is allowed to send text messages, contacts, locations and venues. | ||
CanSendMessages bool `json:"can_send_messages,omitempty"` | ||
// CanSendMediaMessages is true, if the user is allowed to send audios, documents, photos, videos, | ||
// video notes and voice notes, implies can_send_messages. | ||
CanSendMediaMessages bool `json:"can_send_media_messages,omitempty"` | ||
// CanSendPolls is true, if the user is allowed to send polls, implies can_send_messages. | ||
CanSendPolls bool `json:"can_send_polls,omitempty"` | ||
// CanSendOtherMessages is true, if the user is allowed to send animations, games, stickers | ||
// and use inline bots, implies can_send_media_messages. | ||
CanSendOtherMessages bool `json:"can_send_other_messages,omitempty"` | ||
// CanAddWebPagesPreviews is true, if the user is allowed to add web page previews to their messages, | ||
// implies can_send_media_messages | ||
CanAddWebPagesPreviews bool `json:"can_add_web_page_previews,omitempty"` | ||
// CanChangeInfo is true, if the user is allowed to change the chat title, photo and other settings. | ||
// Ignored in public supergroups | ||
CanChangeInfo bool `json:"can_change_info,omitempty"` | ||
// CanInviteUsers is true, if the user is allowed to invite new users to the chat. | ||
CanInviteUsers bool `json:"can_invite_users,omitempty"` | ||
// CanPinMessages is true, if the user is allowed to pin messages. | ||
// Ignored in public supergroups. | ||
CanPinMessages bool `json:"can_pin_messages,omitempty"` | ||
// CanManageTopics is true, if the user is allowed to create forum topics. | ||
// If omitted defaults to the value of can_pin_messages | ||
CanManageTopics bool `json:"can_manage_topics,omitempty"` | ||
} | ||
|
||
// ChatLocation represents a location to which a chat is connected. | ||
type ChatLocation struct { | ||
// Location is the the location to which the supergroup is connected. | ||
// | ||
// It is a required field | ||
Location Location `json:"location,omitempty"` | ||
// Address is location address; 1-64 characters, as defined by the chat owner | ||
// | ||
// It is a required field | ||
Address string `json:"address,omitempty"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package entity | ||
|
||
// InputMedia represents the content of a media message to be sent. | ||
// It should be one of | ||
// | ||
// * InputMediaAnimation | ||
// | ||
// * InputMediaDocument | ||
// | ||
// * InputMediaAudio | ||
// | ||
// * InputMediaPhoto | ||
// | ||
// * InputMediaVideo | ||
// | ||
// TODO: incomplete | ||
type InputMedia struct { | ||
*InputMediaPhoto | ||
} | ||
|
||
// InputMediaPhoto represents a photo to be sent. | ||
type InputMediaPhoto struct { | ||
// Type is type of the result, must be `photo`. | ||
// | ||
// It is a required field | ||
Type string `json:"type,omitempty"` | ||
// Media file to send. | ||
// Pass a file_id to send a file that exists on the Telegram servers (recommended), | ||
// pass an HTTP URL for Telegram to get a file from the Internet, | ||
// or pass “attach://<file_attach_name>” to upload a new one using multipart/form-data | ||
// under <file_attach_name> name. | ||
// | ||
// It is a required field | ||
Media string `json:"media,omitempty"` | ||
// Caption is Caption of the photo to be sent, 0-1024 characters after entities parsing. | ||
Caption string `json:"caption,omitempty"` | ||
// ParseMode is Mode for parsing entities in the photo caption. | ||
ParseMode string `json:"parse_mode,omitempty"` | ||
// CaptionEntities List of special entities that appear in the caption, which can be specified instead of parse_mode | ||
CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package entity | ||
|
||
// Location represents a point on the map. | ||
type Location struct { | ||
// Longitude is longitude as defined by sender. | ||
// | ||
// It is a required field | ||
Longitude float64 `json:"longitude,omitempty"` | ||
// Latitude is latitude as defined by sender. | ||
// | ||
// It is a required field | ||
Latitude float64 `json:"latitude,omitempty"` | ||
// HorizontalAccuracy is the radius of uncertainty for the location, measured in meters; 0-1500. | ||
HorizontalAccuracy float64 `json:"horizontal_accuracy,omitempty"` | ||
// LivePeriod is time relative to the message sending date, | ||
// during which the location can be updated; in seconds. | ||
// For active live locations only. | ||
LivePeriod int64 `json:"live_period,omitempty"` | ||
// Heading is The direction in which user is moving, in degrees; 1-360. | ||
// For active live locations only. | ||
Heading int64 `json:"heading,omitempty"` | ||
// ProximityAlertRadius is the maximum distance for proximity alerts | ||
// about approaching another chat member, in meters. | ||
// For sent live locations only. | ||
ProximityAlertRadius int64 `json:"proximity_alert_radius,omitempty"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,12 +6,33 @@ import "strings" | |
// | ||
// TODO: incomplete | ||
type Message struct { | ||
MessageID int64 `json:"message_id,omitempty"` | ||
From User `json:"from,omitempty"` | ||
Date int64 `json:"date,omitempty"` | ||
ForwardFrom User `json:"forward_from,omitempty"` | ||
ReplyToMessage *Message `json:"reply_to_message,omitempty"` | ||
Text string `json:"text,omitempty"` | ||
// MessageID is a unique message identifier inside this chat. | ||
// | ||
// it is a required field. | ||
MessageID int64 `json:"message_id,omitempty"` | ||
// MessageThreadID is a unique identifier of a message thread to which the message belongs. | ||
// it is for supergroups only | ||
MessageThreadID int64 `json:"message_thread_id,omitempty"` | ||
// From is the sender of the message. | ||
// It is empty for messages sent to channels. | ||
From *User `json:"from,omitempty"` | ||
// SenderChat is the sender of the message, sent on behalf of a chat. | ||
SenderChat *Chat `json:"sender_chat,omitempty"` | ||
// Date is the date the message was sent in Unix time. | ||
// | ||
// It is a required field | ||
Date int64 `json:"date,omitempty"` | ||
// Chat is the conversation this message belongs to. | ||
// | ||
// It is a required field | ||
Chat *Chat `json:"chat,omitempty"` | ||
// ForwardFrom is, for forwarded messages, sender of the original message. | ||
ForwardFrom *User `json:"forward_from,omitempty"` | ||
// ForwardFromChat is, For messages forwarded from channels or from anonymous administrators, | ||
// information about the original sender chat | ||
ForwardFromChat *Chat `json:"forward_from_chat,omitempty"` | ||
ReplyToMessage *Message `json:"reply_to_message,omitempty"` | ||
Text string `json:"text,omitempty"` | ||
} | ||
|
||
// GetCommand checks if this message has Text starting with '/'. | ||
|
@@ -26,3 +47,34 @@ func (m *Message) GetCommand() string { | |
} | ||
return m.Text[1:index] | ||
} | ||
|
||
// MessageEntity represents one special entity in a text message. | ||
// For example, hashtags, usernames, URLs, etc. | ||
type MessageEntity struct { | ||
// Type is Type of the entity. | ||
// Currently, can be “mention” (@username), “hashtag” (#hashtag), “cashtag” ($USD), | ||
// “bot_command” (/start@jobs_bot), “url” (https://telegram.org), “email” ([email protected]), | ||
// “phone_number” (+1-212-555-0123), “bold” (bold text), “italic” (italic text), | ||
// “underline” (underlined text), “strikethrough” (strikethrough text), “spoiler” (spoiler message), | ||
// “code” (monowidth string), “pre” (monowidth block), “text_link” (for clickable text URLs), | ||
// “text_mention” (for users without usernames), “custom_emoji” (for inline custom emoji stickers) | ||
// | ||
// It is a required field | ||
Type string `json:"type,omitempty"` | ||
// Offset is offset in UTF-16 code units to the start of the entity. | ||
// | ||
// It is a required field | ||
Offset int64 `json:"offset,omitempty"` | ||
// Length is length of the entity in UTF-16 code units. | ||
// | ||
// It is a required field | ||
Length int64 `json:"length,omitempty"` | ||
// URL is, for “text_link” only, URL that will be opened after user taps on the text. | ||
URL string `json:"url,omitempty"` | ||
// User is, for “text_mention” only, the mentioned user. | ||
User *User `json:"user,omitempty"` | ||
// Language is, for “pre” only, the programming language of the entity text. | ||
Language string `json:"language,omitempty"` | ||
// CustomEmojiID is, for “custom_emoji” only, unique identifier of the custom emoji. | ||
CustomEmojiID string `json:"custom_emoji_id,omitempty"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package entity | ||
|
||
// PhotoSize represents one size of a photo or a file / sticker thumbnail. | ||
type PhotoSize struct { | ||
// FileID is identifier for this file, which can be used to download or reuse the file. | ||
// | ||
// It is a required field. | ||
FileID string `json:"file_id,omitempty"` | ||
// FileUniqueID is a unique identifier for this file, | ||
// which is supposed to be the same over time and for different bots. | ||
// | ||
// It is a required field. | ||
FileUniqueID string `json:"file_unique_id,omitempty"` | ||
// Width is the photo's width. | ||
// | ||
// It is a required field. | ||
Width int64 `json:"width,omitempty"` | ||
// Height is the photo's height. | ||
// | ||
// It is a required field. | ||
Height int64 `json:"height,omitempty"` | ||
// FileSize is the file size in bytes. | ||
FileSize int64 `json:"file_size,omitempty"` | ||
} | ||
|
||
// UserProfilePhotos represent a user's profile pictures. | ||
type UserProfilePhotos struct { | ||
// TotalCount is the total number of profile pictures the target user has. | ||
TotalCount int64 `json:"total_count,omitempty"` | ||
// Photos is requested profile pictures (in up to 4 sizes each). | ||
Photos [][]PhotoSize `json:"photos,omitempty"` | ||
} |