Skip to content

Commit

Permalink
Bot API v8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
IRus committed Dec 9, 2024
1 parent 8baf125 commit 6b65ef7
Show file tree
Hide file tree
Showing 16 changed files with 61,467 additions and 13 deletions.
5 changes: 0 additions & 5 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "gradle"
Expand Down
3 changes: 1 addition & 2 deletions core-gen/src/main/kotlin/Generate.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import kotlinx.serialization.json.Json
fun main() {
// https://ark0f.github.io/tg-bot-api/custom.json
val apiJson = {}::class.java
.getResource("api800.json")
.getResource("api810.json")
?.readText()
?: error("custom.json not found")

Expand Down Expand Up @@ -66,7 +66,6 @@ private val modelPackageName = "$basePackageName.model"
private val methodPackageName = "$basePackageName.method"

private val botMethodType = ClassName("io.heapy.kotbot.bot", "Method")
private val kotbotType = ClassName("io.heapy.kotbot.bot", "Kotbot")
private val responseType = ClassName("io.heapy.kotbot.bot", "Response")
private val jvmInlineAnnotation = ClassName("kotlin.jvm", "JvmInline")
private val serializableAnnotation = ClassName("kotlinx.serialization", "Serializable")
Expand Down
1 change: 1 addition & 0 deletions core-gen/src/main/kotlin/Parse.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ fun main() {
"api740",
"api790",
"api800",
"api810",
).forEach { v ->
val input = rootPath.resolve(v).readText()
val output = processVersion(input)
Expand Down
15,131 changes: 15,131 additions & 0 deletions core-gen/src/main/resources/api810

Large diffs are not rendered by default.

17,411 changes: 17,411 additions & 0 deletions core-gen/src/main/resources/api810.json

Large diffs are not rendered by default.

6,495 changes: 6,495 additions & 0 deletions core-gen/src/main/resources/api810.md

Large diffs are not rendered by default.

22,312 changes: 22,312 additions & 0 deletions core-gen/src/main/resources/api810_v2.json

Large diffs are not rendered by default.

48 changes: 46 additions & 2 deletions core-gen/src/main/resources/latest.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@
> Subscribe to @BotNews to be the first to know about the latest updates and join the discussion in @BotTalk

#### December 4, 2024


Bot API 8.1


* Added the field nanostar_amount to the class StarTransaction.
* Added the class TransactionPartnerAffiliateProgram for transactions pertaining to incoming affiliate commissions.
* Added the class AffiliateInfo and the field affiliate to the class TransactionPartnerUser, allowing bots to identify the relevant affiliate in transactions with an affiliate commission.


#### November 17, 2024


Expand Down Expand Up @@ -5693,7 +5704,7 @@ Use this method to create a link for an invoice. Returns the created invoice lin
| provider_token | String | Optional | Payment provider token, obtained via @BotFather. Pass an empty string for payments in Telegram Stars. |
| currency | String | Yes | Three-letter ISO 4217 currency code, see more on currencies. Pass “XTR” for payments in Telegram Stars. |
| prices | Array of LabeledPrice | Yes | 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. |
| subscription_period | Integer | Optional | The number of seconds the subscription will be active for before the next payment. The currency must be set to “XTR” (Telegram Stars) if the parameter is used. Currently, it must always be 2592000 (30 days) if specified. Any number of subscriptions can be active for a given bot at the same time, including multiple concurrent subscriptions from the same user. |
| subscription_period | Integer | Optional | The number of seconds the subscription will be active for before the next payment. The currency must be set to “XTR” (Telegram Stars) if the parameter is used. Currently, it must always be 2592000 (30 days) if specified. Any number of subscriptions can be active for a given bot at the same time, including multiple concurrent subscriptions from the same user. Subscription price must no exceed 2500 Telegram Stars. |
| max_tip_amount | Integer | Optional | 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. |
| suggested_tip_amounts | Array of Integer | Optional | 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. |
| provider_data | String | Optional | 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. |
Expand Down Expand Up @@ -5986,13 +5997,30 @@ The withdrawal failed and the transaction was refunded.
| type | String | Type of the state, always “failed” |


#### AffiliateInfo


Contains information about the affiliate that received a commission via this transaction.


| Field | Type | Description |
| --- | --- | --- |
| |
| affiliate_user | User | Optional. The bot or the user that received an affiliate commission if it was received by a bot or a user |
| affiliate_chat | Chat | Optional. The chat that received an affiliate commission if it was received by a chat |
| commission_per_mille | Integer | The number of Telegram Stars received by the affiliate for each 1000 Telegram Stars received by the bot from referred users |
| amount | Integer | Integer amount of Telegram Stars received by the affiliate from the transaction, rounded to 0; can be negative for refunds |
| nanostar_amount | Integer | Optional. The number of 1/1000000000 shares of Telegram Stars received by the affiliate; from -999999999 to 999999999; can be negative for refunds |


#### TransactionPartner


This object describes the source of a transaction, or its recipient for outgoing transactions. Currently, it can be one of


* TransactionPartnerUser
* TransactionPartnerAffiliateProgram
* TransactionPartnerFragment
* TransactionPartnerTelegramAds
* TransactionPartnerTelegramApi
Expand All @@ -6010,13 +6038,28 @@ Describes a transaction with a user.
| |
| type | String | Type of the transaction partner, always “user” |
| user | User | Information about the user |
| affiliate | AffiliateInfo | Optional. Information about the affiliate that received a commission via this transaction |
| invoice_payload | String | Optional. Bot-specified invoice payload |
| subscription_period | Integer | Optional. The duration of the paid subscription |
| paid_media | Array of PaidMedia | Optional. Information about the paid media bought by the user |
| paid_media_payload | String | Optional. Bot-specified paid media payload |
| gift | Gift | Optional. The gift sent to the user by the bot |


#### TransactionPartnerAffiliateProgram


Describes the affiliate program that issued the affiliate commission received via this transaction.


| Field | Type | Description |
| --- | --- | --- |
| |
| type | String | Type of the transaction partner, always “affiliate_program” |
| sponsor_user | User | Optional. Information about the bot that sponsored the affiliate program |
| commission_per_mille | Integer | The number of Telegram Stars received by the bot for each 1000 Telegram Stars received by the affiliate program sponsor from referred users |


#### TransactionPartnerFragment


Expand Down Expand Up @@ -6077,7 +6120,8 @@ Describes a Telegram Star transaction.
| --- | --- | --- |
| |
| id | String | Unique identifier of the transaction. Coincides with the identifier of the original transaction for refund transactions. Coincides with SuccessfulPayment.telegram_payment_charge_id for successful incoming payments from users. |
| amount | Integer | Number of Telegram Stars transferred by the transaction |
| amount | Integer | Integer amount of Telegram Stars transferred by the transaction |
| nanostar_amount | Integer | Optional. The number of 1/1000000000 shares of Telegram Stars transferred by the transaction; from 0 to 999999999 |
| date | Integer | Date the transaction was created in Unix time |
| source | TransactionPartner | Optional. Source of an incoming transaction (e.g., a user purchasing goods or services, Fragment refunding a failed withdrawal). Only for incoming transactions |
| receiver | TransactionPartner | Optional. Receiver of an outgoing transaction (e.g., a user for a purchase refund, Fragment for a withdrawal). Only for outgoing transactions |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public data class CreateInvoiceLink(
*/
public val prices: List<LabeledPrice>,
/**
* The number of seconds the subscription will be active for before the next payment. The currency must be set to "XTR" (Telegram Stars) if the parameter is used. Currently, it must always be 2592000 (30 days) if specified. Any number of subscriptions can be active for a given bot at the same time, including multiple concurrent subscriptions from the same user.
* The number of seconds the subscription will be active for before the next payment. The currency must be set to "XTR" (Telegram Stars) if the parameter is used. Currently, it must always be 2592000 (30 days) if specified. Any number of subscriptions can be active for a given bot at the same time, including multiple concurrent subscriptions from the same user. Subscription price must no exceed 2500 Telegram Stars.
*/
public val subscription_period: Int? = null,
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.heapy.kotbot.bot.model

import kotlin.Int
import kotlinx.serialization.Serializable

/**
* Contains information about the affiliate that received a commission via this transaction.
*/
@Serializable
public data class AffiliateInfo(
/**
* *Optional*. The bot or the user that received an affiliate commission if it was received by a bot or a user
*/
public val affiliate_user: User? = null,
/**
* *Optional*. The chat that received an affiliate commission if it was received by a chat
*/
public val affiliate_chat: Chat? = null,
/**
* The number of Telegram Stars received by the affiliate for each 1000 Telegram Stars received by the bot from referred users
*/
public val commission_per_mille: Int,
/**
* Integer amount of Telegram Stars received by the affiliate from the transaction, rounded to 0; can be negative for refunds
*/
public val amount: Int,
/**
* *Optional*. The number of 1/1000000000 shares of Telegram Stars received by the affiliate; from -999999999 to 999999999; can be negative for refunds
*/
public val nanostar_amount: Int? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ public data class StarTransaction(
*/
public val id: String,
/**
* Number of Telegram Stars transferred by the transaction
* Integer amount of Telegram Stars transferred by the transaction
*/
public val amount: Int,
/**
* *Optional*. The number of 1/1000000000 shares of Telegram Stars transferred by the transaction; from 0 to 999999999
*/
public val nanostar_amount: Int? = null,
/**
* Date the transaction was created in Unix time
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import kotlinx.serialization.Serializable
* This object describes the source of a transaction, or its recipient for outgoing transactions. Currently, it can be one of
*
* * [TransactionPartnerUser](https://core.telegram.org/bots/api/#transactionpartneruser)
* * [TransactionPartnerAffiliateProgram](https://core.telegram.org/bots/api/#transactionpartneraffiliateprogram)
* * [TransactionPartnerFragment](https://core.telegram.org/bots/api/#transactionpartnerfragment)
* * [TransactionPartnerTelegramAds](https://core.telegram.org/bots/api/#transactionpartnertelegramads)
* * [TransactionPartnerTelegramApi](https://core.telegram.org/bots/api/#transactionpartnertelegramapi)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.heapy.kotbot.bot.model

import kotlin.Int
import kotlin.String
import kotlinx.serialization.Serializable

/**
* Describes the affiliate program that issued the affiliate commission received via this transaction.
*/
@Serializable
public data class TransactionPartnerAffiliateProgram(
/**
* Type of the transaction partner, always "affiliate_program"
*/
public val type: String,
/**
* *Optional*. Information about the bot that sponsored the affiliate program
*/
public val sponsor_user: User? = null,
/**
* The number of Telegram Stars received by the bot for each 1000 Telegram Stars received by the affiliate program sponsor from referred users
*/
public val commission_per_mille: Int,
) : TransactionPartner
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ public data class TransactionPartnerUser(
* Information about the user
*/
public val user: User,
/**
* *Optional*. Information about the affiliate that received a commission via this transaction
*/
public val affiliate: AffiliateInfo? = null,
/**
* *Optional*. Bot-specified invoice payload
*/
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/kotlin/io/heapy/kotbot/bot/Serializers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public object ReactionTypeSerializer : JsonContentPolymorphicSerializer<Reaction
when (val type = element.jsonObject["type"]?.jsonPrimitive?.content) {
"emoji" -> ReactionTypeEmoji.serializer()
"custom_emoji" -> ReactionTypeCustomEmoji.serializer()
"paid" -> ReactionTypePaid.serializer()
else -> error("Unknown argument type: $type")
}
}
Expand All @@ -121,7 +122,6 @@ public class MaybeInaccessibleMessageSerializer :
public class ChatBoostSourceSerializer : JsonContentPolymorphicSerializer<ChatBoostSource>(ChatBoostSource::class) {
override fun selectDeserializer(element: JsonElement): KSerializer<out ChatBoostSource> =
when (val type = element.jsonObject["source"]?.jsonPrimitive?.content) {

"premium" -> ChatBoostSourcePremium.serializer()
"gift_code" -> ChatBoostSourceGiftCode.serializer()
"giveaway" -> ChatBoostSourceGiveaway.serializer()
Expand Down Expand Up @@ -194,8 +194,10 @@ public class TransactionPartnerSerializer : JsonContentPolymorphicSerializer<Tra
override fun selectDeserializer(element: JsonElement): KSerializer<out TransactionPartner> =
when (val type = element.jsonObject["type"]?.jsonPrimitive?.content) {
"user" -> TransactionPartnerUser.serializer()
"affiliate_program" -> TransactionPartnerAffiliateProgram.serializer()
"fragment" -> TransactionPartnerFragment.serializer()
"telegram_ads" -> TransactionPartnerTelegramAds.serializer()
"telegram_api" -> TransactionPartnerTelegramApi.serializer()
"other" -> TransactionPartnerOther.serializer()
else -> error("Unknown argument type: $type")
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
group=io.heapy.kotbot
version=1.1.0
version=1.2.0
kotlin.code.style=official

0 comments on commit 6b65ef7

Please sign in to comment.