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

View File

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

View File

@ -641,23 +641,15 @@ 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{
BaseChat: BaseChat{ChatID: chatID},
Title: title,
Description: description,
Payload: payload,
ProviderToken: providerToken,
StartParameter: startParameter,
Currency: currency,
Prices: prices,
PhotoUrl: photoUrl,
PhotoSize: photoSize,
PhotoWidth: photoWidth,
PhotoHeight: photoHeight,
NeedName: needName,
NeedPhoneNumber: needPhoneNumber,
NeedEmail: needEmail,
NeedShippingAddress: needShippingAddress,
IsFlexible: isFlexible}
BaseChat: BaseChat{ChatID: chatID},
Title: title,
Description: description,
Payload: payload,
ProviderToken: providerToken,
StartParameter: startParameter,
Currency: currency,
Prices: prices}
}

View File

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