all repos — telegram-bot-api @ 04f51c32513f07bbb8f8392715d5524040e2671a

Golang bindings for the Telegram Bot API

Add response parameters to error messages
Behrang Noruzi Niya behrangn@gmail.com
Sun, 04 Mar 2018 14:40:17 +0330
commit

04f51c32513f07bbb8f8392715d5524040e2671a

parent

5435d1d8eaf19425b40aebf050f5fda3280c00cc

2 files changed, 15 insertions(+), 2 deletions(-)

jump to
M bot.gobot.go

@@ -79,7 +79,11 @@ log.Printf("%s resp: %s", endpoint, bytes)

} if !apiResp.Ok { - return apiResp, errors.New(apiResp.Description) + parameters := ResponseParameters{} + if apiResp.Parameters != nil { + parameters = *apiResp.Parameters + } + return apiResp, Error{apiResp.Description, parameters} } return apiResp, nil
M types.gotypes.go

@@ -410,7 +410,7 @@ 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 - Pay bool `json:"pay,omitempty"` // optional + Pay bool `json:"pay,omitempty"` // optional } // CallbackQuery is data sent when a keyboard button with callback data

@@ -771,3 +771,12 @@ InvoicePayload string `json:"invoice_payload"`

ShippingOptionID string `json:"shipping_option_id,omitempty"` OrderInfo *OrderInfo `json:"order_info,omitempty"` } + +type Error struct { + Message string + ResponseParameters +} + +func (e Error) Error() string { + return e.Message +}