Fixes and comments

bot-api-6.1
MrYadro 2017-06-03 13:59:40 +07:00
parent 42d132b90a
commit 41814af2a0
No known key found for this signature in database
GPG Key ID: F46CD4085B2F9482
4 changed files with 32 additions and 28 deletions

10
bot.go
View File

@ -705,12 +705,13 @@ func (bot *BotAPI) GetGameHighScores(config GetGameHighScoresConfig) ([]GameHigh
return highScores, err return highScores, err
} }
// AnswerShippingQuery allows you to reply to Update with shipping_query parameter.
func (bot *BotAPI) AnswerShippingQuery(config ShippingConfig) (APIResponse, error) { func (bot *BotAPI) AnswerShippingQuery(config ShippingConfig) (APIResponse, error) {
v := url.Values{} v := url.Values{}
v.Add("shipping_query_id", config.ShippingQueryID) v.Add("shipping_query_id", config.ShippingQueryID)
v.Add("ok", strconv.FormatBool(config.Ok)) v.Add("ok", strconv.FormatBool(config.OK))
if config.Ok == true { if config.OK == true {
data, err := json.Marshal(config.ShippingOptions) data, err := json.Marshal(config.ShippingOptions)
if err != nil { if err != nil {
return APIResponse{}, err return APIResponse{}, err
@ -725,12 +726,13 @@ func (bot *BotAPI) AnswerShippingQuery(config ShippingConfig) (APIResponse, erro
return bot.MakeRequest("answerShippingQuery", v) return bot.MakeRequest("answerShippingQuery", v)
} }
// AnswerPreCheckoutQuery allows you to reply to Update with pre_checkout_query.
func (bot *BotAPI) AnswerPreCheckoutQuery(config PreCheckoutConfig) (APIResponse, error) { func (bot *BotAPI) AnswerPreCheckoutQuery(config PreCheckoutConfig) (APIResponse, error) {
v := url.Values{} v := url.Values{}
v.Add("pre_checkout_query_id", config.PreCheckoutQueryID) v.Add("pre_checkout_query_id", config.PreCheckoutQueryID)
v.Add("ok", strconv.FormatBool(config.Ok)) v.Add("ok", strconv.FormatBool(config.OK))
if config.Ok != true { if config.OK != true {
v.Add("error", config.ErrorMessage) v.Add("error", config.ErrorMessage)
} }

View File

@ -900,6 +900,7 @@ type ChatConfigWithUser struct {
UserID int UserID int
} }
// InvoiceConfig contains information for sendInvoice request.
type InvoiceConfig struct { type InvoiceConfig struct {
BaseChat BaseChat
Title string // required Title string // required
@ -909,7 +910,7 @@ type InvoiceConfig struct {
StartParameter string // required StartParameter string // required
Currency string // required Currency string // required
Prices *[]LabeledPrice // required Prices *[]LabeledPrice // required
PhotoUrl string PhotoURL string
PhotoSize int PhotoSize int
PhotoWidth int PhotoWidth int
PhotoHeight int PhotoHeight int
@ -936,8 +937,8 @@ func (config InvoiceConfig) values() (url.Values, error) {
return v, err return v, err
} }
v.Add("prices", string(data)) v.Add("prices", string(data))
if config.PhotoUrl != "" { if config.PhotoURL != "" {
v.Add("photo_url", config.PhotoUrl) v.Add("photo_url", config.PhotoURL)
} }
if config.PhotoSize != 0 { if config.PhotoSize != 0 {
v.Add("photo_size", strconv.Itoa(config.PhotoSize)) v.Add("photo_size", strconv.Itoa(config.PhotoSize))
@ -971,15 +972,17 @@ func (config InvoiceConfig) method() string {
return "sendInvoice" return "sendInvoice"
} }
// ShippingConfig contains information for answerShippingQuery request.
type ShippingConfig struct { type ShippingConfig struct {
ShippingQueryID string // required ShippingQueryID string // required
Ok bool // required OK bool // required
ShippingOptions *[]ShippingOption ShippingOptions *[]ShippingOption
ErrorMessage string ErrorMessage string
} }
// PreCheckoutConfig conatins information for answerPreCheckoutQuery request.
type PreCheckoutConfig struct { type PreCheckoutConfig struct {
PreCheckoutQueryID string // required PreCheckoutQueryID string // required
Ok bool // required OK bool // required
ErrorMessage string ErrorMessage string
} }

View File

@ -641,7 +641,8 @@ func NewCallbackWithAlert(id, text string) CallbackConfig {
} }
} }
func NewInvoice(chatID int64, title, description, payload, providerToken, startParameter, currency string, prices *[]LabeledPrice, photoUrl string, photoSize, photoWidth, photoHeight int, needName, needPhoneNumber, needEmail, needShippingAddress, isFlexible bool) InvoiceConfig { // NewInvoice created a new Invoice request to the user.
func NewInvoice(chatID int64, title, description, payload, providerToken, startParameter, currency string, prices *[]LabeledPrice) InvoiceConfig {
return InvoiceConfig{ return InvoiceConfig{
BaseChat: BaseChat{ChatID: chatID}, BaseChat: BaseChat{ChatID: chatID},
Title: title, Title: title,
@ -650,14 +651,5 @@ func NewInvoice(chatID int64, title, description, payload, providerToken, startP
ProviderToken: providerToken, ProviderToken: providerToken,
StartParameter: startParameter, StartParameter: startParameter,
Currency: currency, Currency: currency,
Prices: prices, Prices: prices}
PhotoUrl: photoUrl,
PhotoSize: photoSize,
PhotoWidth: photoWidth,
PhotoHeight: photoHeight,
NeedName: needName,
NeedPhoneNumber: needPhoneNumber,
NeedEmail: needEmail,
NeedShippingAddress: needShippingAddress,
IsFlexible: isFlexible}
} }

View File

@ -652,7 +652,7 @@ type InputContactMessageContent struct {
LastName string `json:"last_name"` LastName string `json:"last_name"`
} }
// Invoice contains information about invoice // Invoice contains basic information about an invoice.
type Invoice struct { type Invoice struct {
Title string `json:"title"` Title string `json:"title"`
Description string `json:"description"` Description string `json:"description"`
@ -661,11 +661,13 @@ type Invoice struct {
TotalAmount int `json:"total_amount"` TotalAmount int `json:"total_amount"`
} }
// LabeledPrice represents a portion of the price for goods or services.
type LabeledPrice struct { type LabeledPrice struct {
Label string `json:"label"` Label string `json:"label"`
Amount int `json:"amount"` Amount int `json:"amount"`
} }
// ShippingAddress represents a shipping address.
type ShippingAddress struct { type ShippingAddress struct {
CountryCode string `json:"country_code"` CountryCode string `json:"country_code"`
State string `json:"state"` State string `json:"state"`
@ -675,6 +677,7 @@ type ShippingAddress struct {
PostCode string `json:"post_code"` PostCode string `json:"post_code"`
} }
// OrderInfo represents information about an order.
type OrderInfo struct { type OrderInfo struct {
Name string `json:"name,omitempty"` Name string `json:"name,omitempty"`
PhoneNumber string `json:"phone_number,omitempty"` PhoneNumber string `json:"phone_number,omitempty"`
@ -682,12 +685,14 @@ type OrderInfo struct {
ShippingAddress *ShippingAddress `json:"shipping_address,omitempty"` ShippingAddress *ShippingAddress `json:"shipping_address,omitempty"`
} }
// ShippingOption represents one shipping option.
type ShippingOption struct { type ShippingOption struct {
ID string `json:"id"` ID string `json:"id"`
Title string `json:"title"` Title string `json:"title"`
Prices *[]LabeledPrice `json:"prices"` Prices *[]LabeledPrice `json:"prices"`
} }
// SuccessfulPayment contains basic information about a successful payment.
type SuccessfulPayment struct { type SuccessfulPayment struct {
Currency string `json:"currency"` Currency string `json:"currency"`
TotalAmount int `json:"total_amount"` TotalAmount int `json:"total_amount"`
@ -698,6 +703,7 @@ type SuccessfulPayment struct {
ProviderPaymentChargeID string `json:"provider_payment_charge_id"` ProviderPaymentChargeID string `json:"provider_payment_charge_id"`
} }
// ShippingQuery contains information about an incoming shipping query.
type ShippingQuery struct { type ShippingQuery struct {
ID string `json:"id"` ID string `json:"id"`
From *User `json:"from"` From *User `json:"from"`
@ -705,6 +711,7 @@ type ShippingQuery struct {
ShippingAddress *ShippingAddress `json:"shipping_address"` ShippingAddress *ShippingAddress `json:"shipping_address"`
} }
// PreCheckoutQuery contains information about an incoming pre-checkout query.
type PreCheckoutQuery struct { type PreCheckoutQuery struct {
ID string `json:"id"` ID string `json:"id"`
From *User `json:"from"` From *User `json:"from"`