Add some missing fields, generalize configs, remove unneeded methods.

bot-api-6.1
Syfaro 2018-10-08 23:05:24 -05:00
parent 1f859674f7
commit 4d758f17d4
5 changed files with 349 additions and 234 deletions

View File

@ -63,7 +63,7 @@ func main() {
``` ```
There are more examples on the [wiki](https://github.com/go-telegram-bot-api/telegram-bot-api/wiki) There are more examples on the [wiki](https://github.com/go-telegram-bot-api/telegram-bot-api/wiki)
with detailed information on how to do many differen kinds of things. with detailed information on how to do many different kinds of things.
It's a great place to get started on using keyboards, commands, or other It's a great place to get started on using keyboards, commands, or other
kinds of reply markup. kinds of reply markup.

110
bot.go
View File

@ -329,11 +329,9 @@ func (bot *BotAPI) GetUserProfilePhotos(config UserProfilePhotosConfig) (UserPro
// //
// Requires FileID. // Requires FileID.
func (bot *BotAPI) GetFile(config FileConfig) (File, error) { func (bot *BotAPI) GetFile(config FileConfig) (File, error) {
params := make(Params) params, _ := config.params()
params["file_id"] = config.FileID resp, err := bot.MakeRequest(config.method(), params)
resp, err := bot.MakeRequest("getFile", params)
if err != nil { if err != nil {
return File{}, err return File{}, err
} }
@ -437,12 +435,10 @@ func (bot *BotAPI) ListenForWebhook(pattern string) UpdatesChannel {
} }
// GetChat gets information about a chat. // GetChat gets information about a chat.
func (bot *BotAPI) GetChat(config ChatConfig) (Chat, error) { func (bot *BotAPI) GetChat(config ChatInfoConfig) (Chat, error) {
params := make(Params) params, _ := config.params()
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername) resp, err := bot.MakeRequest(config.method(), params)
resp, err := bot.MakeRequest("getChat", params)
if err != nil { if err != nil {
return Chat{}, err return Chat{}, err
} }
@ -457,12 +453,10 @@ func (bot *BotAPI) GetChat(config ChatConfig) (Chat, error) {
// //
// If none have been appointed, only the creator will be returned. // If none have been appointed, only the creator will be returned.
// Bots are not shown, even if they are an administrator. // Bots are not shown, even if they are an administrator.
func (bot *BotAPI) GetChatAdministrators(config ChatConfig) ([]ChatMember, error) { func (bot *BotAPI) GetChatAdministrators(config ChatAdministratorsConfig) ([]ChatMember, error) {
params := make(Params) params, _ := config.params()
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername) resp, err := bot.MakeRequest(config.method(), params)
resp, err := bot.MakeRequest("getChatAdministrators", params)
if err != nil { if err != nil {
return []ChatMember{}, err return []ChatMember{}, err
} }
@ -474,12 +468,10 @@ func (bot *BotAPI) GetChatAdministrators(config ChatConfig) ([]ChatMember, error
} }
// GetChatMembersCount gets the number of users in a chat. // GetChatMembersCount gets the number of users in a chat.
func (bot *BotAPI) GetChatMembersCount(config ChatConfig) (int, error) { func (bot *BotAPI) GetChatMembersCount(config ChatMemberCountConfig) (int, error) {
params := make(Params) params, _ := config.params()
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername) resp, err := bot.MakeRequest(config.method(), params)
resp, err := bot.MakeRequest("getChatMembersCount", params)
if err != nil { if err != nil {
return -1, err return -1, err
} }
@ -491,13 +483,10 @@ func (bot *BotAPI) GetChatMembersCount(config ChatConfig) (int, error) {
} }
// GetChatMember gets a specific chat member. // GetChatMember gets a specific chat member.
func (bot *BotAPI) GetChatMember(config ChatConfigWithUser) (ChatMember, error) { func (bot *BotAPI) GetChatMember(config GetChatMemberConfig) (ChatMember, error) {
params := make(Params) params, _ := config.params()
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername) resp, err := bot.MakeRequest(config.method(), params)
params.AddNonZero("user_id", config.UserID)
resp, err := bot.MakeRequest("getChatMember", params)
if err != nil { if err != nil {
return ChatMember{}, err return ChatMember{}, err
} }
@ -508,63 +497,11 @@ func (bot *BotAPI) GetChatMember(config ChatConfigWithUser) (ChatMember, error)
return member, err return member, err
} }
// UnbanChatMember unbans a user from a chat. Note that this only will work
// in supergroups and channels, and requires the bot to be an admin.
func (bot *BotAPI) UnbanChatMember(config ChatMemberConfig) (APIResponse, error) {
params := make(Params)
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername, config.ChannelUsername)
params.AddNonZero("user_id", config.UserID)
return bot.MakeRequest("unbanChatMember", params)
}
// RestrictChatMember to restrict a user in a supergroup. The bot must be an
//administrator in the supergroup for this to work and must have the
//appropriate admin rights. Pass True for all boolean parameters to lift
//restrictions from a user. Returns True on success.
func (bot *BotAPI) RestrictChatMember(config RestrictChatMemberConfig) (APIResponse, error) {
params := make(Params)
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername, config.ChannelUsername)
params.AddNonZero("user_id", config.UserID)
params.AddNonNilBool("can_send_messages", config.CanSendMessages)
params.AddNonNilBool("can_send_media_messages", config.CanSendMediaMessages)
params.AddNonNilBool("can_send_other_messages", config.CanSendOtherMessages)
params.AddNonNilBool("can_add_web_page_previews", config.CanAddWebPagePreviews)
params.AddNonZero64("until_date", config.UntilDate)
return bot.MakeRequest("restrictChatMember", params)
}
// PromoteChatMember add admin rights to user
func (bot *BotAPI) PromoteChatMember(config PromoteChatMemberConfig) (APIResponse, error) {
params := make(Params)
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername, config.ChannelUsername)
params.AddNonZero("user_id", config.UserID)
params.AddNonNilBool("can_change_info", config.CanChangeInfo)
params.AddNonNilBool("can_post_messages", config.CanPostMessages)
params.AddNonNilBool("can_edit_messages", config.CanEditMessages)
params.AddNonNilBool("can_delete_messages", config.CanDeleteMessages)
params.AddNonNilBool("can_invite_members", config.CanInviteUsers)
params.AddNonNilBool("can_restrict_members", config.CanRestrictMembers)
params.AddNonNilBool("can_pin_messages", config.CanPinMessages)
params.AddNonNilBool("can_promote_members", config.CanPromoteMembers)
return bot.MakeRequest("promoteChatMember", params)
}
// GetGameHighScores allows you to get the high scores for a game. // GetGameHighScores allows you to get the high scores for a game.
func (bot *BotAPI) GetGameHighScores(config GetGameHighScoresConfig) ([]GameHighScore, error) { func (bot *BotAPI) GetGameHighScores(config GetGameHighScoresConfig) ([]GameHighScore, error) {
v, err := config.params() params, _ := config.params()
if err != nil {
return nil, err
}
resp, err := bot.MakeRequest(config.method(), v) resp, err := bot.MakeRequest(config.method(), params)
if err != nil { if err != nil {
return []GameHighScore{}, err return []GameHighScore{}, err
} }
@ -576,12 +513,10 @@ func (bot *BotAPI) GetGameHighScores(config GetGameHighScoresConfig) ([]GameHigh
} }
// GetInviteLink get InviteLink for a chat // GetInviteLink get InviteLink for a chat
func (bot *BotAPI) GetInviteLink(config ChatConfig) (string, error) { func (bot *BotAPI) GetInviteLink(config ChatInviteLinkConfig) (string, error) {
params := make(Params) params, _ := config.params()
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername) resp, err := bot.MakeRequest(config.method(), params)
resp, err := bot.MakeRequest("exportChatInviteLink", params)
if err != nil { if err != nil {
return "", err return "", err
} }
@ -594,12 +529,9 @@ func (bot *BotAPI) GetInviteLink(config ChatConfig) (string, error) {
// GetStickerSet returns a StickerSet. // GetStickerSet returns a StickerSet.
func (bot *BotAPI) GetStickerSet(config GetStickerSetConfig) (StickerSet, error) { func (bot *BotAPI) GetStickerSet(config GetStickerSetConfig) (StickerSet, error) {
v, err := config.params() params, _ := config.params()
if err != nil {
return StickerSet{}, nil
}
resp, err := bot.MakeRequest(config.method(), v) resp, err := bot.MakeRequest(config.method(), params)
if err != nil { if err != nil {
return StickerSet{}, nil return StickerSet{}, nil
} }

View File

@ -140,16 +140,16 @@ type MessageConfig struct {
} }
func (config MessageConfig) params() (Params, error) { func (config MessageConfig) params() (Params, error) {
v, err := config.BaseChat.params() params, err := config.BaseChat.params()
if err != nil { if err != nil {
return v, err return params, err
} }
v.AddNonEmpty("text", config.Text) params.AddNonEmpty("text", config.Text)
v.AddBool("disable_web_page_preview", config.DisableWebPagePreview) params.AddBool("disable_web_page_preview", config.DisableWebPagePreview)
v.AddNonEmpty("parse_mode", config.ParseMode) params.AddNonEmpty("parse_mode", config.ParseMode)
return v, nil return params, nil
} }
func (config MessageConfig) method() string { func (config MessageConfig) method() string {
@ -165,15 +165,15 @@ type ForwardConfig struct {
} }
func (config ForwardConfig) params() (Params, error) { func (config ForwardConfig) params() (Params, error) {
v, err := config.BaseChat.params() params, err := config.BaseChat.params()
if err != nil { if err != nil {
return v, err return params, err
} }
v.AddNonZero64("from_chat_id", config.FromChatID) params.AddNonZero64("from_chat_id", config.FromChatID)
v.AddNonZero("message_id", config.MessageID) params.AddNonZero("message_id", config.MessageID)
return v, nil return params, nil
} }
func (config ForwardConfig) method() string { func (config ForwardConfig) method() string {
@ -216,19 +216,19 @@ type AudioConfig struct {
} }
func (config AudioConfig) params() (Params, error) { func (config AudioConfig) params() (Params, error) {
v, err := config.BaseChat.params() params, err := config.BaseChat.params()
if err != nil { if err != nil {
return v, err return params, err
} }
v.AddNonEmpty(config.name(), config.FileID) params.AddNonEmpty(config.name(), config.FileID)
v.AddNonZero("duration", config.Duration) params.AddNonZero("duration", config.Duration)
v.AddNonEmpty("performer", config.Performer) params.AddNonEmpty("performer", config.Performer)
v.AddNonEmpty("title", config.Title) params.AddNonEmpty("title", config.Title)
v.AddNonEmpty("caption", config.Caption) params.AddNonEmpty("caption", config.Caption)
v.AddNonEmpty("parse_mode", config.ParseMode) params.AddNonEmpty("parse_mode", config.ParseMode)
return v, nil return params, nil
} }
func (config AudioConfig) name() string { func (config AudioConfig) name() string {
@ -270,11 +270,11 @@ type StickerConfig struct {
} }
func (config StickerConfig) params() (Params, error) { func (config StickerConfig) params() (Params, error) {
v, err := config.BaseChat.params() params, err := config.BaseChat.params()
v.AddNonEmpty(config.name(), config.FileID) params.AddNonEmpty(config.name(), config.FileID)
return v, err return params, err
} }
func (config StickerConfig) name() string { func (config StickerConfig) name() string {
@ -288,20 +288,22 @@ func (config StickerConfig) method() string {
// VideoConfig contains information about a SendVideo request. // VideoConfig contains information about a SendVideo request.
type VideoConfig struct { type VideoConfig struct {
BaseFile BaseFile
Duration int Duration int
Caption string Caption string
ParseMode string ParseMode string
SupportsStreaming bool
} }
func (config VideoConfig) params() (Params, error) { func (config VideoConfig) params() (Params, error) {
v, err := config.BaseChat.params() params, err := config.BaseChat.params()
v.AddNonEmpty(config.name(), config.FileID) params.AddNonEmpty(config.name(), config.FileID)
v.AddNonZero("duration", config.Duration) params.AddNonZero("duration", config.Duration)
v.AddNonEmpty("caption", config.Caption) params.AddNonEmpty("caption", config.Caption)
v.AddNonEmpty("parse_mode", config.ParseMode) params.AddNonEmpty("parse_mode", config.ParseMode)
params.AddBool("supports_streaming", config.SupportsStreaming)
return v, err return params, err
} }
func (config VideoConfig) name() string { func (config VideoConfig) name() string {
@ -321,14 +323,14 @@ type AnimationConfig struct {
} }
func (config AnimationConfig) params() (Params, error) { func (config AnimationConfig) params() (Params, error) {
v, err := config.BaseChat.params() params, err := config.BaseChat.params()
v.AddNonEmpty(config.name(), config.FileID) params.AddNonEmpty(config.name(), config.FileID)
v.AddNonZero("duration", config.Duration) params.AddNonZero("duration", config.Duration)
v.AddNonEmpty("caption", config.Caption) params.AddNonEmpty("caption", config.Caption)
v.AddNonEmpty("parse_mode", config.ParseMode) params.AddNonEmpty("parse_mode", config.ParseMode)
return v, err return params, err
} }
func (config AnimationConfig) name() string { func (config AnimationConfig) name() string {
@ -347,13 +349,13 @@ type VideoNoteConfig struct {
} }
func (config VideoNoteConfig) params() (Params, error) { func (config VideoNoteConfig) params() (Params, error) {
v, err := config.BaseChat.params() params, err := config.BaseChat.params()
v.AddNonEmpty(config.name(), config.FileID) params.AddNonEmpty(config.name(), config.FileID)
v.AddNonZero("duration", config.Duration) params.AddNonZero("duration", config.Duration)
v.AddNonZero("length", config.Length) params.AddNonZero("length", config.Length)
return v, err return params, err
} }
func (config VideoNoteConfig) name() string { func (config VideoNoteConfig) name() string {
@ -373,14 +375,14 @@ type VoiceConfig struct {
} }
func (config VoiceConfig) params() (Params, error) { func (config VoiceConfig) params() (Params, error) {
v, err := config.BaseChat.params() params, err := config.BaseChat.params()
v.AddNonEmpty(config.name(), config.FileID) params.AddNonEmpty(config.name(), config.FileID)
v.AddNonZero("duration", config.Duration) params.AddNonZero("duration", config.Duration)
v.AddNonEmpty("caption", config.Caption) params.AddNonEmpty("caption", config.Caption)
v.AddNonEmpty("parse_mode", config.ParseMode) params.AddNonEmpty("parse_mode", config.ParseMode)
return v, err return params, err
} }
func (config VoiceConfig) name() string { func (config VoiceConfig) name() string {
@ -400,13 +402,13 @@ type LocationConfig struct {
} }
func (config LocationConfig) params() (Params, error) { func (config LocationConfig) params() (Params, error) {
v, err := config.BaseChat.params() params, err := config.BaseChat.params()
v.AddNonZeroFloat("latitude", config.Latitude) params.AddNonZeroFloat("latitude", config.Latitude)
v.AddNonZeroFloat("longitude", config.Longitude) params.AddNonZeroFloat("longitude", config.Longitude)
v.AddNonZero("live_period", config.LivePeriod) params.AddNonZero("live_period", config.LivePeriod)
return v, err return params, err
} }
func (config LocationConfig) method() string { func (config LocationConfig) method() string {
@ -421,12 +423,12 @@ type EditMessageLiveLocationConfig struct {
} }
func (config EditMessageLiveLocationConfig) params() (Params, error) { func (config EditMessageLiveLocationConfig) params() (Params, error) {
v, err := config.BaseEdit.params() params, err := config.BaseEdit.params()
v.AddNonZeroFloat("latitude", config.Latitude) params.AddNonZeroFloat("latitude", config.Latitude)
v.AddNonZeroFloat("longitude", config.Longitude) params.AddNonZeroFloat("longitude", config.Longitude)
return v, err return params, err
} }
func (config EditMessageLiveLocationConfig) method() string { func (config EditMessageLiveLocationConfig) method() string {
@ -457,15 +459,15 @@ type VenueConfig struct {
} }
func (config VenueConfig) params() (Params, error) { func (config VenueConfig) params() (Params, error) {
v, err := config.BaseChat.params() params, err := config.BaseChat.params()
v.AddNonZeroFloat("latitude", config.Latitude) params.AddNonZeroFloat("latitude", config.Latitude)
v.AddNonZeroFloat("longitude", config.Longitude) params.AddNonZeroFloat("longitude", config.Longitude)
v["title"] = config.Title params["title"] = config.Title
v["address"] = config.Address params["address"] = config.Address
v.AddNonEmpty("foursquare_id", config.FoursquareID) params.AddNonEmpty("foursquare_id", config.FoursquareID)
return v, err return params, err
} }
func (config VenueConfig) method() string { func (config VenueConfig) method() string {
@ -478,16 +480,19 @@ type ContactConfig struct {
PhoneNumber string PhoneNumber string
FirstName string FirstName string
LastName string LastName string
VCard string
} }
func (config ContactConfig) params() (Params, error) { func (config ContactConfig) params() (Params, error) {
v, err := config.BaseChat.params() params, err := config.BaseChat.params()
v["phone_number"] = config.PhoneNumber params["phone_number"] = config.PhoneNumber
v["first_name"] = config.FirstName params["first_name"] = config.FirstName
v["last_name"] = config.LastName
return v, err params.AddNonEmpty("last_name", config.LastName)
params.AddNonEmpty("vcard", config.VCard)
return params, err
} }
func (config ContactConfig) method() string { func (config ContactConfig) method() string {
@ -501,11 +506,11 @@ type GameConfig struct {
} }
func (config GameConfig) params() (Params, error) { func (config GameConfig) params() (Params, error) {
v, err := config.BaseChat.params() params, err := config.BaseChat.params()
v["game_short_name"] = config.GameShortName params["game_short_name"] = config.GameShortName
return v, err return params, err
} }
func (config GameConfig) method() string { func (config GameConfig) method() string {
@ -580,11 +585,11 @@ type ChatActionConfig struct {
} }
func (config ChatActionConfig) params() (Params, error) { func (config ChatActionConfig) params() (Params, error) {
v, err := config.BaseChat.params() params, err := config.BaseChat.params()
v["action"] = config.Action params["action"] = config.Action
return v, err return params, err
} }
func (config ChatActionConfig) method() string { func (config ChatActionConfig) method() string {
@ -600,13 +605,13 @@ type EditMessageTextConfig struct {
} }
func (config EditMessageTextConfig) params() (Params, error) { func (config EditMessageTextConfig) params() (Params, error) {
v, err := config.BaseEdit.params() params, err := config.BaseEdit.params()
v["text"] = config.Text params["text"] = config.Text
v.AddNonEmpty("parse_mode", config.ParseMode) params.AddNonEmpty("parse_mode", config.ParseMode)
v.AddBool("disable_web_page_preview", config.DisableWebPagePreview) params.AddBool("disable_web_page_preview", config.DisableWebPagePreview)
return v, err return params, err
} }
func (config EditMessageTextConfig) method() string { func (config EditMessageTextConfig) method() string {
@ -621,18 +626,37 @@ type EditMessageCaptionConfig struct {
} }
func (config EditMessageCaptionConfig) params() (Params, error) { func (config EditMessageCaptionConfig) params() (Params, error) {
v, err := config.BaseEdit.params() params, err := config.BaseEdit.params()
v["caption"] = config.Caption params["caption"] = config.Caption
v.AddNonEmpty("parse_mode", config.ParseMode) params.AddNonEmpty("parse_mode", config.ParseMode)
return v, err return params, err
} }
func (config EditMessageCaptionConfig) method() string { func (config EditMessageCaptionConfig) method() string {
return "editMessageCaption" return "editMessageCaption"
} }
// EditMessageMediaConfig contains information about editing a message's media.
type EditMessageMediaConfig struct {
BaseEdit
Media interface{}
}
func (EditMessageMediaConfig) method() string {
return "editMessageMedia"
}
func (config EditMessageMediaConfig) params() (Params, error) {
params, err := config.BaseEdit.params()
params.AddInterface("media", config.Media)
return params, err
}
// EditMessageReplyMarkupConfig allows you to modify the reply markup // EditMessageReplyMarkupConfig allows you to modify the reply markup
// of a message. // of a message.
type EditMessageReplyMarkupConfig struct { type EditMessageReplyMarkupConfig struct {
@ -674,6 +698,18 @@ type FileConfig struct {
FileID string FileID string
} }
func (FileConfig) method() string {
return "getFile"
}
func (config FileConfig) params() (Params, error) {
params := make(Params)
params["file_id"] = config.FileID
return params, nil
}
// UpdateConfig contains information about a GetUpdates request. // UpdateConfig contains information about a GetUpdates request.
type UpdateConfig struct { type UpdateConfig struct {
Offset int Offset int
@ -700,6 +736,7 @@ type WebhookConfig struct {
URL *url.URL URL *url.URL
Certificate interface{} Certificate interface{}
MaxConnections int MaxConnections int
AllowedUpdates []string
} }
func (config WebhookConfig) method() string { func (config WebhookConfig) method() string {
@ -714,6 +751,7 @@ func (config WebhookConfig) params() (Params, error) {
} }
params.AddNonZero("max_connections", config.MaxConnections) params.AddNonZero("max_connections", config.MaxConnections)
params.AddInterface("allowed_updates", config.AllowedUpdates)
return params, nil return params, nil
} }
@ -932,6 +970,60 @@ type ChatConfig struct {
SuperGroupUsername string SuperGroupUsername string
} }
func (config ChatConfig) params() (Params, error) {
params := make(Params)
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
return params, nil
}
// ChatInfoConfig contains information about getting chat information.
type ChatInfoConfig struct {
ChatConfig
}
func (ChatInfoConfig) method() string {
return "getChat"
}
// ChatMemberCountConfig contains information about getting the number of users in a chat.
type ChatMemberCountConfig struct {
ChatConfig
}
func (ChatMemberCountConfig) method() string {
return "getChatMembersCount"
}
// ChatAdministratorsConfig contains information about getting chat administrators.
type ChatAdministratorsConfig struct {
ChatConfig
}
func (ChatAdministratorsConfig) method() string {
return "getChatAdministrators"
}
// ChatInviteLinkConfig contains information about getting a chat link.
//
// Note that generating a new link will revoke any previous links.
type ChatInviteLinkConfig struct {
ChatConfig
}
func (ChatInviteLinkConfig) method() string {
return "exportChatInviteLink"
}
func (config ChatInviteLinkConfig) params() (Params, error) {
params := make(Params)
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
return params, nil
}
// LeaveChatConfig allows you to leave a chat. // LeaveChatConfig allows you to leave a chat.
type LeaveChatConfig struct { type LeaveChatConfig struct {
ChatID int64 ChatID int64
@ -950,65 +1042,86 @@ func (config LeaveChatConfig) params() (Params, error) {
return params, nil return params, nil
} }
// ChatConfigWithUser contains information about getting information on // ChatConfigWithUser contains information about a chat and a user.
// a specific user within a chat.
type ChatConfigWithUser struct { type ChatConfigWithUser struct {
ChatID int64 ChatID int64
SuperGroupUsername string SuperGroupUsername string
UserID int UserID int
} }
func (config ChatConfigWithUser) params() (Params, error) {
params := make(Params)
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
params.AddNonZero("user_id", config.UserID)
return params, nil
}
// GetChatMemberConfig is information about getting a specific member in a chat.
type GetChatMemberConfig struct {
ChatConfigWithUser
}
func (GetChatMemberConfig) method() string {
return "getChatMember"
}
// InvoiceConfig contains information for sendInvoice request. // InvoiceConfig contains information for sendInvoice request.
type InvoiceConfig struct { type InvoiceConfig struct {
BaseChat BaseChat
Title string // required Title string // required
Description string // required Description string // required
Payload string // required Payload string // required
ProviderToken string // required ProviderToken string // required
StartParameter string // required StartParameter string // required
Currency string // required Currency string // required
Prices *[]LabeledPrice // required Prices *[]LabeledPrice // required
ProviderData string ProviderData string
PhotoURL string PhotoURL string
PhotoSize int PhotoSize int
PhotoWidth int PhotoWidth int
PhotoHeight int PhotoHeight int
NeedName bool NeedName bool
NeedPhoneNumber bool NeedPhoneNumber bool
NeedEmail bool NeedEmail bool
NeedShippingAddress bool NeedShippingAddress bool
IsFlexible bool SendPhoneNumberToProvider bool
SendEmailToProvider bool
IsFlexible bool
} }
func (config InvoiceConfig) params() (Params, error) { func (config InvoiceConfig) params() (Params, error) {
v, err := config.BaseChat.params() params, err := config.BaseChat.params()
if err != nil { if err != nil {
return v, err return params, err
} }
v["title"] = config.Title params["title"] = config.Title
v["description"] = config.Description params["description"] = config.Description
v["payload"] = config.Payload params["payload"] = config.Payload
v["provider_token"] = config.ProviderToken params["provider_token"] = config.ProviderToken
v["start_parameter"] = config.StartParameter params["start_parameter"] = config.StartParameter
v["currency"] = config.Currency params["currency"] = config.Currency
if err = v.AddInterface("prices", config.Prices); err != nil { if err = params.AddInterface("prices", config.Prices); err != nil {
return v, err return params, err
} }
v.AddNonEmpty("provider_data", config.ProviderData) params.AddNonEmpty("provider_data", config.ProviderData)
v.AddNonEmpty("photo_url", config.PhotoURL) params.AddNonEmpty("photo_url", config.PhotoURL)
v.AddNonZero("photo_size", config.PhotoSize) params.AddNonZero("photo_size", config.PhotoSize)
v.AddNonZero("photo_width", config.PhotoWidth) params.AddNonZero("photo_width", config.PhotoWidth)
v.AddNonZero("photo_height", config.PhotoHeight) params.AddNonZero("photo_height", config.PhotoHeight)
v.AddBool("need_name", config.NeedName) params.AddBool("need_name", config.NeedName)
v.AddBool("need_phone_number", config.NeedPhoneNumber) params.AddBool("need_phone_number", config.NeedPhoneNumber)
v.AddBool("need_email", config.NeedEmail) params.AddBool("need_email", config.NeedEmail)
v.AddBool("need_shipping_address", config.NeedShippingAddress) params.AddBool("need_shipping_address", config.NeedShippingAddress)
v.AddBool("is_flexible", config.IsFlexible) params.AddBool("is_flexible", config.IsFlexible)
params.AddBool("send_phone_number_to_provider", config.SendPhoneNumberToProvider)
params.AddBool("send_email_to_provider", config.SendEmailToProvider)
return v, nil return params, nil
} }
func (config InvoiceConfig) method() string { func (config InvoiceConfig) method() string {

View File

@ -302,16 +302,50 @@ func NewMediaGroup(chatID int64, files []interface{}) MediaGroupConfig {
// NewInputMediaPhoto creates a new InputMediaPhoto. // NewInputMediaPhoto creates a new InputMediaPhoto.
func NewInputMediaPhoto(media string) InputMediaPhoto { func NewInputMediaPhoto(media string) InputMediaPhoto {
return InputMediaPhoto{ return InputMediaPhoto{
Type: "photo", BaseInputMedia{
Media: media, Type: "photo",
Media: media,
},
} }
} }
// NewInputMediaVideo creates a new InputMediaVideo. // NewInputMediaVideo creates a new InputMediaVideo.
func NewInputMediaVideo(media string) InputMediaVideo { func NewInputMediaVideo(media string) InputMediaVideo {
return InputMediaVideo{ return InputMediaVideo{
Type: "video", BaseInputMedia: BaseInputMedia{
Media: media, Type: "video",
Media: media,
},
}
}
// NewInputMediaAnimation creates a new InputMediaAnimation.
func NewInputMediaAnimation(media string) InputMediaAnimation {
return InputMediaAnimation{
BaseInputMedia: BaseInputMedia{
Type: "animation",
Media: media,
},
}
}
// NewInputMediaAudio creates a new InputMediaAudio.
func NewInputMediaAudio(media string) InputMediaAudio {
return InputMediaAudio{
BaseInputMedia: BaseInputMedia{
Type: "audio",
Media: media,
},
}
}
// NewInputMediaDocument creates a new InputMediaDocument.
func NewInputMediaDocument(media string) InputMediaDocument {
return InputMediaDocument{
BaseInputMedia: BaseInputMedia{
Type: "document",
Media: media,
},
} }
} }

View File

@ -175,6 +175,7 @@ type Message struct {
PinnedMessage *Message `json:"pinned_message"` // optional PinnedMessage *Message `json:"pinned_message"` // optional
Invoice *Invoice `json:"invoice"` // optional Invoice *Invoice `json:"invoice"` // optional
SuccessfulPayment *SuccessfulPayment `json:"successful_payment"` // optional SuccessfulPayment *SuccessfulPayment `json:"successful_payment"` // optional
ConnectedWebsite string `json:"connected_website"` // optional
PassportData *PassportData `json:"passport_data,omitempty"` // optional PassportData *PassportData `json:"passport_data,omitempty"` // optional
} }
@ -367,6 +368,7 @@ type Contact struct {
FirstName string `json:"first_name"` FirstName string `json:"first_name"`
LastName string `json:"last_name"` // optional LastName string `json:"last_name"` // optional
UserID int `json:"user_id"` // optional UserID int `json:"user_id"` // optional
VCard string `json:"vcard"` // optional
} }
// Location contains information about a place. // Location contains information about a place.
@ -692,6 +694,21 @@ type InlineQueryResultLocation struct {
ThumbHeight int `json:"thumb_height"` ThumbHeight int `json:"thumb_height"`
} }
// InlineQueryResultContact is an inline query response contact.
type InlineQueryResultContact struct {
Type string `json:"type"` // required
ID string `json:"id"` // required
PhoneNumber string `json:"phone_number"` // required
FirstName string `json:"first_name"` // required
LastName string `json:"last_name"`
VCard string `json:"vcard"`
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
InputMessageContent interface{} `json:"input_message_content,omitempty"`
ThumbURL string `json:"thumb_url"`
ThumbWidth int `json:"thumb_width"`
ThumbHeight int `json:"thumb_height"`
}
// InlineQueryResultGame is an inline query response game. // InlineQueryResultGame is an inline query response game.
type InlineQueryResultGame struct { type InlineQueryResultGame struct {
Type string `json:"type"` Type string `json:"type"`
@ -740,6 +757,7 @@ type InputContactMessageContent struct {
PhoneNumber string `json:"phone_number"` PhoneNumber string `json:"phone_number"`
FirstName string `json:"first_name"` FirstName string `json:"first_name"`
LastName string `json:"last_name"` LastName string `json:"last_name"`
VCard string `json:"vcard"`
} }
// Invoice contains basic information about an invoice. // Invoice contains basic information about an invoice.
@ -820,29 +838,47 @@ type StickerSet struct {
Stickers []Sticker `json:"stickers"` Stickers []Sticker `json:"stickers"`
} }
// InputMediaPhoto is a photo to send as part of a media group. // BaseInputMedia is a base type for the InputMedia types.
// type BaseInputMedia struct {
// Telegram recommends to use a file_id instead of uploading.
type InputMediaPhoto struct {
Type string `json:"type"` Type string `json:"type"`
Media string `json:"media"` Media string `json:"media"`
Caption string `json:"caption"` Caption string `json:"caption"`
ParseMode string `json:"parse_mode"` ParseMode string `json:"parse_mode"`
} }
// InputMediaPhoto is a photo to send as part of a media group.
type InputMediaPhoto struct {
BaseInputMedia
}
// InputMediaVideo is a video to send as part of a media group. // InputMediaVideo is a video to send as part of a media group.
//
// Telegram recommends to use a file_id instead of uploading.
type InputMediaVideo struct { type InputMediaVideo struct {
Type string `json:"type"` BaseInputMedia
Media string `json:"media"` Width int `json:"width"`
// thumb intentionally missing as it is not currently compatible Height int `json:"height"`
Caption string `json:"caption"` Duration int `json:"duration"`
ParseMode string `json:"parse_mode"` SupportsStreaming bool `json:"supports_streaming"`
Width int `json:"width"` }
Height int `json:"height"`
Duration int `json:"duration"` // InputMediaAnimation is an animation to send as part of a media group.
SupportsStreaming bool `json:"supports_streaming"` type InputMediaAnimation struct {
BaseInputMedia
Width int `json:"width"`
Height int `json:"height"`
Duration int `json:"duration"`
}
// InputMediaAudio is a audio to send as part of a media group.
type InputMediaAudio struct {
BaseInputMedia
Duration int `json:"duration"`
Performer string `json:"performer"`
Title string `json:"title"`
}
// InputMediaDocument is a audio to send as part of a media group.
type InputMediaDocument struct {
BaseInputMedia
} }
// Error is an error containing extra information returned by the Telegram API. // Error is an error containing extra information returned by the Telegram API.