Skip to content

Commit 8e945a9

Browse files
committed
fix: new types and no ffsjon
1 parent dea9904 commit 8e945a9

24 files changed

+344
-43293
lines changed

tgbotapi/callback_query_ffjson.go

Lines changed: 0 additions & 463 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package tgbotapi
2+
3+
import "net/url"
4+
5+
var _ Chattable = (*CreateInvoiceLinkConfig)(nil)
6+
7+
type CreateInvoiceLinkConfig struct {
8+
BaseChat
9+
10+
// Unique identifier of the business connection on behalf of which the message will be sent
11+
BusinessConnectionID string `json:"business_connection_id,omitempty"`
12+
}
13+
14+
func (v CreateInvoiceLinkConfig) method() string {
15+
return "createInvoiceLink"
16+
}
17+
18+
// Values returns url.Values representation of InvoiceConfig.
19+
//
20+
//goland:noinspection GoMixedReceiverTypes
21+
func (v CreateInvoiceLinkConfig) Values() (url.Values, error) {
22+
values, _ := v.BaseChat.Values()
23+
if v.BusinessConnectionID != "" {
24+
values.Add("business_connection_id", v.BusinessConnectionID)
25+
}
26+
return values, nil
27+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package tgbotapi
2+
3+
// ReplyParameters describes reply parameters for the message that is being sent.
4+
type ReplyParameters struct {
5+
MessageID int64 `json:"message_id"`
6+
7+
// Optional. If the message to be replied to is from a different chat, unique identifier for the chat or username of the channel (in the format @channelusername). Not supported for messages sent on behalf of a business account.
8+
ChatIDInt int64
9+
ChatIDStr string
10+
11+
AllowSendingWithoutReply bool `json:"allow_sending_without_reply,omitempty"` // Optional. Pass True if the message should be sent even if the specified message to be replied to is not found. Always False for replies in another chat or forum topic. Always True for messages sent on behalf of a business account.
12+
Quote string `json:"quote,omitempty"` // Optional. Quoted part of the message to be replied to; 0-1024 characters after entities parsing. The quote must be an exact substring of the message to be replied to, including bold, italic, underline, strikethrough, spoiler, and custom_emoji entities. The message will fail to send if the quote isn't found in the original message.
13+
QuoteParseMode string `json:"quote_parse_mode,omitempty"` // Optional. Mode for parsing entities in the quote. See formatting options for more details.
14+
QuoteEntities []MessageEntity `json:"quote_entities,omitempty"` // Optional. A JSON-serialized list of special entities that appear in the quote. It can be specified instead of quote_parse_mode.
15+
QuotePosition int64 `json:"quote_position,omitempty"` // Optional. Position of the quote in the original message in UTF-16 code units
16+
17+
}

tgbotapi/config_send_invoice.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package tgbotapi
2+
3+
import (
4+
"github.com/pquerna/ffjson/ffjson"
5+
"net/url"
6+
)
7+
8+
type LabeledPrice struct {
9+
Label string `json:"label"` // Portion label
10+
Amount int64 `json:"amount"` // Price of the product in the smallest units of the currency (integer, not float/double). For example, for a price of US$ 1.45 pass amount = 145. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies).
11+
}
12+
13+
var _ Chattable = (*InvoiceConfig)(nil)
14+
15+
type InvoiceConfig struct {
16+
BaseChat
17+
Title string `json:"title"` // Product name, 1-32 characters
18+
Description string `json:"description"` // Product description, 1-255 characters
19+
Payload string `json:"payload"` // Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use it for your internal processes.
20+
ProviderToken string `json:"provider_token,omitempty"` // Payment provider token, obtained via @BotFather. Pass an empty string for payments in Telegram Stars.
21+
Currency string `json:"currency"` // Three-letter ISO 4217 currency code, see more on currencies. Pass “XTR” for payments in Telegram Stars.
22+
Prices []LabeledPrice `json:"prices"` // Price breakdown, a JSON-serialized list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.). Must contain exactly one item for payments in Telegram Stars.
23+
MaxTipAmount int64 `json:"max_tip_amount,omitempty"` // The maximum accepted amount for tips in the smallest units of the currency (integer, not float/double). For example, for a maximum tip of US$ 1.45 pass max_tip_amount = 145. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). Defaults to 0. Not supported for payments in Telegram Stars.
24+
SuggestedTipAmounts []int64 `json:"suggested_tip_amounts,omitempty"` //A JSON-serialized array of suggested amounts of tips in the smallest units of the currency (integer, not float/double). At most 4 suggested tip amounts can be specified. The suggested tip amounts must be positive, passed in a strictly increased order and must not exceed max_tip_amount.
25+
StartParameter string `json:"start_parameter,omitempty"` // Unique deep-linking parameter. If left empty, forwarded copies of the sent message will have a Pay button, allowing multiple users to pay directly from the forwarded message, using the same invoice. If non-empty, forwarded copies of the sent message will have a URL button with a deep link to the bot (instead of a Pay button), with the value used as the start parameter
26+
ProviderData string `json:"provider_data,omitempty"` // JSON-serialized data about the invoice, which will be shared with the payment provider. A detailed description of required fields should be provided by the payment provider.
27+
PhotoURL string `json:"photo_url,omitempty"` // URL of the product photo for the invoice. Can be a photo of the goods or a marketing image for a service. People like it better when they see what they are paying for.
28+
PhotoSize int `json:"photo_size,omitempty"` // Photo size in bytes
29+
PhotoWidth int `json:"photo_width,omitempty"` // Photo width
30+
PhotoHeight int `json:"photo_height,omitempty"` // Photo height
31+
NeedName bool `json:"need_name,omitempty"` // Pass True if you require the user's full name to complete the order. Ignored for payments in Telegram Stars.
32+
NeedPhoneNumber bool `json:"need_phone_number,omitempty"` // Pass True if you require the user's phone number to complete the order. Ignored for payments in Telegram Stars.
33+
NeedEmail bool `json:"need_email,omitempty"` // Pass True if you require the user's email address to complete the order. Ignored for payments in Telegram Stars.
34+
NeedShippingAddress bool `json:"need_shipping_address,omitempty"` // Pass True if you require the user's shipping address to complete the order. Ignored for payments in Telegram Stars.
35+
36+
SendPhoneNumberToProvider bool `json:"send_phone_number_to_provider,omitempty"` // Pass True if the user's phone number should be sent to the provider. Ignored for payments in Telegram Stars.
37+
SendEmailToProvider bool `json:"send_email_to_provider,omitempty"` // Pass True if the user's email address should be sent to the provider. Ignored for payments in Telegram Stars.
38+
IsFlexible bool `json:"is_flexible,omitempty"` // Pass True if the final price depends on the shipping method. Ignored for payments in Telegram Stars.
39+
}
40+
41+
func (v InvoiceConfig) method() string {
42+
return "sendInvoice"
43+
}
44+
45+
// Values returns url.Values representation of InvoiceConfig.
46+
//
47+
//goland:noinspection GoMixedReceiverTypes
48+
func (v InvoiceConfig) Values() (url.Values, error) {
49+
values, _ := v.BaseChat.Values()
50+
values.Add("title", v.Title)
51+
values.Add("description", v.Description)
52+
values.Add("payload", v.Payload)
53+
values.Add("currency", v.Currency)
54+
if v.ProviderToken != "" {
55+
values.Add("provider_token", v.ProviderToken)
56+
}
57+
if len(v.Prices) > 0 {
58+
if b, err := ffjson.MarshalFast(v.Prices); err != nil {
59+
return nil, err
60+
} else {
61+
values.Add("prices", string(b))
62+
}
63+
}
64+
return values, nil
65+
}

tgbotapi/configs.go

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,22 @@ type Fileable interface {
106106
useExistingFile() bool
107107
}
108108

109-
// BaseChat is base type for all chat config types.
109+
// BaseChat is a base type for all chat config types.
110110
type BaseChat struct {
111111
ChatID int64 `json:"chat_id,omitempty"`
112112
ChannelUsername string `json:"channel_username,omitempty"`
113113
ReplyToMessageID int `json:"reply_to_message_id,omitempty"`
114114
ReplyMarkup interface{} `json:"reply_markup,omitempty"`
115115
DisableNotification bool `json:"disable_notification,omitempty"`
116+
117+
ProtectContent bool `json:"protect_content,omitempty"` // Protects the contents of the sent message from forwarding and saving
118+
119+
// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only
120+
MessageThreadID int64 `json:"message_thread_id,omitempty"`
121+
MessageEffectID string `json:"message_effect_id,omitempty"`
122+
AllowPaidBroadcast bool `json:"allow_paid_broadcast,omitempty"` // Pass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance
123+
124+
ReplyParameters *ReplyParameters `json:"reply_parameters,omitempty"` // Description of the message to reply to
116125
}
117126

118127
// Values returns url.Values representation of BaseChat
@@ -130,6 +139,39 @@ func (j BaseChat) Values() (url.Values, error) {
130139
values.Add("reply_to_message_id", strconv.Itoa(j.ReplyToMessageID))
131140
}
132141

142+
if j.ProtectContent {
143+
values.Add("protect_content", "true")
144+
}
145+
146+
if j.AllowPaidBroadcast {
147+
values.Add("allow_paid_broadcast", "true")
148+
}
149+
150+
if j.MessageThreadID != 0 {
151+
values.Add("message_thread_id", strconv.FormatInt(j.MessageThreadID, 10))
152+
}
153+
154+
if j.MessageEffectID != "" {
155+
values.Add("message_effect_id", j.MessageEffectID)
156+
}
157+
if j.AllowPaidBroadcast {
158+
values.Add("allow_paid_broadcast", "true")
159+
}
160+
161+
if j.ReplyParameters != nil {
162+
data, err := ffjson.Marshal(j.ReplyParameters)
163+
if err != nil {
164+
ffjson.Pool(data)
165+
return values, err
166+
}
167+
if string(data) == "null" {
168+
panic(fmt.Sprintf("string(data) == null, BaseChat: %v", j))
169+
}
170+
171+
values.Add("reply_parameters", string(data))
172+
ffjson.Pool(data)
173+
}
174+
133175
if j.ReplyMarkup != nil {
134176
data, err := ffjson.Marshal(j.ReplyMarkup)
135177
if err != nil {

0 commit comments

Comments
 (0)