Add helpers, change some items to pointers, add more inline results.

bot-api-6.1
Syfaro 2016-04-13 08:22:58 -05:00
parent 109da1a19f
commit 1ceb22b273
2 changed files with 145 additions and 70 deletions

View File

@ -209,6 +209,17 @@ func NewVoiceShare(chatID int64, fileID string) VoiceConfig {
}
}
// NewContact allows you to send a shared contact.
func NewContact(chatID int64, phoneNumber, firstName string) ContactConfig {
return ContactConfig{
BaseChat: BaseChat{
ChatID: chatID,
},
PhoneNumber: phoneNumber,
FirstName: firstName,
}
}
// NewLocation shares your location.
//
// chatID is where to send it, latitude and longitude are coordinates.
@ -216,14 +227,25 @@ func NewLocation(chatID int64, latitude float64, longitude float64) LocationConf
return LocationConfig{
BaseChat: BaseChat{
ChatID: chatID,
ReplyToMessageID: 0,
ReplyMarkup: nil,
},
Latitude: latitude,
Longitude: longitude,
}
}
// NewVenue allows you to send a venue and its location.
func NewVenue(chatID int64, title, address string, latitude, longitude float64) VenueConfig {
return VenueConfig{
BaseChat: BaseChat{
ChatID: chatID,
},
Title: title,
Address: address,
Latitude: latitude,
Longitude: longitude,
}
}
// NewChatAction sets a chat action.
// Actions last for 5 seconds, or until your next action.
//

111
types.go
View File

@ -20,10 +20,10 @@ type APIResponse struct {
// Update is an update response, from GetUpdates.
type Update struct {
UpdateID int `json:"update_id"`
Message Message `json:"message"`
InlineQuery InlineQuery `json:"inline_query"`
ChosenInlineResult ChosenInlineResult `json:"chosen_inline_result"`
CallbackQuery CallbackQuery `json:"callback_query"`
Message *Message `json:"message"`
InlineQuery *InlineQuery `json:"inline_query"`
ChosenInlineResult *ChosenInlineResult `json:"chosen_inline_result"`
CallbackQuery *CallbackQuery `json:"callback_query"`
}
// User is a user on Telegram.
@ -91,28 +91,28 @@ func (c *Chat) IsChannel() bool {
// almost anything.
type Message struct {
MessageID int `json:"message_id"`
From User `json:"from"` // optional
From *User `json:"from"` // optional
Date int `json:"date"`
Chat Chat `json:"chat"`
ForwardFrom User `json:"forward_from"` // optional
Chat *Chat `json:"chat"`
ForwardFrom *User `json:"forward_from"` // optional
ForwardDate int `json:"forward_date"` // optional
ReplyToMessage *Message `json:"reply_to_message"` // optional
Text string `json:"text"` // optional
Entities []MessageEntity `json:"entities"` // optional
Audio Audio `json:"audio"` // optional
Document Document `json:"document"` // optional
Photo []PhotoSize `json:"photo"` // optional
Sticker Sticker `json:"sticker"` // optional
Video Video `json:"video"` // optional
Voice Voice `json:"voice"` // optional
Entities *[]MessageEntity `json:"entities"` // optional
Audio *Audio `json:"audio"` // optional
Document *Document `json:"document"` // optional
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
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
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
@ -200,7 +200,7 @@ type Audio struct {
// Document contains information about a document.
type Document struct {
FileID string `json:"file_id"`
Thumbnail PhotoSize `json:"thumb"` // optional
Thumbnail *PhotoSize `json:"thumb"` // optional
FileName string `json:"file_name"` // optional
MimeType string `json:"mime_type"` // optional
FileSize int `json:"file_size"` // optional
@ -211,7 +211,7 @@ type Sticker struct {
FileID string `json:"file_id"`
Width int `json:"width"`
Height int `json:"height"`
Thumbnail PhotoSize `json:"thumb"` // optional
Thumbnail *PhotoSize `json:"thumb"` // optional
FileSize int `json:"file_size"` // optional
}
@ -221,7 +221,7 @@ type Video struct {
Width int `json:"width"`
Height int `json:"height"`
Duration int `json:"duration"`
Thumbnail PhotoSize `json:"thumb"` // optional
Thumbnail *PhotoSize `json:"thumb"` // optional
MimeType string `json:"mime_type"` // optional
FileSize int `json:"file_size"` // optional
}
@ -320,8 +320,8 @@ type InlineKeyboardButton struct {
// is clicked.
type CallbackQuery struct {
ID string `json:"id"`
From User `json:"from"`
Message Message `json:"message"` // optional
From *User `json:"from"`
Message *Message `json:"message"` // optional
InlineMessageID string `json:"inline_message_id"` // optional
Data string `json:"data"` // optional
}
@ -336,8 +336,8 @@ type ForceReply struct {
// InlineQuery is a Query from Telegram for an inline request.
type InlineQuery struct {
ID string `json:"id"`
From User `json:"from"`
Location Location `json:"location"` // optional
From *User `json:"from"`
Location *Location `json:"location"` // optional
Query string `json:"query"`
Offset string `json:"offset"`
}
@ -418,11 +418,64 @@ type InlineQueryResultVideo struct {
InputMessageContent interface{} `json:"input_message_content"`
}
// 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
Performer string `json:"performer"`
Duration int `json:"audio_duration"`
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup"`
InputMessageContent interface{} `json:"input_message_content"`
}
// 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
Duration int `json:"voice_duration"`
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup"`
InputMessageContent interface{} `json:"input_message_content"`
}
// 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"`
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup"`
InputMessageContent interface{} `json:"input_message_content"`
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
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup"`
InputMessageContent interface{} `json:"input_message_content"`
ThumbURL string `json:"thumb_url"`
ThumbWidth int `json:"thumb_width"`
ThumbHeight int `json:"thumb_height"`
}
// ChosenInlineResult is an inline query result chosen by a User
type ChosenInlineResult struct {
ResultID string `json:"result_id"`
From User `json:"from"`
Location Location `json:"location"`
From *User `json:"from"`
Location *Location `json:"location"`
InlineMessageID string `json:"inline_message_id"`
Query string `json:"query"`
}