Refactoring, poor BC, closes #44 and probably resolves #41.

- EntityType and ChatType enums introduced.
- Documentation fixes, struct refactoring.
- Poor BC, poor BC...
pull/76/head^2
Ian Byrd 8 years ago
parent d8b2ca1983
commit 6360f1f7d9
No known key found for this signature in database
GPG Key ID: 598F598CA3B8055F

@ -502,10 +502,10 @@ func (b *Bot) SendVenue(recipient Recipient, venue *Venue, options *SendOptions)
//
// Currently, Telegram supports only a narrow range of possible
// actions, these are aligned as constants of this package.
func (b *Bot) SendChatAction(recipient Recipient, action string) error {
func (b *Bot) SendChatAction(recipient Recipient, action ChatAction) error {
params := map[string]string{
"chat_id": recipient.Destination(),
"action": action,
"action": string(action),
}
responseJSON, err := sendCommand("sendChatAction", b.Token, params)

@ -1,15 +1,5 @@
package telebot
// ParseMode determines the way client applications treat the text of the message
type ParseMode string
// Supported ParseMode
const (
ModeDefault ParseMode = ""
ModeMarkdown ParseMode = "Markdown"
ModeHTML ParseMode = "HTML"
)
// SendOptions represents a set of custom options that could
// be appled to messages sent.
type SendOptions struct {

@ -27,14 +27,52 @@
//
package telebot
// A bunch of available chat actions.
// ChatAction is a client-side status indicating bot activity.
type ChatAction string
const (
Typing ChatAction = "typing"
UploadingPhoto ChatAction = "upload_photo"
UploadingVideo ChatAction = "upload_video"
UploadingAudio ChatAction = "upload_audio"
UploadingDocument ChatAction = "upload_document"
RecordingVideo ChatAction = "record_video"
RecordingAudio ChatAction = "record_audio"
FindingLocation ChatAction = "find_location"
)
// ParseMode determines the way client applications treat the text of the message
type ParseMode string
const (
ModeDefault ParseMode = ""
ModeMarkdown ParseMode = "Markdown"
ModeHTML ParseMode = "HTML"
)
// EntityType is a MessageEntity type.
type EntityType string
const (
EntityMention EntityType = "mention"
EntityTMention EntityType = "text_mention"
EntityHashtag EntityType = "hashtag"
EntityCommand EntityType = "bot_command"
EntityURL EntityType = "url"
EntityEmail EntityType = "email"
EntityBold EntityType = "bold"
EntityItalic EntityType = "italic"
EntityCode EntityType = "code"
EntityCodeBlock EntityType = "pre"
EntityTextLink EntityType = "text_link"
)
// ChatType represents one of the possible chat types.
type ChatType string
const (
Typing = "typing"
UploadingPhoto = "upload_photo"
UploadingVideo = "upload_video"
UploadingAudio = "upload_audio"
UploadingDocument = "upload_document"
RecordingVideo = "record_video"
RecordingAudio = "record_audio"
FindingLocation = "find_location"
ChatPrivate ChatType = "private"
ChatGroup ChatType = "group"
ChatSuperGroup ChatType = "supergroup"
ChatChannel ChatType = "channel"
)

@ -26,13 +26,17 @@ func (u User) Destination() string {
}
// Chat object represents a Telegram user, bot or group chat.
// Title for channels and group chats
//
// Type of chat, can be either “private”, “group”, "supergroup" or “channel”
type Chat struct {
ID int64 `json:"id"`
Type string `json:"type"`
ID int64 `json:"id"`
// See telebot.ChatType and consts.
Type ChatType `json:"type"`
// Won't be there for ChatPrivate.
Title string `json:"title"`
Title string `json:"title"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
Username string `json:"username"`
@ -147,10 +151,11 @@ type KeyboardButton struct {
InlineQuery string `json:"switch_inline_query,omitempty"`
}
// InlineKeyboardMarkup represents an inline keyboard that appears right next
// to the message it belongs to.
// InlineKeyboardMarkup represents an inline keyboard that appears
// right next to the message it belongs to.
type InlineKeyboardMarkup struct {
// Array of button rows, each represented by an Array of KeyboardButton objects.
// Array of button rows, each represented by
// an Array of KeyboardButton objects.
InlineKeyboard [][]KeyboardButton `json:"inline_keyboard,omitempty"`
}
@ -183,10 +188,14 @@ type Callback struct {
// MessageID will be set if the button was attached to a message
// sent via the bot in inline mode.
MessageID string `json:"inline_message_id"`
Data string `json:"data"`
// Data associated with the callback button. Be aware that
// a bad client can send arbitrary data in this field.
Data string `json:"data"`
}
// CallbackResponse builds a response to an Callback query.
// CallbackResponse builds a response to a Callback query.
//
// See also: https://core.telegram.org/bots/api#answerCallbackQuery
type CallbackResponse struct {
// The ID of the callback to which this is a response.
@ -208,7 +217,8 @@ type CallbackResponse struct {
URL string `json:"url,omitempty"`
}
// Venue object represents a venue location with name, address and optional foursquare id.
// Venue object represents a venue location with name, address and
// optional foursquare ID.
type Venue struct {
Location Location `json:"location"`
Title string `json:"title"`
@ -216,44 +226,38 @@ type Venue struct {
FoursquareID string `json:"foursquare_id,omitempty"`
}
// MessageEntity
// This object represents one special entity in a text message.
// For example, hashtags, usernames, URLs, etc
// MessageEntity object represents "special" parts of text messages,
// including hashtags, usernames, URLs, etc.
type MessageEntity struct {
// Specifies entity type.
Type EntityType `json:"type"`
// type Type of the entity. Can be mention (@username), hashtag,
// bot_command, url, email, bold (bold text), italic (italic text),
// code (monowidth string), pre (monowidth block), text_link (for clickable text URLs),
// text_mention (for users without usernames)
Type string `json:"type"`
// offset Offset in UTF-16 code units to the start of the entity
// Offset in UTF-16 code units to the start of the entity.
Offset int `json:"offset"`
//length Length of the entity in UTF-16 code units
// Length of the entity in UTF-16 code units.
Length int `json:"length"`
//url Optional. For “text_link” only, url that will be opened after user taps on the text
Url string `json:"url,omitempty"`
// (Optional) For EntityTextLink entity type only.
//
// URL will be opened after user taps on the text.
URL string `json:"url,omitempty"`
//user Optional. For “text_mention” only, the mentioned user
// (Optional) For EntityTMention entity type only.
User User `json:"user,omitempty"`
}
// ChatMember ,
// This struct contains information about one member of the chat.
// ChatMember object represents information about a single chat member.
type ChatMember struct {
User User `json:"user"`
Status string `json:"status"`
}
// UserProfilePhotos ,
// This struct represent a user's profile pictures.
//
// Count : Total number of profile pictures the target user has
//
// Photos : Array of Array of PhotoSize , Requested profile pictures (in up to 4 sizes each)
// UserProfilePhotos object represent a user's profile pictures.
type UserProfilePhotos struct {
Count int `json:"total_count"`
// Total number of profile pictures the target user has.
Count int `json:"total_count"`
// Requested profile pictures (in up to 4 sizes each).
Photos [][]Photo `json:"photos"`
}

Loading…
Cancel
Save