Skip to content

Commit 76a2c87

Browse files
authored
[api] Support v6.2 (#267)
## Bot API 6.2 - August 12, 2022 ### Custom Emoji Support - [x] Added the [MessageEntity](https://core.telegram.org/bots/api#messageentity) type “custom_emoji”. - [x] Added the field custom_emoji_id to the class [MessageEntity](https://core.telegram.org/bots/api#messageentity) for “custom_emoji” entities. - [x] Added the method [getCustomEmojiStickers](https://core.telegram.org/bots/api#getcustomemojistickers). - [x] Added the fields type and custom_emoji_id to the class [Sticker](https://core.telegram.org/bots/api#sticker). - [x] Added the field sticker_type to the class [StickerSet](https://core.telegram.org/bots/api#stickerset), describing the type of stickers in the set. - [x] The field contains_masks has been removed from the documentation of the class [StickerSet](https://core.telegram.org/bots/api#stickerset). The field is still returned in the object for backward compatibility, but new bots should use the field sticker_type instead. - [x] Added the parameter sticker_type to the method [createNewStickerSet](https://core.telegram.org/bots/api#createnewstickerset). - [x] The parameter contains_masks has been removed from the documentation of the method [createNewStickerSet](https://core.telegram.org/bots/api#createnewstickerset). The parameter will still work for backward compatibility, but new bots should use the parameter sticker_type instead. ### Other Changes - [x] Added the field has_restricted_voice_and_video_messages to the class [Chat](https://core.telegram.org/bots/api#chat) to support the [new setting](https://telegram.org/blog/custom-emoji#privacy-settings-for-voice-messages).
1 parent d58ad47 commit 76a2c87

File tree

13 files changed

+109
-39
lines changed

13 files changed

+109
-39
lines changed

core/src/com/bot4s/telegram/api/RequestHandler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import cats.syntax.flatMap._
77
import cats.syntax.functor._
88
import cats.syntax.monadError._
99
import com.bot4s.telegram.methods._
10-
import com.bot4s.telegram.models.MenuButton.menuButtonDecoder
1110
import io.circe.{ Decoder, Encoder }
1211
import com.typesafe.scalalogging.StrictLogging
1312

@@ -72,6 +71,7 @@ abstract class RequestHandler[F[_]](implicit monadError: MonadError[F, Throwable
7271
case s: GetChatMemberCount => sendRequest[R, GetChatMemberCount](s)
7372
case s: GetChatMembersCount => sendRequest[R, GetChatMembersCount](s)
7473
case s: GetChatMenuButton => sendRequest[R, GetChatMenuButton](s)
74+
case s: GetCustomEmojiStickers => sendRequest[R, GetCustomEmojiStickers](s)
7575
case s: GetFile => sendRequest[R, GetFile](s)
7676
case s: GetGameHighScores => sendRequest[R, GetGameHighScores](s)
7777
case s: GetMe.type => sendRequest[R, GetMe.type](s)

core/src/com/bot4s/telegram/marshalling/CirceDecoders.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import com.bot4s.telegram.models.MaskPositionType.MaskPositionType
1414
import com.bot4s.telegram.models.MemberStatus.MemberStatus
1515
import com.bot4s.telegram.models.BotCommandScope.BotCommandScope
1616
import com.bot4s.telegram.models.MessageEntityType.MessageEntityType
17+
import com.bot4s.telegram.models.StickerType.StickerType
1718
import UpdateType.UpdateType
1819
import com.bot4s.telegram.models._
1920
import io.circe.{ Decoder, HCursor }
@@ -46,6 +47,17 @@ trait CirceDecoders extends StrictLogging {
4647
}
4748
}
4849

50+
implicit val stickerTypeDecoder: Decoder[StickerType] =
51+
Decoder[String].map { s =>
52+
try {
53+
StickerType.withName(pascalize(s))
54+
} catch {
55+
case e: NoSuchElementException =>
56+
logger.warn(s"Unexpected StickerType: '$s', fallback to Unknown.")
57+
StickerType.Unknown
58+
}
59+
}
60+
4961
implicit val parseModeDecoder: Decoder[ParseMode] =
5062
Decoder[String].map(s => ParseMode.withName(pascalize(s)))
5163

@@ -88,6 +100,7 @@ trait CirceDecoders extends StrictLogging {
88100

89101
implicit val KeyboardButtonPollTypeDecoder: Decoder[KeyboardButtonPollType] = deriveDecoder[KeyboardButtonPollType]
90102

103+
implicit val menuButtonDecoder: Decoder[MenuButton] = MenuButton.menuButtonDecoder
91104
implicit val contactDecoder: Decoder[Contact] = deriveDecoder[Contact]
92105
implicit val documentDecoder: Decoder[Document] = deriveDecoder[Document]
93106
implicit val fileDecoder: Decoder[File] = deriveDecoder[File]

core/src/com/bot4s/telegram/marshalling/CirceEncoders.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import com.bot4s.telegram.models.MaskPositionType.MaskPositionType
1212
import com.bot4s.telegram.models.MemberStatus.MemberStatus
1313
import com.bot4s.telegram.models.BotCommandScope.BotCommandScope
1414
import com.bot4s.telegram.models.MessageEntityType.MessageEntityType
15+
import com.bot4s.telegram.models.StickerType.StickerType
1516
import UpdateType.UpdateType
1617
import com.bot4s.telegram.models._
1718
import io.circe.Encoder
@@ -60,6 +61,9 @@ trait CirceEncoders {
6061
implicit val messageEntityTypeEncoder: Encoder[MessageEntityType] =
6162
Encoder[String].contramap[MessageEntityType](e => CaseConversions.snakenize(e.toString))
6263

64+
implicit val stickerTypeEncoder: Encoder[StickerType] =
65+
Encoder[String].contramap[StickerType](e => CaseConversions.snakenize(e.toString))
66+
6367
implicit val messageEntityEncoder: Encoder[MessageEntity] = deriveConfiguredEncoder[MessageEntity]
6468

6569
implicit val parseModeEncoder: Encoder[ParseMode] =
@@ -246,6 +250,8 @@ trait CirceEncoders {
246250
implicit val getUpdatesEncoder: Encoder[GetUpdates] = deriveConfiguredEncoder[GetUpdates]
247251

248252
implicit val chatLocationEncoder: Encoder[ChatLocation] = deriveConfiguredEncoder[ChatLocation]
253+
// for v6.2 support
254+
implicit val getCustomEmojiStickers: Encoder[GetCustomEmojiStickers] = deriveConfiguredEncoder[GetCustomEmojiStickers]
249255
// for v6.1 support
250256
implicit val createInvoiceLinkEncoder: Encoder[CreateInvoiceLink] = deriveConfiguredEncoder[CreateInvoiceLink]
251257
// for v6.0 support

core/src/com/bot4s/telegram/methods/CreateNewStickerSet.scala

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.bot4s.telegram.methods
22

33
import com.bot4s.telegram.models.MaskPosition
44
import com.bot4s.telegram.models.InputFile
5+
import com.bot4s.telegram.models.StickerType.StickerType
56

67
/**
78
* Use this method to create new sticker set owned by a user.
@@ -19,17 +20,19 @@ import com.bot4s.telegram.models.InputFile
1920
* [[https://core.telegram.org/stickers#animated-sticker-requirements for technical requirements]]
2021
* @param webmSticker InputFile Optional WEBM video with the sticker, uploaded using multipart/form-data see
2122
* [[https://core.telegram.org/stickers#video-sticker-requirements for technical requirements]]
23+
* @param stickerType Optional StickerType. Type of stickers in the set, pass “regular” or “mask”. Custom emoji sticker sets can't be created via the Bot API at the moment. By default, a regular sticker set is created.
2224
* @param emojis String One or more emoji corresponding to the sticker
23-
* @param containsMasks Boolean Optional Pass True, if a set of mask stickers should be created
25+
* @param containsMasks Boolean Optional Pass True, if a set of mask stickers should be created. Deprecated, use stickerType instead
2426
* @param maskPosition MaskPosition Optional Position where the mask should be placed on faces
2527
*/
2628
case class CreateNewStickerSet(
2729
userId: Long,
2830
name: String,
2931
title: String,
30-
pngSticker: Option[InputFile],
31-
tgsSticker: Option[InputFile],
32-
webmSticker: Option[InputFile],
32+
pngSticker: Option[InputFile] = None,
33+
tgsSticker: Option[InputFile] = None,
34+
webmSticker: Option[InputFile] = None,
35+
stickerType: Option[StickerType] = None,
3336
emojis: String,
3437
containsMasks: Option[Boolean] = None,
3538
maskPosition: Option[MaskPosition] = None
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.bot4s.telegram.methods
2+
3+
import com.bot4s.telegram.models.Sticker
4+
5+
/**
6+
* Use this method to get information about custom emoji stickers by their identifiers.
7+
* Returns an Array of Sticker objects.
8+
*
9+
* @param customEmojiIds Array of string. List of custom emoji identifiers. At most 200 custom emoji identifiers can be specified
10+
*/
11+
case class GetCustomEmojiStickers(customEmojiIds: Array[String]) extends JsonRequest[List[Sticker]]

core/src/com/bot4s/telegram/models/Chat.scala

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,22 @@ import com.bot4s.telegram.models.ChatType.ChatType
1818
* Each administrator in a chat generates their own invite links, so the bot must first generate the link using exportChatInviteLink.
1919
* Returned only in getChat.
2020
*
21-
* @param pinnedMessage Message Optional. Pinned message, for supergroups. Returned only in getChat.
22-
* @param permissions ChatPermissions Optional. Default chat member permissions, for groups and supergroups. Returned only in getChat.
23-
* @param slowModeDelay Integer Optional. For supergroups, the minimum allowed delay between consecutive messages sent by each unpriviledged user; in seconds. Returned only in getChat.
24-
* @param messageAutoDeleteTime Integer Optional. The time after which all messages sent to the chat will be automatically deleted; in seconds. Returned only in getChat.
25-
* @param stickerSetName String Optional. For supergroups, name of group sticker set. Returned only in getChat.
26-
* @param canSetStickerSet Boolean Optional. True, if the bot can change the group sticker set. Returned only in getChat.
27-
* @param linkedChatId Long Optinal. Unique identifier for the linked chat, i.e. the discussion group identifier for a channel and vice versa; for supergroups and channel chats.
28-
* This identifier may be greater than 32 bits and some programming languages may have difficulty/silent defects in interpreting it.
29-
* But it is smaller than 52 bits, so a signed 64 bit integer or double-precision float type are safe for storing this identifier. Returned only in getChat.
30-
* @param location Optional ChatLocation. For supergroups, the location to which the supergroup is connected. Returned only in getChat.
31-
* @param hasPrivateForwards Boolean Optional. True, if privacy settings of the other party in the private chat allows to use tg://user?id=<user_id> links only in chats with the user.
32-
* Returned only in getChat.
33-
* @param hasProtectedContent Boolean Optional. True, if messages from the chat can't be forwarded to other chats. Returned only in getChat.
34-
* @param joinToSendMessages Boolean Optional. True, if users need to join the supergroup before they can send messages. Returned only in getChat.
35-
* @param joinByRequest Boolean Optional. True, if all users directly joining the supergroup need to be approved by supergroup administrators. Returned only in getChat.
21+
* @param pinnedMessage Message Optional. Pinned message, for supergroups. Returned only in getChat.
22+
* @param permissions ChatPermissions Optional. Default chat member permissions, for groups and supergroups. Returned only in getChat.
23+
* @param slowModeDelay Integer Optional. For supergroups, the minimum allowed delay between consecutive messages sent by each unpriviledged user; in seconds. Returned only in getChat.
24+
* @param messageAutoDeleteTime Integer Optional. The time after which all messages sent to the chat will be automatically deleted; in seconds. Returned only in getChat.
25+
* @param stickerSetName String Optional. For supergroups, name of group sticker set. Returned only in getChat.
26+
* @param canSetStickerSet Boolean Optional. True, if the bot can change the group sticker set. Returned only in getChat.
27+
* @param linkedChatId Long Optinal. Unique identifier for the linked chat, i.e. the discussion group identifier for a channel and vice versa; for supergroups and channel chats.
28+
* This identifier may be greater than 32 bits and some programming languages may have difficulty/silent defects in interpreting it.
29+
* But it is smaller than 52 bits, so a signed 64 bit integer or double-precision float type are safe for storing this identifier. Returned only in getChat.
30+
* @param location Optional ChatLocation. For supergroups, the location to which the supergroup is connected. Returned only in getChat.
31+
* @param hasPrivateForwards Boolean Optional. True, if privacy settings of the other party in the private chat allows to use tg://user?id=<user_id> links only in chats with the user.
32+
* Returned only in getChat.
33+
* @param hasProtectedContent Boolean Optional. True, if messages from the chat can't be forwarded to other chats. Returned only in getChat.
34+
* @param joinToSendMessages Boolean Optional. True, if users need to join the supergroup before they can send messages. Returned only in getChat.
35+
* @param joinByRequest Boolean Optional. True, if all users directly joining the supergroup need to be approved by supergroup administrators. Returned only in getChat.
36+
* @param hasRestrictedVoiceAndVideoMessages Boolean Optional. True, if the privacy settings of the other party restrict sending voice and video note messages in the private chat. Returned only in getChat.
3637
*/
3738
case class Chat(
3839
id: Long,
@@ -56,7 +57,8 @@ case class Chat(
5657
hasPrivateForwards: Option[Boolean] = None,
5758
hasProtectedContent: Option[Boolean] = None,
5859
joinToSendMessages: Option[Boolean] = None,
59-
joinByRequest: Option[Boolean] = None
60+
joinByRequest: Option[Boolean] = None,
61+
hasRestrictedVoiceAndVideoMessages: Option[Boolean] = None
6062
) {
6163
val chatId = ChatId(id)
6264
}

core/src/com/bot4s/telegram/models/MenuButton.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ object MenuButton {
4949
import io.circe.generic.extras.Configuration
5050
import com.bot4s.telegram.marshalling.CirceDecoders._
5151

52-
private implicit val configuration: Configuration = Configuration.default.withSnakeCaseMemberNames
52+
private implicit val configuration: Configuration = Configuration.default
5353
.withDiscriminator("type")
5454
.copy(
5555
transformConstructorNames = {
@@ -59,6 +59,5 @@ object MenuButton {
5959
}
6060
)
6161

62-
implicit val menuButtonDecoder: Decoder[MenuButton] =
63-
deriveConfiguredDecoder[MenuButton]
62+
implicit val menuButtonDecoder: Decoder[MenuButton] = deriveConfiguredDecoder
6463
}

core/src/com/bot4s/telegram/models/MessageEntity.scala

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,21 @@ import com.bot4s.telegram.models.MessageEntityType.MessageEntityType
77
*
88
* For example, hashtags, usernames, URLs, etc.
99
*
10-
* @param type String Type of the entity.
11-
* One of mention (@username), hashtag, bot_command, url, email, bold (bold text), italic (italic text),
12-
* code (monowidth string), pre (monowidth block), text_link (for clickable text URLs),
13-
* text_mention (for users without usernames)
14-
* @param offset Integer Offset in UTF-16 code units to the start of the entity
15-
* @param length Integer Length of the entity in UTF-16 code units
16-
* @param url String Optional For "text_link" only, url that will be opened after user taps on the text
17-
* @param user User Optional. For "text_mention" only, the mentioned user
10+
* @param type String Type of the entity.
11+
* One of mention (@username), hashtag, bot_command, url, email, bold (bold text), italic (italic text),
12+
* code (monowidth string), pre (monowidth block), text_link (for clickable text URLs),
13+
* text_mention (for users without usernames)
14+
* @param offset Integer Offset in UTF-16 code units to the start of the entity
15+
* @param length Integer Length of the entity in UTF-16 code units
16+
* @param url String Optional For "text_link" only, url that will be opened after user taps on the text
17+
* @param user User Optional. For "text_mention" only, the mentioned user
18+
* @param customEmojiId String Optional. For “custom_emoji” only, unique identifier of the custom emoji. Use getCustomEmojiStickers to get full information about the sticker
1819
*/
1920
case class MessageEntity(
2021
`type`: MessageEntityType,
2122
offset: Int,
2223
length: Int,
2324
url: Option[String] = None,
24-
user: Option[User] = None
25+
user: Option[User] = None,
26+
customEmojiId: Option[String] = None
2527
)

core/src/com/bot4s/telegram/models/MessageEntityType.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ object MessageEntityType extends Enumeration {
77
type MessageEntityType = Value
88

99
val Bold, BotCommand, Cashtag, Code, Email, Spoiler, Hashtag, Italic, Mention, PhoneNumber, Pre, TextLink,
10-
TextMention, Unknown, Url = Value
10+
TextMention, Unknown, Url, CustomEmoji = Value
1111
}

core/src/com/bot4s/telegram/models/Sticker.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package com.bot4s.telegram.models
22

3+
import com.bot4s.telegram.models.StickerType.StickerType
4+
35
/**
46
* This object represents a sticker.
57
*
68
* @param fileId Identifier for this file
79
* @param fileUniqueId Unique identifier for this file
10+
* @param type Type of the sticker, currently one of “regular”, “mask”, “custom_emoji”.
11+
* The type of the sticker is independent from its format, which is determined by the fields is_animated and is_video.
812
* @param width Sticker width
913
* @param height Sticker height
1014
* @param isAnimated Boolean True, if the sticker is animated
@@ -16,10 +20,12 @@ package com.bot4s.telegram.models
1620
* For mask stickers, the position where the mask should be placed
1721
* @param fileSize Integer Optional. File size
1822
* @param premiumAnimation File Optional. Premium animation for the sticker, if the sticker is premium
23+
* @param customEmojiId String Optional. For custom emoji stickers, unique identifier of the custom emoji
1924
*/
2025
case class Sticker(
2126
fileId: String,
2227
fileUniqueId: String,
28+
`type`: StickerType,
2329
width: Int,
2430
height: Int,
2531
isAnimated: Boolean,
@@ -29,5 +35,6 @@ case class Sticker(
2935
setName: Option[String] = None,
3036
maskPosition: Option[MaskPosition] = None,
3137
fileSize: Option[Int] = None,
32-
premiumAnimation: Option[File] = None
38+
premiumAnimation: Option[File] = None,
39+
customEmojiId: Option[String] = None
3340
)

0 commit comments

Comments
 (0)