Skip to content

Commit 9537422

Browse files
committed
Telegram Bot API December 4, 2024 updates (v8.1)
1 parent 622a703 commit 9537422

File tree

8 files changed

+131
-22
lines changed

8 files changed

+131
-22
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# F[Tg] - Telegramium
22

3-
[![Telegram](https://img.shields.io/badge/Telegram%20Bot%20API-8.0%20(October%2031%2C%202024)-blue)](https://core.telegram.org/bots/api#recent-changes)
3+
[![Telegram](https://img.shields.io/badge/Telegram%20Bot%20API-8.1%20(December%204%2C%202024)-blue)](https://core.telegram.org/bots/api#recent-changes)
44
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.github.apimorphism/telegramium-core_3/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.github.apimorphism/telegramium-core_3)
55

66

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
enablePlugins(GitPlugin)
22

33
ThisBuild / version := Version.mkVersion(
4-
"9.800.0",
4+
"9.801.0",
55
git.gitCurrentBranch.value,
66
git.gitDescribedVersion.value,
77
git.gitUncommittedChanges.value
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package telegramium.bots
2+
3+
/** Contains information about the affiliate that received a commission via this transaction.
4+
*
5+
* @param commissionPerMille
6+
* The number of Telegram Stars received by the affiliate for each 1000 Telegram Stars received by the bot from
7+
* referred users
8+
* @param amount
9+
* Integer amount of Telegram Stars received by the affiliate from the transaction, rounded to 0; can be negative for
10+
* refunds
11+
* @param affiliateUser
12+
* Optional. The bot or the user that received an affiliate commission if it was received by a bot or a user
13+
* @param affiliateChat
14+
* Optional. The chat that received an affiliate commission if it was received by a chat
15+
* @param nanostarAmount
16+
* Optional. The number of 1/1000000000 shares of Telegram Stars received by the affiliate; from -999999999 to
17+
* 999999999; can be negative for refunds
18+
*/
19+
final case class AffiliateInfo(
20+
commissionPerMille: Int,
21+
amount: Int,
22+
affiliateUser: Option[User] = Option.empty,
23+
affiliateChat: Option[Chat] = Option.empty,
24+
nanostarAmount: Option[Int] = Option.empty
25+
)

telegramium-core/src/main/scala/telegramium/bots/StarTransaction.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ package telegramium.bots
77
* transactions. Coincides with SuccessfulPayment.telegram_payment_charge_id for successful incoming payments from
88
* users.
99
* @param amount
10-
* Number of Telegram Stars transferred by the transaction
10+
* Integer amount of Telegram Stars transferred by the transaction
1111
* @param date
1212
* Date the transaction was created in Unix time
13+
* @param nanostarAmount
14+
* Optional. The number of 1/1000000000 shares of Telegram Stars transferred by the transaction; from 0 to 999999999
1315
* @param source
1416
* Optional. Source of an incoming transaction (e.g., a user purchasing goods or services, Fragment refunding a
1517
* failed withdrawal). Only for incoming transactions
@@ -21,6 +23,7 @@ final case class StarTransaction(
2123
id: String,
2224
amount: Int,
2325
date: Int,
26+
nanostarAmount: Option[Int] = Option.empty,
2427
source: Option[iozhik.OpenEnum[TransactionPartner]] = Option.empty,
2528
receiver: Option[iozhik.OpenEnum[TransactionPartner]] = Option.empty
2629
)

telegramium-core/src/main/scala/telegramium/bots/TransactionPartner.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@ package telegramium.bots
22

33
sealed trait TransactionPartner {}
44

5+
/** Describes the affiliate program that issued the affiliate commission received via this transaction.
6+
*
7+
* @param commissionPerMille
8+
* The number of Telegram Stars received by the bot for each 1000 Telegram Stars received by the affiliate program
9+
* sponsor from referred users
10+
* @param sponsorUser
11+
* Optional. Information about the bot that sponsored the affiliate program
12+
*/
13+
final case class TransactionPartnerAffiliateProgram(commissionPerMille: Int, sponsorUser: Option[User] = Option.empty)
14+
extends TransactionPartner
15+
516
/** Describes a transaction with an unknown source or recipient. */
617
case object TransactionPartnerOther extends TransactionPartner
718

@@ -12,6 +23,8 @@ case object TransactionPartnerTelegramAds extends TransactionPartner
1223
*
1324
* @param user
1425
* Information about the user
26+
* @param affiliate
27+
* Optional. Information about the affiliate that received a commission via this transaction
1528
* @param invoicePayload
1629
* Optional. Bot-specified invoice payload
1730
* @param subscriptionPeriod
@@ -25,6 +38,7 @@ case object TransactionPartnerTelegramAds extends TransactionPartner
2538
*/
2639
final case class TransactionPartnerUser(
2740
user: User,
41+
affiliate: Option[AffiliateInfo] = Option.empty,
2842
invoicePayload: Option[String] = Option.empty,
2943
subscriptionPeriod: Option[Int] = Option.empty,
3044
paidMedia: List[iozhik.OpenEnum[PaidMedia]] = List.empty,

telegramium-core/src/main/scala/telegramium/bots/client/CreateInvoiceLinkReq.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import telegramium.bots.LabeledPrice
2323
* The number of seconds the subscription will be active for before the next payment. The currency must be set to
2424
* “XTR” (Telegram Stars) if the parameter is used. Currently, it must always be 2592000 (30 days) if specified. Any
2525
* number of subscriptions can be active for a given bot at the same time, including multiple concurrent
26-
* subscriptions from the same user.
26+
* subscriptions from the same user. Subscription price must no exceed 2500 Telegram Stars.
2727
* @param maxTipAmount
2828
* The maximum accepted amount for tips in the smallest units of the currency (integer, not float/double). For
2929
* example, for a maximum tip of US$ 1.45 pass max_tip_amount = 145. See the exp parameter in currencies.json, it

telegramium-core/src/main/scala/telegramium/bots/client/Methods.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ trait Methods {
493493
* The number of seconds the subscription will be active for before the next payment. The currency must be set to
494494
* “XTR” (Telegram Stars) if the parameter is used. Currently, it must always be 2592000 (30 days) if specified.
495495
* Any number of subscriptions can be active for a given bot at the same time, including multiple concurrent
496-
* subscriptions from the same user.
496+
* subscriptions from the same user. Subscription price must no exceed 2500 Telegram Stars.
497497
* @param maxTipAmount
498498
* The maximum accepted amount for tips in the smallest units of the currency (integer, not float/double). For
499499
* example, for a maximum tip of US$ 1.45 pass max_tip_amount = 145. See the exp parameter in currencies.json, it

telegramium-core/src/main/scala/telegramium/bots/package.scala

Lines changed: 84 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3725,22 +3725,45 @@ object CirceImplicits {
37253725
telegram_ads.asJson.mapObject(_.add("type", Json.fromString("telegram_ads")))
37263726
case telegram_api: TransactionPartnerTelegramApi =>
37273727
telegram_api.asJson.mapObject(_.add("type", Json.fromString("telegram_api")))
3728+
case affiliate_program: TransactionPartnerAffiliateProgram =>
3729+
affiliate_program.asJson.mapObject(_.add("type", Json.fromString("affiliate_program")))
37283730
case user: TransactionPartnerUser => user.asJson.mapObject(_.add("type", Json.fromString("user")))
37293731
case other: TransactionPartnerOther.type => other.asJson.mapObject(_.add("type", Json.fromString("other")))
37303732
}
37313733

37323734
implicit lazy val transactionpartnerDecoder: Decoder[iozhik.OpenEnum[TransactionPartner]] = for {
37333735
fType <- Decoder[String].prepare(_.downField("type"))
37343736
value <- fType match {
3735-
case "fragment" => Decoder[TransactionPartnerFragment].map(iozhik.OpenEnum.Known(_))
3736-
case "telegram_ads" => Decoder[TransactionPartnerTelegramAds.type].map(iozhik.OpenEnum.Known(_))
3737-
case "telegram_api" => Decoder[TransactionPartnerTelegramApi].map(iozhik.OpenEnum.Known(_))
3738-
case "user" => Decoder[TransactionPartnerUser].map(iozhik.OpenEnum.Known(_))
3739-
case "other" => Decoder[TransactionPartnerOther.type].map(iozhik.OpenEnum.Known(_))
3740-
case unknown => Decoder.const(iozhik.OpenEnum.Unknown[TransactionPartner](unknown))
3737+
case "fragment" => Decoder[TransactionPartnerFragment].map(iozhik.OpenEnum.Known(_))
3738+
case "telegram_ads" => Decoder[TransactionPartnerTelegramAds.type].map(iozhik.OpenEnum.Known(_))
3739+
case "telegram_api" => Decoder[TransactionPartnerTelegramApi].map(iozhik.OpenEnum.Known(_))
3740+
case "affiliate_program" => Decoder[TransactionPartnerAffiliateProgram].map(iozhik.OpenEnum.Known(_))
3741+
case "user" => Decoder[TransactionPartnerUser].map(iozhik.OpenEnum.Known(_))
3742+
case "other" => Decoder[TransactionPartnerOther.type].map(iozhik.OpenEnum.Known(_))
3743+
case unknown => Decoder.const(iozhik.OpenEnum.Unknown[TransactionPartner](unknown))
37413744
}
37423745
} yield value
37433746

3747+
implicit lazy val transactionpartneraffiliateprogramEncoder: Encoder[TransactionPartnerAffiliateProgram] =
3748+
(x: TransactionPartnerAffiliateProgram) => {
3749+
Json.fromFields(
3750+
List(
3751+
"sponsor_user" -> x.sponsorUser.asJson,
3752+
"commission_per_mille" -> x.commissionPerMille.asJson
3753+
).filter(!_._2.isNull)
3754+
)
3755+
}
3756+
3757+
implicit lazy val transactionpartneraffiliateprogramDecoder: Decoder[TransactionPartnerAffiliateProgram] =
3758+
Decoder.instance { h =>
3759+
for {
3760+
_sponsorUser <- h.get[Option[User]]("sponsor_user")
3761+
_commissionPerMille <- h.get[Int]("commission_per_mille")
3762+
} yield {
3763+
TransactionPartnerAffiliateProgram(sponsorUser = _sponsorUser, commissionPerMille = _commissionPerMille)
3764+
}
3765+
}
3766+
37443767
implicit lazy val transactionpartnerotherEncoder: Encoder[TransactionPartnerOther.type] =
37453768
(_: TransactionPartnerOther.type) => ().asJson
37463769

@@ -3758,6 +3781,7 @@ object CirceImplicits {
37583781
Json.fromFields(
37593782
List(
37603783
"user" -> x.user.asJson,
3784+
"affiliate" -> x.affiliate.asJson,
37613785
"invoice_payload" -> x.invoicePayload.asJson,
37623786
"subscription_period" -> x.subscriptionPeriod.asJson,
37633787
"paid_media" -> x.paidMedia.asJson,
@@ -3771,6 +3795,7 @@ object CirceImplicits {
37713795
Decoder.instance { h =>
37723796
for {
37733797
_user <- h.get[User]("user")
3798+
_affiliate <- h.get[Option[AffiliateInfo]]("affiliate")
37743799
_invoicePayload <- h.get[Option[String]]("invoice_payload")
37753800
_subscriptionPeriod <- h.get[Option[Int]]("subscription_period")
37763801
_paidMedia <- h.getOrElse[List[iozhik.OpenEnum[PaidMedia]]]("paid_media")(List.empty)
@@ -3779,6 +3804,7 @@ object CirceImplicits {
37793804
} yield {
37803805
TransactionPartnerUser(
37813806
user = _user,
3807+
affiliate = _affiliate,
37823808
invoicePayload = _invoicePayload,
37833809
subscriptionPeriod = _subscriptionPeriod,
37843810
paidMedia = _paidMedia,
@@ -3824,6 +3850,38 @@ object CirceImplicits {
38243850
}
38253851
}
38263852

3853+
implicit lazy val affiliateinfoEncoder: Encoder[AffiliateInfo] =
3854+
(x: AffiliateInfo) => {
3855+
Json.fromFields(
3856+
List(
3857+
"affiliate_user" -> x.affiliateUser.asJson,
3858+
"affiliate_chat" -> x.affiliateChat.asJson,
3859+
"commission_per_mille" -> x.commissionPerMille.asJson,
3860+
"amount" -> x.amount.asJson,
3861+
"nanostar_amount" -> x.nanostarAmount.asJson
3862+
).filter(!_._2.isNull)
3863+
)
3864+
}
3865+
3866+
implicit lazy val affiliateinfoDecoder: Decoder[AffiliateInfo] =
3867+
Decoder.instance { h =>
3868+
for {
3869+
_affiliateUser <- h.get[Option[User]]("affiliate_user")
3870+
_affiliateChat <- h.get[Option[Chat]]("affiliate_chat")
3871+
_commissionPerMille <- h.get[Int]("commission_per_mille")
3872+
_amount <- h.get[Int]("amount")
3873+
_nanostarAmount <- h.get[Option[Int]]("nanostar_amount")
3874+
} yield {
3875+
AffiliateInfo(
3876+
affiliateUser = _affiliateUser,
3877+
affiliateChat = _affiliateChat,
3878+
commissionPerMille = _commissionPerMille,
3879+
amount = _amount,
3880+
nanostarAmount = _nanostarAmount
3881+
)
3882+
}
3883+
}
3884+
38273885
implicit lazy val animationEncoder: Encoder[Animation] =
38283886
(x: Animation) => {
38293887
Json.fromFields(
@@ -6605,25 +6663,34 @@ object CirceImplicits {
66056663
(x: StarTransaction) => {
66066664
Json.fromFields(
66076665
List(
6608-
"id" -> x.id.asJson,
6609-
"amount" -> x.amount.asJson,
6610-
"date" -> x.date.asJson,
6611-
"source" -> x.source.asJson,
6612-
"receiver" -> x.receiver.asJson
6666+
"id" -> x.id.asJson,
6667+
"amount" -> x.amount.asJson,
6668+
"nanostar_amount" -> x.nanostarAmount.asJson,
6669+
"date" -> x.date.asJson,
6670+
"source" -> x.source.asJson,
6671+
"receiver" -> x.receiver.asJson
66136672
).filter(!_._2.isNull)
66146673
)
66156674
}
66166675

66176676
implicit lazy val startransactionDecoder: Decoder[StarTransaction] =
66186677
Decoder.instance { h =>
66196678
for {
6620-
_id <- h.get[String]("id")
6621-
_amount <- h.get[Int]("amount")
6622-
_date <- h.get[Int]("date")
6623-
_source <- h.get[Option[iozhik.OpenEnum[TransactionPartner]]]("source")
6624-
_receiver <- h.get[Option[iozhik.OpenEnum[TransactionPartner]]]("receiver")
6679+
_id <- h.get[String]("id")
6680+
_amount <- h.get[Int]("amount")
6681+
_nanostarAmount <- h.get[Option[Int]]("nanostar_amount")
6682+
_date <- h.get[Int]("date")
6683+
_source <- h.get[Option[iozhik.OpenEnum[TransactionPartner]]]("source")
6684+
_receiver <- h.get[Option[iozhik.OpenEnum[TransactionPartner]]]("receiver")
66256685
} yield {
6626-
StarTransaction(id = _id, amount = _amount, date = _date, source = _source, receiver = _receiver)
6686+
StarTransaction(
6687+
id = _id,
6688+
amount = _amount,
6689+
nanostarAmount = _nanostarAmount,
6690+
date = _date,
6691+
source = _source,
6692+
receiver = _receiver
6693+
)
66276694
}
66286695
}
66296696

0 commit comments

Comments
 (0)