Skip to content

Commit 1ceb22b

Browse files
author
Syfaro
committed
Add helpers, change some items to pointers, add more inline results.
1 parent 109da1a commit 1ceb22b

File tree

2 files changed

+145
-70
lines changed

2 files changed

+145
-70
lines changed

helpers.go

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,16 +209,38 @@ func NewVoiceShare(chatID int64, fileID string) VoiceConfig {
209209
}
210210
}
211211

212+
// NewContact allows you to send a shared contact.
213+
func NewContact(chatID int64, phoneNumber, firstName string) ContactConfig {
214+
return ContactConfig{
215+
BaseChat: BaseChat{
216+
ChatID: chatID,
217+
},
218+
PhoneNumber: phoneNumber,
219+
FirstName: firstName,
220+
}
221+
}
222+
212223
// NewLocation shares your location.
213224
//
214225
// chatID is where to send it, latitude and longitude are coordinates.
215226
func NewLocation(chatID int64, latitude float64, longitude float64) LocationConfig {
216227
return LocationConfig{
217228
BaseChat: BaseChat{
218-
ChatID: chatID,
219-
ReplyToMessageID: 0,
220-
ReplyMarkup: nil,
229+
ChatID: chatID,
230+
},
231+
Latitude: latitude,
232+
Longitude: longitude,
233+
}
234+
}
235+
236+
// NewVenue allows you to send a venue and its location.
237+
func NewVenue(chatID int64, title, address string, latitude, longitude float64) VenueConfig {
238+
return VenueConfig{
239+
BaseChat: BaseChat{
240+
ChatID: chatID,
221241
},
242+
Title: title,
243+
Address: address,
222244
Latitude: latitude,
223245
Longitude: longitude,
224246
}

types.go

Lines changed: 120 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ type APIResponse struct {
1919

2020
// Update is an update response, from GetUpdates.
2121
type Update struct {
22-
UpdateID int `json:"update_id"`
23-
Message Message `json:"message"`
24-
InlineQuery InlineQuery `json:"inline_query"`
25-
ChosenInlineResult ChosenInlineResult `json:"chosen_inline_result"`
26-
CallbackQuery CallbackQuery `json:"callback_query"`
22+
UpdateID int `json:"update_id"`
23+
Message *Message `json:"message"`
24+
InlineQuery *InlineQuery `json:"inline_query"`
25+
ChosenInlineResult *ChosenInlineResult `json:"chosen_inline_result"`
26+
CallbackQuery *CallbackQuery `json:"callback_query"`
2727
}
2828

2929
// User is a user on Telegram.
@@ -90,36 +90,36 @@ func (c *Chat) IsChannel() bool {
9090
// Message is returned by almost every request, and contains data about
9191
// almost anything.
9292
type Message struct {
93-
MessageID int `json:"message_id"`
94-
From User `json:"from"` // optional
95-
Date int `json:"date"`
96-
Chat Chat `json:"chat"`
97-
ForwardFrom User `json:"forward_from"` // optional
98-
ForwardDate int `json:"forward_date"` // optional
99-
ReplyToMessage *Message `json:"reply_to_message"` // optional
100-
Text string `json:"text"` // optional
101-
Entities []MessageEntity `json:"entities"` // optional
102-
Audio Audio `json:"audio"` // optional
103-
Document Document `json:"document"` // optional
104-
Photo []PhotoSize `json:"photo"` // optional
105-
Sticker Sticker `json:"sticker"` // optional
106-
Video Video `json:"video"` // optional
107-
Voice Voice `json:"voice"` // optional
108-
Caption string `json:"caption"` // optional
109-
Contact Contact `json:"contact"` // optional
110-
Location Location `json:"location"` // optional
111-
Venue Venue `json:"venue"` // optional
112-
NewChatMember User `json:"new_chat_member"` // optional
113-
LeftChatMember User `json:"left_chat_member"` // optional
114-
NewChatTitle string `json:"new_chat_title"` // optional
115-
NewChatPhoto []PhotoSize `json:"new_chat_photo"` // optional
116-
DeleteChatPhoto bool `json:"delete_chat_photo"` // optional
117-
GroupChatCreated bool `json:"group_chat_created"` // optional
118-
SuperGroupChatCreated bool `json:"supergroup_chat_created"` // optional
119-
ChannelChatCreated bool `json:"channel_chat_created"` // optional
120-
MigrateToChatID int64 `json:"migrate_to_chat_id"` // optional
121-
MigrateFromChatID int64 `json:"migrate_from_chat_id"` // optional
122-
PinnedMessage *Message `json:"pinned_message"` // optional
93+
MessageID int `json:"message_id"`
94+
From *User `json:"from"` // optional
95+
Date int `json:"date"`
96+
Chat *Chat `json:"chat"`
97+
ForwardFrom *User `json:"forward_from"` // optional
98+
ForwardDate int `json:"forward_date"` // optional
99+
ReplyToMessage *Message `json:"reply_to_message"` // optional
100+
Text string `json:"text"` // optional
101+
Entities *[]MessageEntity `json:"entities"` // optional
102+
Audio *Audio `json:"audio"` // optional
103+
Document *Document `json:"document"` // optional
104+
Photo *[]PhotoSize `json:"photo"` // optional
105+
Sticker *Sticker `json:"sticker"` // optional
106+
Video *Video `json:"video"` // optional
107+
Voice *Voice `json:"voice"` // optional
108+
Caption string `json:"caption"` // optional
109+
Contact *Contact `json:"contact"` // optional
110+
Location *Location `json:"location"` // optional
111+
Venue *Venue `json:"venue"` // optional
112+
NewChatMember *User `json:"new_chat_member"` // optional
113+
LeftChatMember *User `json:"left_chat_member"` // optional
114+
NewChatTitle string `json:"new_chat_title"` // optional
115+
NewChatPhoto *[]PhotoSize `json:"new_chat_photo"` // optional
116+
DeleteChatPhoto bool `json:"delete_chat_photo"` // optional
117+
GroupChatCreated bool `json:"group_chat_created"` // optional
118+
SuperGroupChatCreated bool `json:"supergroup_chat_created"` // optional
119+
ChannelChatCreated bool `json:"channel_chat_created"` // optional
120+
MigrateToChatID int64 `json:"migrate_to_chat_id"` // optional
121+
MigrateFromChatID int64 `json:"migrate_from_chat_id"` // optional
122+
PinnedMessage *Message `json:"pinned_message"` // optional
123123
}
124124

125125
// Time converts the message timestamp into a Time.
@@ -199,31 +199,31 @@ type Audio struct {
199199

200200
// Document contains information about a document.
201201
type Document struct {
202-
FileID string `json:"file_id"`
203-
Thumbnail PhotoSize `json:"thumb"` // optional
204-
FileName string `json:"file_name"` // optional
205-
MimeType string `json:"mime_type"` // optional
206-
FileSize int `json:"file_size"` // optional
202+
FileID string `json:"file_id"`
203+
Thumbnail *PhotoSize `json:"thumb"` // optional
204+
FileName string `json:"file_name"` // optional
205+
MimeType string `json:"mime_type"` // optional
206+
FileSize int `json:"file_size"` // optional
207207
}
208208

209209
// Sticker contains information about a sticker.
210210
type Sticker struct {
211-
FileID string `json:"file_id"`
212-
Width int `json:"width"`
213-
Height int `json:"height"`
214-
Thumbnail PhotoSize `json:"thumb"` // optional
215-
FileSize int `json:"file_size"` // optional
211+
FileID string `json:"file_id"`
212+
Width int `json:"width"`
213+
Height int `json:"height"`
214+
Thumbnail *PhotoSize `json:"thumb"` // optional
215+
FileSize int `json:"file_size"` // optional
216216
}
217217

218218
// Video contains information about a video.
219219
type Video struct {
220-
FileID string `json:"file_id"`
221-
Width int `json:"width"`
222-
Height int `json:"height"`
223-
Duration int `json:"duration"`
224-
Thumbnail PhotoSize `json:"thumb"` // optional
225-
MimeType string `json:"mime_type"` // optional
226-
FileSize int `json:"file_size"` // optional
220+
FileID string `json:"file_id"`
221+
Width int `json:"width"`
222+
Height int `json:"height"`
223+
Duration int `json:"duration"`
224+
Thumbnail *PhotoSize `json:"thumb"` // optional
225+
MimeType string `json:"mime_type"` // optional
226+
FileSize int `json:"file_size"` // optional
227227
}
228228

229229
// Voice contains information about a voice.
@@ -319,11 +319,11 @@ type InlineKeyboardButton struct {
319319
// CallbackQuery is data sent when a keyboard button with callback data
320320
// is clicked.
321321
type CallbackQuery struct {
322-
ID string `json:"id"`
323-
From User `json:"from"`
324-
Message Message `json:"message"` // optional
325-
InlineMessageID string `json:"inline_message_id"` // optional
326-
Data string `json:"data"` // optional
322+
ID string `json:"id"`
323+
From *User `json:"from"`
324+
Message *Message `json:"message"` // optional
325+
InlineMessageID string `json:"inline_message_id"` // optional
326+
Data string `json:"data"` // optional
327327
}
328328

329329
// ForceReply allows the Bot to have users directly reply to it without
@@ -335,11 +335,11 @@ type ForceReply struct {
335335

336336
// InlineQuery is a Query from Telegram for an inline request.
337337
type InlineQuery struct {
338-
ID string `json:"id"`
339-
From User `json:"from"`
340-
Location Location `json:"location"` // optional
341-
Query string `json:"query"`
342-
Offset string `json:"offset"`
338+
ID string `json:"id"`
339+
From *User `json:"from"`
340+
Location *Location `json:"location"` // optional
341+
Query string `json:"query"`
342+
Offset string `json:"offset"`
343343
}
344344

345345
// InlineQueryResultArticle is an inline query response article.
@@ -418,13 +418,66 @@ type InlineQueryResultVideo struct {
418418
InputMessageContent interface{} `json:"input_message_content"`
419419
}
420420

421+
// InlineQueryResultAudio is an inline query response audio.
422+
type InlineQueryResultAudio struct {
423+
Type string `json:"type"` // required
424+
ID string `json:"id"` // required
425+
URL string `json:"audio_url"` // required
426+
Title string `json:"title"` // required
427+
Performer string `json:"performer"`
428+
Duration int `json:"audio_duration"`
429+
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup"`
430+
InputMessageContent interface{} `json:"input_message_content"`
431+
}
432+
433+
// InlineQueryResultVoice is an inline query response voice.
434+
type InlineQueryResultVoice struct {
435+
Type string `json:"type"` // required
436+
ID string `json:"id"` // required
437+
URL string `json:"voice_url"` // required
438+
Title string `json:"title"` // required
439+
Duration int `json:"voice_duration"`
440+
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup"`
441+
InputMessageContent interface{} `json:"input_message_content"`
442+
}
443+
444+
// InlineQueryResultDocument is an inline query response document.
445+
type InlineQueryResultDocument struct {
446+
Type string `json:"type"` // required
447+
ID string `json:"id"` // required
448+
Title string `json:"title"` // required
449+
Caption string `json:"caption"`
450+
URL string `json:"document_url"` // required
451+
MimeType string `json:"mime_type"` // required
452+
Description string `json:"description"`
453+
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup"`
454+
InputMessageContent interface{} `json:"input_message_content"`
455+
ThumbURL string `json:"thumb_url"`
456+
ThumbWidth int `json:"thumb_width"`
457+
ThumbHeight int `json:"thumb_height"`
458+
}
459+
460+
// InlineQueryResultLocation is an inline query response location.
461+
type InlineQueryResultLocation struct {
462+
Type string `json:"type"` // required
463+
ID string `json:"id"` // required
464+
Latitude float64 `json:"latitude"` // required
465+
Longitude float64 `json:"longitude"` // required
466+
Title string `json:"title"` // required
467+
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup"`
468+
InputMessageContent interface{} `json:"input_message_content"`
469+
ThumbURL string `json:"thumb_url"`
470+
ThumbWidth int `json:"thumb_width"`
471+
ThumbHeight int `json:"thumb_height"`
472+
}
473+
421474
// ChosenInlineResult is an inline query result chosen by a User
422475
type ChosenInlineResult struct {
423-
ResultID string `json:"result_id"`
424-
From User `json:"from"`
425-
Location Location `json:"location"`
426-
InlineMessageID string `json:"inline_message_id"`
427-
Query string `json:"query"`
476+
ResultID string `json:"result_id"`
477+
From *User `json:"from"`
478+
Location *Location `json:"location"`
479+
InlineMessageID string `json:"inline_message_id"`
480+
Query string `json:"query"`
428481
}
429482

430483
// InputTextMessageContent contains text for displaying

0 commit comments

Comments
 (0)