Skip to content

Commit db12d94

Browse files
author
Syfaro
committed
Add kick and unban methods, update some inline query result responses.
1 parent 18510df commit db12d94

File tree

4 files changed

+128
-63
lines changed

4 files changed

+128
-63
lines changed

bot.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,3 +502,38 @@ func (bot *BotAPI) AnswerCallbackQuery(config CallbackConfig) (APIResponse, erro
502502

503503
return bot.MakeRequest("answerCallbackQuery", v)
504504
}
505+
506+
// KickChatMember kicks a user from a chat. Note that this only will work
507+
// in supergroups, and requires the bot to be an admin. Also note they
508+
// will be unable to rejoin until they are unbanned.
509+
func (bot *BotAPI) KickChatMember(config ChatMemberConfig) (APIResponse, error) {
510+
v := url.Values{}
511+
512+
if config.SuperGroupUsername == "" {
513+
v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
514+
} else {
515+
v.Add("chat_id", config.SuperGroupUsername)
516+
}
517+
v.Add("user_id", strconv.Itoa(config.UserID))
518+
519+
bot.debugLog("kickChatMember", v, nil)
520+
521+
return bot.MakeRequest("kickChatMember", v)
522+
}
523+
524+
// UnbanChatMember unbans a user from a chat. Note that this only will work
525+
// in supergroups, and requires the bot to be an admin.
526+
func (bot *BotAPI) UnbanChatMember(config ChatMemberConfig) (APIResponse, error) {
527+
v := url.Values{}
528+
529+
if config.SuperGroupUsername == "" {
530+
v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
531+
} else {
532+
v.Add("chat_id", config.SuperGroupUsername)
533+
}
534+
v.Add("user_id", strconv.Itoa(config.UserID))
535+
536+
bot.debugLog("unbanChatMember", v, nil)
537+
538+
return bot.MakeRequest("unbanChatMember", v)
539+
}

configs.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,3 +559,9 @@ type CallbackConfig struct {
559559
Text string `json:"text"`
560560
ShowAlert bool `json:"show_alert"`
561561
}
562+
563+
type ChatMemberConfig struct {
564+
ChatID int64
565+
SuperGroupUsername string
566+
UserID int
567+
}

helpers.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,12 @@ func NewWebhookWithCert(link string, file interface{}) WebhookConfig {
285285
// NewInlineQueryResultArticle creates a new inline query article.
286286
func NewInlineQueryResultArticle(id, title, messageText string) InlineQueryResultArticle {
287287
return InlineQueryResultArticle{
288-
Type: "article",
289-
ID: id,
290-
Title: title,
291-
MessageText: messageText,
288+
Type: "article",
289+
ID: id,
290+
Title: title,
291+
InputMessageContent: InputTextMessageContent{
292+
Text: messageText,
293+
},
292294
}
293295
}
294296

types.go

Lines changed: 81 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -344,81 +344,78 @@ type InlineQuery struct {
344344

345345
// InlineQueryResultArticle is an inline query response article.
346346
type InlineQueryResultArticle struct {
347-
Type string `json:"type"` // required
348-
ID string `json:"id"` // required
349-
Title string `json:"title"` // required
350-
MessageText string `json:"message_text"` // required
351-
ParseMode string `json:"parse_mode"`
352-
DisableWebPagePreview bool `json:"disable_web_page_preview"`
353-
URL string `json:"url"`
354-
HideURL bool `json:"hide_url"`
355-
Description string `json:"description"`
356-
ThumbURL string `json:"thumb_url"`
357-
ThumbWidth int `json:"thumb_width"`
358-
ThumbHeight int `json:"thumb_height"`
347+
Type string `json:"type"` // required
348+
ID string `json:"id"` // required
349+
Title string `json:"title"` // required
350+
InputMessageContent interface{} `json:"input_message_content"` // required
351+
ReplyMarkup InlineKeyboardMarkup `json:"reply_markup"`
352+
URL string `json:"url"`
353+
HideURL bool `json:"hide_url"`
354+
Description string `json:"description"`
355+
ThumbURL string `json:"thumb_url"`
356+
ThumbWidth int `json:"thumb_width"`
357+
ThumbHeight int `json:"thumb_height"`
359358
}
360359

361360
// InlineQueryResultPhoto is an inline query response photo.
362361
type InlineQueryResultPhoto struct {
363-
Type string `json:"type"` // required
364-
ID string `json:"id"` // required
365-
URL string `json:"photo_url"` // required
366-
MimeType string `json:"mime_type"`
367-
Width int `json:"photo_width"`
368-
Height int `json:"photo_height"`
369-
ThumbURL string `json:"thumb_url"`
370-
Title string `json:"title"`
371-
Description string `json:"description"`
372-
Caption string `json:"caption"`
373-
MessageText string `json:"message_text"`
374-
ParseMode string `json:"parse_mode"`
375-
DisableWebPagePreview bool `json:"disable_web_page_preview"`
362+
Type string `json:"type"` // required
363+
ID string `json:"id"` // required
364+
URL string `json:"photo_url"` // required
365+
MimeType string `json:"mime_type"`
366+
Width int `json:"photo_width"`
367+
Height int `json:"photo_height"`
368+
ThumbURL string `json:"thumb_url"`
369+
Title string `json:"title"`
370+
Description string `json:"description"`
371+
Caption string `json:"caption"`
372+
ReplyMarkup InlineKeyboardMarkup `json:"reply_markup"`
373+
InputMessageContent interface{} `json:"input_message_content"`
376374
}
377375

378376
// InlineQueryResultGIF is an inline query response GIF.
379377
type InlineQueryResultGIF struct {
380-
Type string `json:"type"` // required
381-
ID string `json:"id"` // required
382-
URL string `json:"gif_url"` // required
383-
Width int `json:"gif_width"`
384-
Height int `json:"gif_height"`
385-
ThumbURL string `json:"thumb_url"`
386-
Title string `json:"title"`
387-
Caption string `json:"caption"`
388-
MessageText string `json:"message_text"`
389-
ParseMode string `json:"parse_mode"`
390-
DisableWebPagePreview bool `json:"disable_web_page_preview"`
378+
Type string `json:"type"` // required
379+
ID string `json:"id"` // required
380+
URL string `json:"gif_url"` // required
381+
Width int `json:"gif_width"`
382+
Height int `json:"gif_height"`
383+
ThumbURL string `json:"thumb_url"`
384+
Title string `json:"title"`
385+
Caption string `json:"caption"`
386+
ReplyMarkup InlineKeyboardMarkup `json:"reply_markup"`
387+
InputMessageContent interface{} `json:"input_message_content"`
391388
}
392389

393390
// InlineQueryResultMPEG4GIF is an inline query response MPEG4 GIF.
394391
type InlineQueryResultMPEG4GIF struct {
395-
Type string `json:"type"` // required
396-
ID string `json:"id"` // required
397-
URL string `json:"mpeg4_url"` // required
398-
Width int `json:"mpeg4_width"`
399-
Height int `json:"mpeg4_height"`
400-
ThumbURL string `json:"thumb_url"`
401-
Title string `json:"title"`
402-
Caption string `json:"caption"`
403-
MessageText string `json:"message_text"`
404-
ParseMode string `json:"parse_mode"`
405-
DisableWebPagePreview bool `json:"disable_web_page_preview"`
392+
Type string `json:"type"` // required
393+
ID string `json:"id"` // required
394+
URL string `json:"mpeg4_url"` // required
395+
Width int `json:"mpeg4_width"`
396+
Height int `json:"mpeg4_height"`
397+
ThumbURL string `json:"thumb_url"`
398+
Title string `json:"title"`
399+
Caption string `json:"caption"`
400+
ReplyMarkup InlineKeyboardMarkup `json:"reply_markup"`
401+
InputMessageContent interface{} `json:"input_message_content"`
406402
}
407403

408404
// InlineQueryResultVideo is an inline query response video.
409405
type InlineQueryResultVideo struct {
410-
Type string `json:"type"` // required
411-
ID string `json:"id"` // required
412-
URL string `json:"video_url"` // required
413-
MimeType string `json:"mime_type"` // required
414-
MessageText string `json:"message_text"` // required
415-
ParseMode string `json:"parse_mode"`
416-
DisableWebPagePreview bool `json:"disable_web_page_preview"`
417-
Width int `json:"video_width"`
418-
Height int `json:"video_height"`
419-
ThumbURL string `json:"thumb_url"`
420-
Title string `json:"title"`
421-
Description string `json:"description"`
406+
Type string `json:"type"` // required
407+
ID string `json:"id"` // required
408+
URL string `json:"video_url"` // required
409+
MimeType string `json:"mime_type"` // required
410+
ThumbURL string `json:"thumb_url"`
411+
Title string `json:"title"`
412+
Caption string `json:"caption"`
413+
Width int `json:"video_width"`
414+
Height int `json:"video_height"`
415+
Duration int `json:"video_duration"`
416+
Description string `json:"description"`
417+
ReplyMarkup InlineKeyboardMarkup `json:"reply_markup"`
418+
InputMessageContent interface{} `json:"input_message_content"`
422419
}
423420

424421
// ChosenInlineResult is an inline query result chosen by a User
@@ -427,3 +424,28 @@ type ChosenInlineResult struct {
427424
From User `json:"from"`
428425
Query string `json:"query"`
429426
}
427+
428+
type InputTextMessageContent struct {
429+
Text string `json:"message_text"`
430+
ParseMode string `json:"parse_mode"`
431+
DisableWebPagePreview bool `json:"disable_web_page_preview"`
432+
}
433+
434+
type InputLocationMessageContent struct {
435+
Latitude float64 `json:"latitude"`
436+
Longitude float64 `json:"longitude"`
437+
}
438+
439+
type InputVenueMessageContent struct {
440+
Latitude float64 `json:"latitude"`
441+
Longitude float64 `json:"longitude"`
442+
Title string `json:"title"`
443+
Address string `json:"address"`
444+
FoursquareID string `json:"foursquare_id"`
445+
}
446+
447+
type InputContactMessageContent struct {
448+
PhoneNumber string `json:"phone_number"`
449+
FirstName string `json:"first_name"`
450+
LastName string `json:"last_name"`
451+
}

0 commit comments

Comments
 (0)