2015-06-27 15:44:12 +00:00
|
|
|
package telebot
|
|
|
|
|
2015-12-24 08:51:42 +00:00
|
|
|
import "strconv"
|
|
|
|
|
2015-10-16 22:36:07 +00:00
|
|
|
// Recipient is basically any possible endpoint you can send
|
|
|
|
// messages to. It's usually a distinct user or a chat.
|
|
|
|
type Recipient interface {
|
2015-12-24 08:51:42 +00:00
|
|
|
// ID of user or group chat, @Username for channel
|
|
|
|
Destination() string
|
2015-10-16 22:36:07 +00:00
|
|
|
}
|
|
|
|
|
2015-10-16 16:36:20 +00:00
|
|
|
// User object represents a Telegram user, bot
|
2015-07-06 16:58:54 +00:00
|
|
|
//
|
|
|
|
// object represents a group chat if Title is empty.
|
2015-06-27 15:44:12 +00:00
|
|
|
type User struct {
|
2015-07-06 16:27:10 +00:00
|
|
|
ID int `json:"id"`
|
2015-06-27 15:44:12 +00:00
|
|
|
FirstName string `json:"first_name"`
|
2015-10-16 16:36:20 +00:00
|
|
|
|
|
|
|
LastName string `json:"last_name"`
|
|
|
|
Username string `json:"username"`
|
|
|
|
}
|
|
|
|
|
2015-10-16 22:36:07 +00:00
|
|
|
// Destination is internal user ID.
|
2015-12-24 08:51:42 +00:00
|
|
|
func (u User) Destination() string {
|
|
|
|
return strconv.Itoa(u.ID)
|
2015-10-16 22:36:07 +00:00
|
|
|
}
|
|
|
|
|
2015-10-16 16:36:20 +00:00
|
|
|
// Chat object represents a Telegram user, bot or group chat.
|
2016-11-10 20:04:50 +00:00
|
|
|
//
|
2015-12-24 08:51:42 +00:00
|
|
|
// Type of chat, can be either “private”, “group”, "supergroup" or “channel”
|
2015-10-16 16:36:20 +00:00
|
|
|
type Chat struct {
|
2016-11-10 20:04:50 +00:00
|
|
|
ID int64 `json:"id"`
|
|
|
|
|
|
|
|
// See telebot.ChatType and consts.
|
|
|
|
Type ChatType `json:"type"`
|
|
|
|
|
|
|
|
// Won't be there for ChatPrivate.
|
|
|
|
Title string `json:"title"`
|
2015-10-16 16:36:20 +00:00
|
|
|
|
|
|
|
FirstName string `json:"first_name"`
|
2015-06-27 15:44:12 +00:00
|
|
|
LastName string `json:"last_name"`
|
|
|
|
Username string `json:"username"`
|
|
|
|
}
|
|
|
|
|
2015-10-16 22:36:07 +00:00
|
|
|
// Destination is internal chat ID.
|
2015-12-24 08:51:42 +00:00
|
|
|
func (c Chat) Destination() string {
|
|
|
|
ret := "@" + c.Username
|
|
|
|
if c.Type != "channel" {
|
|
|
|
ret = strconv.FormatInt(c.ID, 10)
|
|
|
|
}
|
|
|
|
return ret
|
2015-10-16 22:36:07 +00:00
|
|
|
}
|
|
|
|
|
2015-10-16 16:36:20 +00:00
|
|
|
// IsGroupChat returns true if chat object represents a group chat.
|
2015-10-16 22:36:07 +00:00
|
|
|
func (c Chat) IsGroupChat() bool {
|
2015-12-24 08:51:42 +00:00
|
|
|
return c.Type != "private"
|
2015-07-06 16:58:54 +00:00
|
|
|
}
|
|
|
|
|
2015-06-27 15:44:12 +00:00
|
|
|
// Update object represents an incoming update.
|
|
|
|
type Update struct {
|
2016-11-09 23:34:57 +00:00
|
|
|
ID int64 `json:"update_id"`
|
2016-04-21 20:31:30 +00:00
|
|
|
Payload *Message `json:"message"`
|
2016-01-22 11:38:45 +00:00
|
|
|
|
|
|
|
// optional
|
2016-04-21 20:31:30 +00:00
|
|
|
Callback *Callback `json:"callback_query"`
|
|
|
|
Query *Query `json:"inline_query"`
|
2015-06-27 15:44:12 +00:00
|
|
|
}
|
2015-06-27 17:37:22 +00:00
|
|
|
|
2016-01-22 11:38:45 +00:00
|
|
|
// Thumbnail object represents an image/sticker of a particular size.
|
2015-06-27 17:37:22 +00:00
|
|
|
type Thumbnail struct {
|
|
|
|
File
|
|
|
|
|
|
|
|
Width int `json:"width"`
|
|
|
|
Height int `json:"height"`
|
|
|
|
}
|
|
|
|
|
2015-07-02 18:39:39 +00:00
|
|
|
// Photo object represents a photo with caption.
|
|
|
|
type Photo struct {
|
2016-01-22 11:38:45 +00:00
|
|
|
File
|
|
|
|
|
2015-07-02 18:39:39 +00:00
|
|
|
Thumbnail
|
|
|
|
|
|
|
|
Caption string
|
|
|
|
}
|
|
|
|
|
2015-06-27 17:37:22 +00:00
|
|
|
// Audio object represents an audio file (voice note).
|
|
|
|
type Audio struct {
|
|
|
|
File
|
|
|
|
|
|
|
|
// Duration of the recording in seconds as defined by sender.
|
|
|
|
Duration int `json:"duration"`
|
|
|
|
|
2016-11-09 22:05:01 +00:00
|
|
|
// FileSize (optional) of the audio file.
|
|
|
|
FileSize int `json:"file_size"`
|
|
|
|
|
|
|
|
// Title (optional) as defined by sender or by audio tags.
|
|
|
|
Title string `json:"title"`
|
|
|
|
|
|
|
|
// Performer (optional) is defined by sender or by audio tags.
|
|
|
|
Performer string `json:"performer"`
|
|
|
|
|
|
|
|
// MIME type (optional) of the file as defined by sender.
|
2015-06-27 17:37:22 +00:00
|
|
|
Mime string `json:"mime_type"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Document object represents a general file (as opposed to Photo or Audio).
|
|
|
|
// Telegram users can send files of any type of up to 1.5 GB in size.
|
|
|
|
type Document struct {
|
|
|
|
File
|
|
|
|
|
|
|
|
// Document thumbnail as defined by sender.
|
|
|
|
Preview Thumbnail `json:"thumb"`
|
|
|
|
|
|
|
|
// Original filename as defined by sender.
|
|
|
|
FileName string `json:"file_name"`
|
|
|
|
|
|
|
|
// MIME type of the file as defined by sender.
|
|
|
|
Mime string `json:"mime_type"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sticker object represents a WebP image, so-called sticker.
|
|
|
|
type Sticker struct {
|
|
|
|
File
|
|
|
|
|
|
|
|
Width int `json:"width"`
|
|
|
|
Height int `json:"height"`
|
|
|
|
|
|
|
|
// Sticker thumbnail in .webp or .jpg format.
|
|
|
|
Preview Thumbnail `json:"thumb"`
|
|
|
|
}
|
|
|
|
|
2015-07-03 18:54:40 +00:00
|
|
|
// Video object represents an MP4-encoded video.
|
2015-06-27 17:37:22 +00:00
|
|
|
type Video struct {
|
|
|
|
Audio
|
|
|
|
|
|
|
|
Width int `json:"width"`
|
|
|
|
Height int `json:"height"`
|
|
|
|
|
|
|
|
// Text description of the video as defined by sender (usually empty).
|
|
|
|
Caption string `json:"caption"`
|
|
|
|
|
|
|
|
// Video thumbnail.
|
|
|
|
Preview Thumbnail `json:"thumb"`
|
|
|
|
}
|
|
|
|
|
2016-04-21 20:31:30 +00:00
|
|
|
// KeyboardButton represents a button displayed on in a message.
|
|
|
|
type KeyboardButton struct {
|
|
|
|
Text string `json:"text"`
|
|
|
|
URL string `json:"url,omitempty"`
|
|
|
|
Data string `json:"callback_data,omitempty"`
|
|
|
|
InlineQuery string `json:"switch_inline_query,omitempty"`
|
|
|
|
}
|
|
|
|
|
2016-11-10 20:04:50 +00:00
|
|
|
// InlineKeyboardMarkup represents an inline keyboard that appears
|
|
|
|
// right next to the message it belongs to.
|
2016-06-26 14:05:37 +00:00
|
|
|
type InlineKeyboardMarkup struct {
|
2016-11-10 20:04:50 +00:00
|
|
|
// Array of button rows, each represented by
|
|
|
|
// an Array of KeyboardButton objects.
|
2016-06-26 14:05:37 +00:00
|
|
|
InlineKeyboard [][]KeyboardButton `json:"inline_keyboard,omitempty"`
|
|
|
|
}
|
|
|
|
|
2015-07-03 18:54:40 +00:00
|
|
|
// Contact object represents a contact to Telegram user
|
2015-06-27 17:37:22 +00:00
|
|
|
type Contact struct {
|
2015-12-05 09:40:55 +00:00
|
|
|
UserID int `json:"user_id"`
|
2015-06-27 17:37:22 +00:00
|
|
|
PhoneNumber string `json:"phone_number"`
|
|
|
|
FirstName string `json:"first_name"`
|
|
|
|
LastName string `json:"last_name"`
|
|
|
|
}
|
|
|
|
|
2015-07-03 18:54:40 +00:00
|
|
|
// Location object represents geographic position.
|
2015-06-27 17:37:22 +00:00
|
|
|
type Location struct {
|
|
|
|
Latitude float32 `json:"latitude"`
|
2016-08-27 12:40:49 +00:00
|
|
|
Longitude float32 `json:"longitude"`
|
2015-06-27 17:37:22 +00:00
|
|
|
}
|
2016-05-24 04:43:16 +00:00
|
|
|
|
2016-05-25 13:53:01 +00:00
|
|
|
// Callback object represents a query from a callback button in an
|
|
|
|
// inline keyboard.
|
2016-04-21 20:31:30 +00:00
|
|
|
type Callback struct {
|
|
|
|
ID string `json:"id"`
|
2016-05-25 13:53:01 +00:00
|
|
|
|
2016-04-21 20:31:30 +00:00
|
|
|
// For message sent to channels, Sender may be empty
|
|
|
|
Sender User `json:"from"`
|
|
|
|
|
2016-05-25 13:53:01 +00:00
|
|
|
// Message will be set if the button that originated the query
|
|
|
|
// was attached to a message sent by a bot.
|
2016-04-21 20:31:30 +00:00
|
|
|
Message Message `json:"message"`
|
|
|
|
|
2016-05-25 13:53:01 +00:00
|
|
|
// 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"`
|
2016-11-10 20:04:50 +00:00
|
|
|
|
|
|
|
// Data associated with the callback button. Be aware that
|
|
|
|
// a bad client can send arbitrary data in this field.
|
|
|
|
Data string `json:"data"`
|
2016-04-21 20:31:30 +00:00
|
|
|
}
|
2016-07-04 10:56:53 +00:00
|
|
|
|
2016-11-10 20:04:50 +00:00
|
|
|
// CallbackResponse builds a response to a Callback query.
|
|
|
|
//
|
2016-07-25 22:09:18 +00:00
|
|
|
// See also: https://core.telegram.org/bots/api#answerCallbackQuery
|
|
|
|
type CallbackResponse struct {
|
|
|
|
// The ID of the callback to which this is a response.
|
|
|
|
// It is not necessary to specify this field manually.
|
|
|
|
CallbackID string `json:"callback_query_id"`
|
|
|
|
|
|
|
|
// Text of the notification. If not specified, nothing will be shown to the user.
|
|
|
|
Text string `json:"text,omitempty"`
|
|
|
|
|
|
|
|
// (Optional) If true, an alert will be shown by the client instead
|
|
|
|
// of a notification at the top of the chat screen. Defaults to false.
|
|
|
|
ShowAlert bool `json:"show_alert,omitempty"`
|
2016-11-09 22:05:01 +00:00
|
|
|
|
2016-11-09 08:04:22 +00:00
|
|
|
// (Optional) URL that will be opened by the user's client.
|
|
|
|
// If you have created a Game and accepted the conditions via @Botfather
|
|
|
|
// specify the URL that opens your game
|
|
|
|
// note that this will only work if the query comes from a callback_game button.
|
|
|
|
// Otherwise, you may use links like telegram.me/your_bot?start=XXXX that open your bot with a parameter.
|
|
|
|
URL string `json:"url,omitempty"`
|
2016-07-25 22:09:18 +00:00
|
|
|
}
|
|
|
|
|
2016-11-10 20:04:50 +00:00
|
|
|
// Venue object represents a venue location with name, address and
|
|
|
|
// optional foursquare ID.
|
2016-05-24 04:43:16 +00:00
|
|
|
type Venue struct {
|
2016-11-10 19:34:02 +00:00
|
|
|
Location Location `json:"location"`
|
|
|
|
Title string `json:"title"`
|
|
|
|
Address string `json:"address"`
|
|
|
|
FoursquareID string `json:"foursquare_id,omitempty"`
|
2016-05-24 04:43:16 +00:00
|
|
|
}
|
2016-07-10 18:58:42 +00:00
|
|
|
|
2016-11-10 20:04:50 +00:00
|
|
|
// MessageEntity object represents "special" parts of text messages,
|
|
|
|
// including hashtags, usernames, URLs, etc.
|
2016-07-10 18:58:42 +00:00
|
|
|
type MessageEntity struct {
|
2016-11-10 20:04:50 +00:00
|
|
|
// Specifies entity type.
|
|
|
|
Type EntityType `json:"type"`
|
2016-07-10 18:58:42 +00:00
|
|
|
|
2016-11-10 20:04:50 +00:00
|
|
|
// Offset in UTF-16 code units to the start of the entity.
|
2016-07-10 18:58:42 +00:00
|
|
|
Offset int `json:"offset"`
|
|
|
|
|
2016-11-10 20:04:50 +00:00
|
|
|
// Length of the entity in UTF-16 code units.
|
2016-07-10 18:58:42 +00:00
|
|
|
Length int `json:"length"`
|
|
|
|
|
2016-11-10 20:04:50 +00:00
|
|
|
// (Optional) For EntityTextLink entity type only.
|
|
|
|
//
|
|
|
|
// URL will be opened after user taps on the text.
|
|
|
|
URL string `json:"url,omitempty"`
|
2016-07-10 18:58:42 +00:00
|
|
|
|
2016-11-10 20:04:50 +00:00
|
|
|
// (Optional) For EntityTMention entity type only.
|
2016-11-10 19:34:02 +00:00
|
|
|
User User `json:"user,omitempty"`
|
2016-07-10 18:58:42 +00:00
|
|
|
}
|
2016-10-09 20:09:07 +00:00
|
|
|
|
2016-11-10 20:04:50 +00:00
|
|
|
// ChatMember object represents information about a single chat member.
|
2016-10-09 20:09:07 +00:00
|
|
|
type ChatMember struct {
|
|
|
|
User User `json:"user"`
|
|
|
|
Status string `json:"status"`
|
|
|
|
}
|
2016-10-09 20:29:03 +00:00
|
|
|
|
2016-11-10 20:04:50 +00:00
|
|
|
// UserProfilePhotos object represent a user's profile pictures.
|
2016-10-09 20:29:03 +00:00
|
|
|
type UserProfilePhotos struct {
|
2016-11-10 20:04:50 +00:00
|
|
|
// Total number of profile pictures the target user has.
|
|
|
|
Count int `json:"total_count"`
|
|
|
|
|
|
|
|
// Requested profile pictures (in up to 4 sizes each).
|
2016-10-09 20:29:03 +00:00
|
|
|
Photos [][]Photo `json:"photos"`
|
|
|
|
}
|