2015-06-26 06:26:24 +02:00
|
|
|
package tgbotapi
|
2015-06-25 18:25:02 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2016-04-14 00:06:18 +02:00
|
|
|
"errors"
|
2015-09-19 17:53:32 +02:00
|
|
|
"fmt"
|
2016-04-12 15:28:46 +02:00
|
|
|
"net/url"
|
2015-11-21 15:26:28 +01:00
|
|
|
"strings"
|
2015-11-21 15:39:19 +01:00
|
|
|
"time"
|
2015-06-25 18:25:02 +02:00
|
|
|
)
|
|
|
|
|
2016-01-03 23:54:24 +01:00
|
|
|
// APIResponse is a response from the Telegram API with the result
|
|
|
|
// stored raw.
|
2015-06-26 08:53:20 +02:00
|
|
|
type APIResponse struct {
|
2016-10-03 17:47:19 +02:00
|
|
|
Ok bool `json:"ok"`
|
|
|
|
Result json.RawMessage `json:"result"`
|
|
|
|
ErrorCode int `json:"error_code"`
|
|
|
|
Description string `json:"description"`
|
|
|
|
Parameters *ResponseParameters `json:"parameters"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// ResponseParameters are various errors that can be returned in APIResponse.
|
|
|
|
type ResponseParameters struct {
|
2016-11-25 06:50:35 +01:00
|
|
|
MigrateToChatID int64 `json:"migrate_to_chat_id"` // optional
|
|
|
|
RetryAfter int `json:"retry_after"` // optional
|
2015-06-25 18:25:02 +02:00
|
|
|
}
|
|
|
|
|
2015-06-26 08:53:20 +02:00
|
|
|
// Update is an update response, from GetUpdates.
|
2015-06-25 18:25:02 +02:00
|
|
|
type Update struct {
|
2016-04-13 15:22:58 +02:00
|
|
|
UpdateID int `json:"update_id"`
|
|
|
|
Message *Message `json:"message"`
|
2016-05-22 16:37:43 +02:00
|
|
|
EditedMessage *Message `json:"edited_message"`
|
2016-11-25 06:50:35 +01:00
|
|
|
ChannelPost *Message `json:"channel_post"`
|
|
|
|
EditedChannelPost *Message `json:"edited_channel_post"`
|
2016-04-13 15:22:58 +02:00
|
|
|
InlineQuery *InlineQuery `json:"inline_query"`
|
|
|
|
ChosenInlineResult *ChosenInlineResult `json:"chosen_inline_result"`
|
|
|
|
CallbackQuery *CallbackQuery `json:"callback_query"`
|
2015-06-25 18:25:02 +02:00
|
|
|
}
|
|
|
|
|
2017-01-26 18:43:28 +01:00
|
|
|
// UpdatesChannel is the channel for getting updates.
|
|
|
|
type UpdatesChannel <-chan Update
|
2016-12-15 22:51:58 +01:00
|
|
|
|
2017-01-26 18:43:28 +01:00
|
|
|
// Clear discards all unprocessed incoming updates.
|
|
|
|
func (ch UpdatesChannel) Clear() {
|
2016-12-15 22:51:58 +01:00
|
|
|
for len(ch) != 0 {
|
|
|
|
<-ch
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-03 23:54:24 +01:00
|
|
|
// User is a user on Telegram.
|
2015-06-25 18:25:02 +02:00
|
|
|
type User struct {
|
2015-06-26 08:53:20 +02:00
|
|
|
ID int `json:"id"`
|
2015-06-25 18:25:02 +02:00
|
|
|
FirstName string `json:"first_name"`
|
2016-01-03 23:54:24 +01:00
|
|
|
LastName string `json:"last_name"` // optional
|
|
|
|
UserName string `json:"username"` // optional
|
2015-06-25 18:25:02 +02:00
|
|
|
}
|
|
|
|
|
2015-07-31 09:22:01 +02:00
|
|
|
// String displays a simple text version of a user.
|
2016-01-03 23:54:24 +01:00
|
|
|
//
|
|
|
|
// It is normally a user's username, but falls back to a first/last
|
|
|
|
// name as available.
|
2015-07-31 09:22:01 +02:00
|
|
|
func (u *User) String() string {
|
|
|
|
if u.UserName != "" {
|
|
|
|
return u.UserName
|
|
|
|
}
|
|
|
|
|
|
|
|
name := u.FirstName
|
|
|
|
if u.LastName != "" {
|
|
|
|
name += " " + u.LastName
|
|
|
|
}
|
|
|
|
|
|
|
|
return name
|
|
|
|
}
|
|
|
|
|
2016-01-03 23:54:24 +01:00
|
|
|
// GroupChat is a group chat.
|
2015-06-25 18:25:02 +02:00
|
|
|
type GroupChat struct {
|
2015-06-26 08:53:20 +02:00
|
|
|
ID int `json:"id"`
|
2015-06-25 18:25:02 +02:00
|
|
|
Title string `json:"title"`
|
|
|
|
}
|
|
|
|
|
2016-01-03 23:54:24 +01:00
|
|
|
// Chat contains information about the place a message was sent.
|
2015-10-09 16:26:38 +02:00
|
|
|
type Chat struct {
|
2016-10-03 17:47:19 +02:00
|
|
|
ID int64 `json:"id"`
|
|
|
|
Type string `json:"type"`
|
|
|
|
Title string `json:"title"` // optional
|
|
|
|
UserName string `json:"username"` // optional
|
|
|
|
FirstName string `json:"first_name"` // optional
|
|
|
|
LastName string `json:"last_name"` // optional
|
|
|
|
AllMembersAreAdmins bool `json:"all_members_are_administrators"` // optional
|
2015-06-25 18:25:02 +02:00
|
|
|
}
|
|
|
|
|
2016-01-03 23:54:24 +01:00
|
|
|
// IsPrivate returns if the Chat is a private conversation.
|
2016-05-22 17:16:28 +02:00
|
|
|
func (c Chat) IsPrivate() bool {
|
2015-10-09 16:31:00 +02:00
|
|
|
return c.Type == "private"
|
|
|
|
}
|
|
|
|
|
2016-01-03 23:54:24 +01:00
|
|
|
// IsGroup returns if the Chat is a group.
|
2016-05-22 17:16:28 +02:00
|
|
|
func (c Chat) IsGroup() bool {
|
2015-10-09 16:31:00 +02:00
|
|
|
return c.Type == "group"
|
|
|
|
}
|
|
|
|
|
2016-01-03 23:54:24 +01:00
|
|
|
// IsSuperGroup returns if the Chat is a supergroup.
|
2016-05-22 17:16:28 +02:00
|
|
|
func (c Chat) IsSuperGroup() bool {
|
2015-12-10 03:08:37 +01:00
|
|
|
return c.Type == "supergroup"
|
|
|
|
}
|
|
|
|
|
2016-01-03 23:54:24 +01:00
|
|
|
// IsChannel returns if the Chat is a channel.
|
2016-05-22 17:16:28 +02:00
|
|
|
func (c Chat) IsChannel() bool {
|
2015-10-09 16:31:00 +02:00
|
|
|
return c.Type == "channel"
|
|
|
|
}
|
|
|
|
|
2016-05-22 17:16:28 +02:00
|
|
|
// ChatConfig returns a ChatConfig struct for chat related methods.
|
|
|
|
func (c Chat) ChatConfig() ChatConfig {
|
|
|
|
return ChatConfig{ChatID: c.ID}
|
|
|
|
}
|
|
|
|
|
2016-01-03 23:54:24 +01:00
|
|
|
// Message is returned by almost every request, and contains data about
|
|
|
|
// almost anything.
|
2015-06-25 18:25:02 +02:00
|
|
|
type Message struct {
|
2016-04-13 15:22:58 +02:00
|
|
|
MessageID int `json:"message_id"`
|
|
|
|
From *User `json:"from"` // optional
|
|
|
|
Date int `json:"date"`
|
|
|
|
Chat *Chat `json:"chat"`
|
|
|
|
ForwardFrom *User `json:"forward_from"` // optional
|
2016-05-21 03:34:56 +02:00
|
|
|
ForwardFromChat *Chat `json:"forward_from_chat"` // optional
|
2016-11-25 06:50:35 +01:00
|
|
|
ForwardFromMessageID int `json:"forward_from_message_id"` // optional
|
2016-04-13 15:22:58 +02:00
|
|
|
ForwardDate int `json:"forward_date"` // optional
|
|
|
|
ReplyToMessage *Message `json:"reply_to_message"` // optional
|
2016-05-22 16:37:43 +02:00
|
|
|
EditDate int `json:"edit_date"` // optional
|
2016-04-13 15:22:58 +02:00
|
|
|
Text string `json:"text"` // optional
|
|
|
|
Entities *[]MessageEntity `json:"entities"` // optional
|
|
|
|
Audio *Audio `json:"audio"` // optional
|
|
|
|
Document *Document `json:"document"` // optional
|
2016-10-03 17:47:19 +02:00
|
|
|
Game *Game `json:"game"` // optional
|
2016-04-13 15:22:58 +02:00
|
|
|
Photo *[]PhotoSize `json:"photo"` // optional
|
|
|
|
Sticker *Sticker `json:"sticker"` // optional
|
|
|
|
Video *Video `json:"video"` // optional
|
|
|
|
Voice *Voice `json:"voice"` // optional
|
|
|
|
Caption string `json:"caption"` // optional
|
|
|
|
Contact *Contact `json:"contact"` // optional
|
|
|
|
Location *Location `json:"location"` // optional
|
|
|
|
Venue *Venue `json:"venue"` // optional
|
|
|
|
NewChatMember *User `json:"new_chat_member"` // optional
|
|
|
|
LeftChatMember *User `json:"left_chat_member"` // optional
|
|
|
|
NewChatTitle string `json:"new_chat_title"` // optional
|
|
|
|
NewChatPhoto *[]PhotoSize `json:"new_chat_photo"` // optional
|
|
|
|
DeleteChatPhoto bool `json:"delete_chat_photo"` // optional
|
|
|
|
GroupChatCreated bool `json:"group_chat_created"` // optional
|
|
|
|
SuperGroupChatCreated bool `json:"supergroup_chat_created"` // optional
|
|
|
|
ChannelChatCreated bool `json:"channel_chat_created"` // optional
|
|
|
|
MigrateToChatID int64 `json:"migrate_to_chat_id"` // optional
|
|
|
|
MigrateFromChatID int64 `json:"migrate_from_chat_id"` // optional
|
|
|
|
PinnedMessage *Message `json:"pinned_message"` // optional
|
2015-06-25 18:25:02 +02:00
|
|
|
}
|
|
|
|
|
2015-07-31 19:40:42 +02:00
|
|
|
// Time converts the message timestamp into a Time.
|
|
|
|
func (m *Message) Time() time.Time {
|
|
|
|
return time.Unix(int64(m.Date), 0)
|
|
|
|
}
|
|
|
|
|
2016-01-03 23:54:24 +01:00
|
|
|
// IsCommand returns true if message starts with '/'.
|
2015-11-21 14:43:39 +01:00
|
|
|
func (m *Message) IsCommand() bool {
|
|
|
|
return m.Text != "" && m.Text[0] == '/'
|
|
|
|
}
|
|
|
|
|
2016-01-03 23:54:24 +01:00
|
|
|
// Command checks if the message was a command and if it was, returns the
|
|
|
|
// command. If the Message was not a command, it returns an empty string.
|
2016-01-04 18:45:46 +01:00
|
|
|
//
|
|
|
|
// If the command contains the at bot syntax, it removes the bot name.
|
2015-11-21 15:26:28 +01:00
|
|
|
func (m *Message) Command() string {
|
2016-01-03 23:54:24 +01:00
|
|
|
if !m.IsCommand() {
|
|
|
|
return ""
|
2015-12-13 18:31:59 +01:00
|
|
|
}
|
2016-01-03 23:54:24 +01:00
|
|
|
|
2016-01-04 18:45:46 +01:00
|
|
|
command := strings.SplitN(m.Text, " ", 2)[0][1:]
|
|
|
|
|
|
|
|
if i := strings.Index(command, "@"); i != -1 {
|
|
|
|
command = command[:i]
|
|
|
|
}
|
|
|
|
|
|
|
|
return command
|
2015-12-13 18:31:59 +01:00
|
|
|
}
|
|
|
|
|
2016-01-03 23:54:24 +01:00
|
|
|
// CommandArguments checks if the message was a command and if it was,
|
|
|
|
// returns all text after the command name. If the Message was not a
|
|
|
|
// command, it returns an empty string.
|
2015-12-13 18:31:59 +01:00
|
|
|
func (m *Message) CommandArguments() string {
|
2016-01-03 23:54:24 +01:00
|
|
|
if !m.IsCommand() {
|
|
|
|
return ""
|
2015-12-13 18:31:59 +01:00
|
|
|
}
|
2016-01-03 23:54:24 +01:00
|
|
|
|
|
|
|
split := strings.SplitN(m.Text, " ", 2)
|
|
|
|
if len(split) != 2 {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2017-03-18 12:42:30 +01:00
|
|
|
return split[1]
|
2015-11-21 15:26:28 +01:00
|
|
|
}
|
|
|
|
|
2016-04-12 15:28:46 +02:00
|
|
|
// MessageEntity contains information about data in a Message.
|
|
|
|
type MessageEntity struct {
|
|
|
|
Type string `json:"type"`
|
|
|
|
Offset int `json:"offset"`
|
|
|
|
Length int `json:"length"`
|
2016-05-22 16:37:43 +02:00
|
|
|
URL string `json:"url"` // optional
|
|
|
|
User *User `json:"user"` // optional
|
2016-04-12 15:28:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ParseURL attempts to parse a URL contained within a MessageEntity.
|
|
|
|
func (entity MessageEntity) ParseURL() (*url.URL, error) {
|
2016-04-14 00:06:18 +02:00
|
|
|
if entity.URL == "" {
|
|
|
|
return nil, errors.New(ErrBadURL)
|
|
|
|
}
|
|
|
|
|
2016-04-12 15:28:46 +02:00
|
|
|
return url.Parse(entity.URL)
|
|
|
|
}
|
|
|
|
|
2016-01-03 23:54:24 +01:00
|
|
|
// PhotoSize contains information about photos.
|
2015-06-25 18:25:02 +02:00
|
|
|
type PhotoSize struct {
|
2015-06-26 08:53:20 +02:00
|
|
|
FileID string `json:"file_id"`
|
2015-06-25 18:25:02 +02:00
|
|
|
Width int `json:"width"`
|
|
|
|
Height int `json:"height"`
|
2016-01-03 23:54:24 +01:00
|
|
|
FileSize int `json:"file_size"` // optional
|
2015-06-25 18:25:02 +02:00
|
|
|
}
|
|
|
|
|
2016-01-03 23:54:24 +01:00
|
|
|
// Audio contains information about audio.
|
2015-06-25 18:25:02 +02:00
|
|
|
type Audio struct {
|
2015-08-18 03:40:42 +02:00
|
|
|
FileID string `json:"file_id"`
|
|
|
|
Duration int `json:"duration"`
|
2016-01-03 23:54:24 +01:00
|
|
|
Performer string `json:"performer"` // optional
|
|
|
|
Title string `json:"title"` // optional
|
|
|
|
MimeType string `json:"mime_type"` // optional
|
|
|
|
FileSize int `json:"file_size"` // optional
|
2015-06-25 18:25:02 +02:00
|
|
|
}
|
|
|
|
|
2016-01-03 23:54:24 +01:00
|
|
|
// Document contains information about a document.
|
2015-06-25 18:25:02 +02:00
|
|
|
type Document struct {
|
2016-04-13 15:22:58 +02:00
|
|
|
FileID string `json:"file_id"`
|
|
|
|
Thumbnail *PhotoSize `json:"thumb"` // optional
|
|
|
|
FileName string `json:"file_name"` // optional
|
|
|
|
MimeType string `json:"mime_type"` // optional
|
|
|
|
FileSize int `json:"file_size"` // optional
|
2015-06-25 18:25:02 +02:00
|
|
|
}
|
|
|
|
|
2016-01-03 23:54:24 +01:00
|
|
|
// Sticker contains information about a sticker.
|
2015-06-25 18:25:02 +02:00
|
|
|
type Sticker struct {
|
2016-04-13 15:22:58 +02:00
|
|
|
FileID string `json:"file_id"`
|
|
|
|
Width int `json:"width"`
|
|
|
|
Height int `json:"height"`
|
|
|
|
Thumbnail *PhotoSize `json:"thumb"` // optional
|
2016-05-21 03:34:56 +02:00
|
|
|
Emoji string `json:"emoji"` // optional
|
2016-04-13 15:22:58 +02:00
|
|
|
FileSize int `json:"file_size"` // optional
|
2015-06-25 18:25:02 +02:00
|
|
|
}
|
|
|
|
|
2016-01-03 23:54:24 +01:00
|
|
|
// Video contains information about a video.
|
2015-06-25 18:25:02 +02:00
|
|
|
type Video struct {
|
2016-04-13 15:22:58 +02:00
|
|
|
FileID string `json:"file_id"`
|
|
|
|
Width int `json:"width"`
|
|
|
|
Height int `json:"height"`
|
|
|
|
Duration int `json:"duration"`
|
|
|
|
Thumbnail *PhotoSize `json:"thumb"` // optional
|
|
|
|
MimeType string `json:"mime_type"` // optional
|
|
|
|
FileSize int `json:"file_size"` // optional
|
2015-06-25 18:25:02 +02:00
|
|
|
}
|
|
|
|
|
2016-01-03 23:54:24 +01:00
|
|
|
// Voice contains information about a voice.
|
2015-08-18 03:40:42 +02:00
|
|
|
type Voice struct {
|
|
|
|
FileID string `json:"file_id"`
|
|
|
|
Duration int `json:"duration"`
|
2016-01-03 23:54:24 +01:00
|
|
|
MimeType string `json:"mime_type"` // optional
|
|
|
|
FileSize int `json:"file_size"` // optional
|
2015-08-18 03:40:42 +02:00
|
|
|
}
|
|
|
|
|
2016-01-03 23:54:24 +01:00
|
|
|
// Contact contains information about a contact.
|
|
|
|
//
|
|
|
|
// Note that LastName and UserID may be empty.
|
2015-06-25 18:25:02 +02:00
|
|
|
type Contact struct {
|
|
|
|
PhoneNumber string `json:"phone_number"`
|
|
|
|
FirstName string `json:"first_name"`
|
2016-01-03 23:54:24 +01:00
|
|
|
LastName string `json:"last_name"` // optional
|
|
|
|
UserID int `json:"user_id"` // optional
|
2015-06-25 18:25:02 +02:00
|
|
|
}
|
|
|
|
|
2016-01-03 23:54:24 +01:00
|
|
|
// Location contains information about a place.
|
2015-06-25 18:25:02 +02:00
|
|
|
type Location struct {
|
2016-04-14 20:28:38 +02:00
|
|
|
Longitude float64 `json:"longitude"`
|
|
|
|
Latitude float64 `json:"latitude"`
|
2015-06-25 18:25:02 +02:00
|
|
|
}
|
|
|
|
|
2016-04-12 15:28:46 +02:00
|
|
|
// Venue contains information about a venue, including its Location.
|
|
|
|
type Venue struct {
|
|
|
|
Location Location `json:"location"`
|
|
|
|
Title string `json:"title"`
|
|
|
|
Address string `json:"address"`
|
|
|
|
FoursquareID string `json:"foursquare_id"` // optional
|
|
|
|
}
|
|
|
|
|
2016-02-28 17:13:44 +01:00
|
|
|
// UserProfilePhotos contains a set of user profile photos.
|
2015-06-25 18:25:02 +02:00
|
|
|
type UserProfilePhotos struct {
|
2016-04-09 22:30:16 +02:00
|
|
|
TotalCount int `json:"total_count"`
|
|
|
|
Photos [][]PhotoSize `json:"photos"`
|
2015-06-25 18:25:02 +02:00
|
|
|
}
|
|
|
|
|
2016-01-03 23:54:24 +01:00
|
|
|
// File contains information about a file to download from Telegram.
|
2015-09-19 17:46:20 +02:00
|
|
|
type File struct {
|
|
|
|
FileID string `json:"file_id"`
|
2016-01-03 23:54:24 +01:00
|
|
|
FileSize int `json:"file_size"` // optional
|
|
|
|
FilePath string `json:"file_path"` // optional
|
2015-09-19 17:46:20 +02:00
|
|
|
}
|
|
|
|
|
2015-09-19 17:53:32 +02:00
|
|
|
// Link returns a full path to the download URL for a File.
|
|
|
|
//
|
|
|
|
// It requires the Bot Token to create the link.
|
|
|
|
func (f *File) Link(token string) string {
|
2015-09-19 20:42:50 +02:00
|
|
|
return fmt.Sprintf(FileEndpoint, token, f.FilePath)
|
2015-09-19 17:53:32 +02:00
|
|
|
}
|
|
|
|
|
2015-06-26 08:53:20 +02:00
|
|
|
// ReplyKeyboardMarkup allows the Bot to set a custom keyboard.
|
2015-06-25 18:25:02 +02:00
|
|
|
type ReplyKeyboardMarkup struct {
|
2016-04-12 15:28:46 +02:00
|
|
|
Keyboard [][]KeyboardButton `json:"keyboard"`
|
|
|
|
ResizeKeyboard bool `json:"resize_keyboard"` // optional
|
|
|
|
OneTimeKeyboard bool `json:"one_time_keyboard"` // optional
|
|
|
|
Selective bool `json:"selective"` // optional
|
|
|
|
}
|
|
|
|
|
|
|
|
// KeyboardButton is a button within a custom keyboard.
|
|
|
|
type KeyboardButton struct {
|
|
|
|
Text string `json:"text"`
|
|
|
|
RequestContact bool `json:"request_contact"`
|
|
|
|
RequestLocation bool `json:"request_location"`
|
2015-06-25 18:25:02 +02:00
|
|
|
}
|
|
|
|
|
2015-06-26 08:53:20 +02:00
|
|
|
// ReplyKeyboardHide allows the Bot to hide a custom keyboard.
|
2015-06-25 18:25:02 +02:00
|
|
|
type ReplyKeyboardHide struct {
|
|
|
|
HideKeyboard bool `json:"hide_keyboard"`
|
2016-01-03 23:54:24 +01:00
|
|
|
Selective bool `json:"selective"` // optional
|
2015-06-25 18:25:02 +02:00
|
|
|
}
|
|
|
|
|
2016-11-25 06:50:35 +01:00
|
|
|
// ReplyKeyboardRemove allows the Bot to hide a custom keyboard.
|
|
|
|
type ReplyKeyboardRemove struct {
|
|
|
|
RemoveKeyboard bool `json:"remove_keyboard"`
|
|
|
|
Selective bool `json:"selective"`
|
|
|
|
}
|
|
|
|
|
2016-04-12 15:28:46 +02:00
|
|
|
// InlineKeyboardMarkup is a custom keyboard presented for an inline bot.
|
|
|
|
type InlineKeyboardMarkup struct {
|
|
|
|
InlineKeyboard [][]InlineKeyboardButton `json:"inline_keyboard"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// InlineKeyboardButton is a button within a custom keyboard for
|
|
|
|
// inline query responses.
|
|
|
|
//
|
|
|
|
// Note that some values are references as even an empty string
|
|
|
|
// will change behavior.
|
2016-10-03 17:47:19 +02:00
|
|
|
//
|
|
|
|
// CallbackGame, if set, MUST be first button in first row.
|
2016-04-12 15:28:46 +02:00
|
|
|
type InlineKeyboardButton struct {
|
2016-10-03 17:47:19 +02:00
|
|
|
Text string `json:"text"`
|
2016-12-26 15:59:52 +01:00
|
|
|
URL *string `json:"url,omitempty"` // optional
|
|
|
|
CallbackData *string `json:"callback_data,omitempty"` // optional
|
|
|
|
SwitchInlineQuery *string `json:"switch_inline_query,omitempty"` // optional
|
|
|
|
SwitchInlineQueryCurrentChat *string `json:"switch_inline_query_current_chat,omitempty"` // optional
|
|
|
|
CallbackGame *CallbackGame `json:"callback_game,omitempty"` // optional
|
2016-04-12 15:28:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// CallbackQuery is data sent when a keyboard button with callback data
|
|
|
|
// is clicked.
|
|
|
|
type CallbackQuery struct {
|
2016-04-13 15:22:58 +02:00
|
|
|
ID string `json:"id"`
|
|
|
|
From *User `json:"from"`
|
|
|
|
Message *Message `json:"message"` // optional
|
|
|
|
InlineMessageID string `json:"inline_message_id"` // optional
|
2016-10-03 17:47:19 +02:00
|
|
|
ChatInstance string `json:"chat_instance"`
|
|
|
|
Data string `json:"data"` // optional
|
|
|
|
GameShortName string `json:"game_short_name"` // optional
|
2016-04-12 15:28:46 +02:00
|
|
|
}
|
|
|
|
|
2016-01-03 23:54:24 +01:00
|
|
|
// ForceReply allows the Bot to have users directly reply to it without
|
|
|
|
// additional interaction.
|
2015-06-25 18:25:02 +02:00
|
|
|
type ForceReply struct {
|
|
|
|
ForceReply bool `json:"force_reply"`
|
2016-01-03 23:54:24 +01:00
|
|
|
Selective bool `json:"selective"` // optional
|
2015-06-25 18:25:02 +02:00
|
|
|
}
|
2016-01-01 07:10:19 +01:00
|
|
|
|
2016-05-22 17:16:28 +02:00
|
|
|
// ChatMember is information about a member in a chat.
|
|
|
|
type ChatMember struct {
|
|
|
|
User *User `json:"user"`
|
|
|
|
Status string `json:"status"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsCreator returns if the ChatMember was the creator of the chat.
|
|
|
|
func (chat ChatMember) IsCreator() bool { return chat.Status == "creator" }
|
|
|
|
|
|
|
|
// IsAdministrator returns if the ChatMember is a chat administrator.
|
|
|
|
func (chat ChatMember) IsAdministrator() bool { return chat.Status == "administrator" }
|
|
|
|
|
|
|
|
// IsMember returns if the ChatMember is a current member of the chat.
|
|
|
|
func (chat ChatMember) IsMember() bool { return chat.Status == "member" }
|
|
|
|
|
|
|
|
// HasLeft returns if the ChatMember left the chat.
|
|
|
|
func (chat ChatMember) HasLeft() bool { return chat.Status == "left" }
|
|
|
|
|
|
|
|
// WasKicked returns if the ChatMember was kicked from the chat.
|
|
|
|
func (chat ChatMember) WasKicked() bool { return chat.Status == "kicked" }
|
|
|
|
|
2016-10-03 17:47:19 +02:00
|
|
|
// Game is a game within Telegram.
|
|
|
|
type Game struct {
|
|
|
|
Title string `json:"title"`
|
|
|
|
Description string `json:"description"`
|
|
|
|
Photo []PhotoSize `json:"photo"`
|
|
|
|
Text string `json:"text"`
|
|
|
|
TextEntities []MessageEntity `json:"text_entities"`
|
|
|
|
Animation Animation `json:"animation"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Animation is a GIF animation demonstrating the game.
|
|
|
|
type Animation struct {
|
|
|
|
FileID string `json:"file_id"`
|
|
|
|
Thumb PhotoSize `json:"thumb"`
|
|
|
|
FileName string `json:"file_name"`
|
|
|
|
MimeType string `json:"mime_type"`
|
|
|
|
FileSize int `json:"file_size"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// GameHighScore is a user's score and position on the leaderboard.
|
|
|
|
type GameHighScore struct {
|
|
|
|
Position int `json:"position"`
|
|
|
|
User User `json:"user"`
|
|
|
|
Score int `json:"score"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// CallbackGame is for starting a game in an inline keyboard button.
|
|
|
|
type CallbackGame struct{}
|
|
|
|
|
|
|
|
// WebhookInfo is information about a currently set webhook.
|
|
|
|
type WebhookInfo struct {
|
|
|
|
URL string `json:"url"`
|
|
|
|
HasCustomCertificate bool `json:"has_custom_certificate"`
|
|
|
|
PendingUpdateCount int `json:"pending_update_count"`
|
|
|
|
LastErrorDate int `json:"last_error_date"` // optional
|
|
|
|
LastErrorMessage string `json:"last_error_message"` // optional
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsSet returns true if a webhook is currently set.
|
|
|
|
func (info WebhookInfo) IsSet() bool {
|
|
|
|
return info.URL != ""
|
|
|
|
}
|
|
|
|
|
2016-01-03 23:54:24 +01:00
|
|
|
// InlineQuery is a Query from Telegram for an inline request.
|
2016-01-01 07:10:19 +01:00
|
|
|
type InlineQuery struct {
|
2016-04-13 15:22:58 +02:00
|
|
|
ID string `json:"id"`
|
|
|
|
From *User `json:"from"`
|
|
|
|
Location *Location `json:"location"` // optional
|
|
|
|
Query string `json:"query"`
|
|
|
|
Offset string `json:"offset"`
|
2016-01-01 07:10:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// InlineQueryResultArticle is an inline query response article.
|
|
|
|
type InlineQueryResultArticle struct {
|
2016-04-13 22:45:51 +02:00
|
|
|
Type string `json:"type"` // required
|
|
|
|
ID string `json:"id"` // required
|
|
|
|
Title string `json:"title"` // required
|
|
|
|
InputMessageContent interface{} `json:"input_message_content,omitempty"` // required
|
2016-04-13 16:30:52 +02:00
|
|
|
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
2016-04-12 20:26:18 +02:00
|
|
|
URL string `json:"url"`
|
|
|
|
HideURL bool `json:"hide_url"`
|
|
|
|
Description string `json:"description"`
|
|
|
|
ThumbURL string `json:"thumb_url"`
|
|
|
|
ThumbWidth int `json:"thumb_width"`
|
|
|
|
ThumbHeight int `json:"thumb_height"`
|
2016-01-01 07:10:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// InlineQueryResultPhoto is an inline query response photo.
|
|
|
|
type InlineQueryResultPhoto struct {
|
2016-04-12 20:26:18 +02:00
|
|
|
Type string `json:"type"` // required
|
|
|
|
ID string `json:"id"` // required
|
|
|
|
URL string `json:"photo_url"` // required
|
|
|
|
MimeType string `json:"mime_type"`
|
|
|
|
Width int `json:"photo_width"`
|
|
|
|
Height int `json:"photo_height"`
|
|
|
|
ThumbURL string `json:"thumb_url"`
|
|
|
|
Title string `json:"title"`
|
|
|
|
Description string `json:"description"`
|
|
|
|
Caption string `json:"caption"`
|
2016-04-13 16:30:52 +02:00
|
|
|
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
2016-04-13 22:45:51 +02:00
|
|
|
InputMessageContent interface{} `json:"input_message_content,omitempty"`
|
2016-01-01 07:10:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// InlineQueryResultGIF is an inline query response GIF.
|
|
|
|
type InlineQueryResultGIF struct {
|
2016-04-12 20:26:18 +02:00
|
|
|
Type string `json:"type"` // required
|
|
|
|
ID string `json:"id"` // required
|
|
|
|
URL string `json:"gif_url"` // required
|
|
|
|
Width int `json:"gif_width"`
|
|
|
|
Height int `json:"gif_height"`
|
|
|
|
ThumbURL string `json:"thumb_url"`
|
|
|
|
Title string `json:"title"`
|
|
|
|
Caption string `json:"caption"`
|
2016-04-13 16:30:52 +02:00
|
|
|
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
2016-04-13 22:45:51 +02:00
|
|
|
InputMessageContent interface{} `json:"input_message_content,omitempty"`
|
2016-01-01 07:10:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// InlineQueryResultMPEG4GIF is an inline query response MPEG4 GIF.
|
|
|
|
type InlineQueryResultMPEG4GIF struct {
|
2016-04-12 20:26:18 +02:00
|
|
|
Type string `json:"type"` // required
|
|
|
|
ID string `json:"id"` // required
|
|
|
|
URL string `json:"mpeg4_url"` // required
|
|
|
|
Width int `json:"mpeg4_width"`
|
|
|
|
Height int `json:"mpeg4_height"`
|
|
|
|
ThumbURL string `json:"thumb_url"`
|
|
|
|
Title string `json:"title"`
|
|
|
|
Caption string `json:"caption"`
|
2016-04-13 16:30:52 +02:00
|
|
|
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
2016-04-13 22:45:51 +02:00
|
|
|
InputMessageContent interface{} `json:"input_message_content,omitempty"`
|
2016-01-01 07:10:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// InlineQueryResultVideo is an inline query response video.
|
|
|
|
type InlineQueryResultVideo struct {
|
2016-04-12 20:26:18 +02:00
|
|
|
Type string `json:"type"` // required
|
|
|
|
ID string `json:"id"` // required
|
|
|
|
URL string `json:"video_url"` // required
|
|
|
|
MimeType string `json:"mime_type"` // required
|
|
|
|
ThumbURL string `json:"thumb_url"`
|
|
|
|
Title string `json:"title"`
|
|
|
|
Caption string `json:"caption"`
|
|
|
|
Width int `json:"video_width"`
|
|
|
|
Height int `json:"video_height"`
|
|
|
|
Duration int `json:"video_duration"`
|
|
|
|
Description string `json:"description"`
|
2016-04-13 16:30:52 +02:00
|
|
|
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
2016-04-13 22:45:51 +02:00
|
|
|
InputMessageContent interface{} `json:"input_message_content,omitempty"`
|
2016-01-01 07:10:19 +01:00
|
|
|
}
|
2016-01-04 17:15:57 +01:00
|
|
|
|
2016-04-13 15:22:58 +02:00
|
|
|
// InlineQueryResultAudio is an inline query response audio.
|
|
|
|
type InlineQueryResultAudio struct {
|
|
|
|
Type string `json:"type"` // required
|
|
|
|
ID string `json:"id"` // required
|
|
|
|
URL string `json:"audio_url"` // required
|
|
|
|
Title string `json:"title"` // required
|
2016-10-03 17:47:19 +02:00
|
|
|
Caption string `json:"caption"`
|
2016-04-13 15:22:58 +02:00
|
|
|
Performer string `json:"performer"`
|
|
|
|
Duration int `json:"audio_duration"`
|
2016-04-13 16:30:52 +02:00
|
|
|
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
2016-04-13 22:45:51 +02:00
|
|
|
InputMessageContent interface{} `json:"input_message_content,omitempty"`
|
2016-04-13 15:22:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// InlineQueryResultVoice is an inline query response voice.
|
|
|
|
type InlineQueryResultVoice struct {
|
|
|
|
Type string `json:"type"` // required
|
|
|
|
ID string `json:"id"` // required
|
|
|
|
URL string `json:"voice_url"` // required
|
|
|
|
Title string `json:"title"` // required
|
2016-10-03 17:47:19 +02:00
|
|
|
Caption string `json:"caption"`
|
2016-04-13 15:22:58 +02:00
|
|
|
Duration int `json:"voice_duration"`
|
2016-04-13 16:30:52 +02:00
|
|
|
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
2016-04-13 22:45:51 +02:00
|
|
|
InputMessageContent interface{} `json:"input_message_content,omitempty"`
|
2016-04-13 15:22:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// InlineQueryResultDocument is an inline query response document.
|
|
|
|
type InlineQueryResultDocument struct {
|
|
|
|
Type string `json:"type"` // required
|
|
|
|
ID string `json:"id"` // required
|
|
|
|
Title string `json:"title"` // required
|
|
|
|
Caption string `json:"caption"`
|
|
|
|
URL string `json:"document_url"` // required
|
|
|
|
MimeType string `json:"mime_type"` // required
|
|
|
|
Description string `json:"description"`
|
2016-04-13 16:30:52 +02:00
|
|
|
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
2016-04-13 22:45:51 +02:00
|
|
|
InputMessageContent interface{} `json:"input_message_content,omitempty"`
|
2016-04-13 15:22:58 +02:00
|
|
|
ThumbURL string `json:"thumb_url"`
|
|
|
|
ThumbWidth int `json:"thumb_width"`
|
|
|
|
ThumbHeight int `json:"thumb_height"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// InlineQueryResultLocation is an inline query response location.
|
|
|
|
type InlineQueryResultLocation struct {
|
|
|
|
Type string `json:"type"` // required
|
|
|
|
ID string `json:"id"` // required
|
|
|
|
Latitude float64 `json:"latitude"` // required
|
|
|
|
Longitude float64 `json:"longitude"` // required
|
|
|
|
Title string `json:"title"` // required
|
2016-04-13 16:30:52 +02:00
|
|
|
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
2016-04-13 22:45:51 +02:00
|
|
|
InputMessageContent interface{} `json:"input_message_content,omitempty"`
|
2016-04-13 15:22:58 +02:00
|
|
|
ThumbURL string `json:"thumb_url"`
|
|
|
|
ThumbWidth int `json:"thumb_width"`
|
|
|
|
ThumbHeight int `json:"thumb_height"`
|
|
|
|
}
|
|
|
|
|
2016-10-03 17:47:19 +02:00
|
|
|
// InlineQueryResultGame is an inline query response game.
|
|
|
|
type InlineQueryResultGame struct {
|
|
|
|
Type string `json:"type"`
|
|
|
|
ID string `json:"id"`
|
|
|
|
GameShortName string `json:"game_short_name"`
|
|
|
|
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup"`
|
|
|
|
}
|
|
|
|
|
2016-01-04 17:15:57 +01:00
|
|
|
// ChosenInlineResult is an inline query result chosen by a User
|
|
|
|
type ChosenInlineResult struct {
|
2016-04-13 15:22:58 +02:00
|
|
|
ResultID string `json:"result_id"`
|
|
|
|
From *User `json:"from"`
|
|
|
|
Location *Location `json:"location"`
|
|
|
|
InlineMessageID string `json:"inline_message_id"`
|
|
|
|
Query string `json:"query"`
|
2016-01-04 17:15:57 +01:00
|
|
|
}
|
2016-04-12 15:56:05 +02:00
|
|
|
|
2016-04-12 15:59:47 +02:00
|
|
|
// InputTextMessageContent contains text for displaying
|
|
|
|
// as an inline query result.
|
2016-04-12 15:56:05 +02:00
|
|
|
type InputTextMessageContent struct {
|
|
|
|
Text string `json:"message_text"`
|
|
|
|
ParseMode string `json:"parse_mode"`
|
|
|
|
DisableWebPagePreview bool `json:"disable_web_page_preview"`
|
|
|
|
}
|
|
|
|
|
2016-04-12 15:59:47 +02:00
|
|
|
// InputLocationMessageContent contains a location for displaying
|
|
|
|
// as an inline query result.
|
2016-04-12 15:56:05 +02:00
|
|
|
type InputLocationMessageContent struct {
|
|
|
|
Latitude float64 `json:"latitude"`
|
|
|
|
Longitude float64 `json:"longitude"`
|
|
|
|
}
|
|
|
|
|
2016-04-12 15:59:47 +02:00
|
|
|
// InputVenueMessageContent contains a venue for displaying
|
|
|
|
// as an inline query result.
|
2016-04-12 15:56:05 +02:00
|
|
|
type InputVenueMessageContent struct {
|
|
|
|
Latitude float64 `json:"latitude"`
|
|
|
|
Longitude float64 `json:"longitude"`
|
|
|
|
Title string `json:"title"`
|
|
|
|
Address string `json:"address"`
|
|
|
|
FoursquareID string `json:"foursquare_id"`
|
|
|
|
}
|
|
|
|
|
2016-04-12 15:59:47 +02:00
|
|
|
// InputContactMessageContent contains a contact for displaying
|
|
|
|
// as an inline query result.
|
2016-04-12 15:56:05 +02:00
|
|
|
type InputContactMessageContent struct {
|
|
|
|
PhoneNumber string `json:"phone_number"`
|
|
|
|
FirstName string `json:"first_name"`
|
|
|
|
LastName string `json:"last_name"`
|
|
|
|
}
|