Skip to content

Commit 0d8a679

Browse files
authored
[api] Support v6.0 (#211)
https://core.telegram.org/bots/api#april-16-2022 - [x] Added support for Web Apps, see the detailed manual here. (blog announcement) - [x] Added the class WebAppInfo and the fields web_app to the classes KeyboardButton and InlineKeyboardButton. - [x] Added the class SentWebAppMessage and the method answerWebAppQuery for sending an answer to a Web App query, which originated from an inline button of the 'web_app' type. - [x] Added the class WebAppData and the field web_app_data to the class Message. - [x] Added the class MenuButton and the methods setChatMenuButton and getChatMenuButton for managing the behavior of the bot's menu button in private chats. - [x] Added the class ChatAdministratorRights and the methods setMyDefaultAdministratorRights and getMyDefaultAdministratorRights for managing the bot's default administrator rights. - [x] Added support for t.me links that can be used to add the bot to groups and channels as an administrator. - [x] Added the field last_synchronization_error_date to the class WebhookInfo. - [x] Renamed the field can_manage_voice_chats to can_manage_video_chats in the class ChatMemberAdministrator. The old field will remain temporarily available. - [x] Renamed the parameter can_manage_voice_chats to can_manage_video_chats in the method promoteChatMember. The old parameter will remain temporarily available. - [x] Renamed the fields voice_chat_scheduled, voice_chat_started, voice_chat_ended, and voice_chat_participants_invited to video_chat_scheduled, video_chat_started, video_chat_ended, and video_chat_participants_invited in the class Message. The old fields will remain temporarily available.
1 parent b052771 commit 0d8a679

24 files changed

+390
-31
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ 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
1011
import io.circe.{ Decoder, Encoder }
1112
import com.typesafe.scalalogging.StrictLogging
1213

@@ -46,6 +47,7 @@ abstract class RequestHandler[F[_]](implicit monadError: MonadError[F, Throwable
4647
// Pure JSON requests
4748
case s: ApproveChatJoinRequest => sendRequest[R, ApproveChatJoinRequest](s)
4849
case s: AnswerCallbackQuery => sendRequest[R, AnswerCallbackQuery](s)
50+
case s: AnswerWebAppQuery => sendRequest[R, AnswerWebAppQuery](s)
4951
case s: AnswerInlineQuery => sendRequest[R, AnswerInlineQuery](s)
5052
case s: AnswerPreCheckoutQuery => sendRequest[R, AnswerPreCheckoutQuery](s)
5153
case s: AnswerShippingQuery => sendRequest[R, AnswerShippingQuery](s)
@@ -68,6 +70,7 @@ abstract class RequestHandler[F[_]](implicit monadError: MonadError[F, Throwable
6870
case s: GetChatMember => sendRequest[R, GetChatMember](s)
6971
case s: GetChatMemberCount => sendRequest[R, GetChatMemberCount](s)
7072
case s: GetChatMembersCount => sendRequest[R, GetChatMembersCount](s)
73+
case s: GetChatMenuButton => sendRequest[R, GetChatMenuButton](s)
7174
case s: GetFile => sendRequest[R, GetFile](s)
7275
case s: GetGameHighScores => sendRequest[R, GetGameHighScores](s)
7376
case s: GetMe.type => sendRequest[R, GetMe.type](s)
@@ -94,6 +97,7 @@ abstract class RequestHandler[F[_]](implicit monadError: MonadError[F, Throwable
9497
case s: SendPoll => sendRequest[R, SendPoll](s)
9598
case s: SendVenue => sendRequest[R, SendVenue](s)
9699
case s: SetChatDescription => sendRequest[R, SetChatDescription](s)
100+
case s: SetChatMenuButton => sendRequest[R, SetChatMenuButton](s)
97101
case s: SetChatAdministratorCustomTitle => sendRequest[R, SetChatAdministratorCustomTitle](s)
98102
case s: SetChatPermissions => sendRequest[R, SetChatPermissions](s)
99103
case s: SetChatStickerSet => sendRequest[R, SetChatStickerSet](s)

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ import com.bot4s.telegram.models.BotCommandScope.BotCommandScope
1616
import com.bot4s.telegram.models.MessageEntityType.MessageEntityType
1717
import UpdateType.UpdateType
1818
import com.bot4s.telegram.models._
19-
import io.circe.Decoder
19+
import io.circe.{ Decoder, HCursor }
2020
import io.circe.generic.semiauto._
2121
import com.typesafe.scalalogging.StrictLogging
22-
import io.circe.HCursor
2322

2423
/**
2524
* Circe marshalling borrowed/inspired from [[https://github.com/nikdon/telepooz]]
@@ -71,6 +70,11 @@ trait CirceDecoders extends StrictLogging {
7170
implicit val botCommandDecoder: Decoder[BotCommand] = deriveDecoder[BotCommand]
7271

7372
implicit val chatLocationDecoder: Decoder[ChatLocation] = deriveDecoder[ChatLocation]
73+
// for v6.0 support
74+
implicit val webAppInfoDecoder: Decoder[WebAppInfo] = deriveDecoder[WebAppInfo]
75+
implicit val webAppDataDecoder: Decoder[WebAppData] = deriveDecoder[WebAppData]
76+
implicit val chatAdminRightsDecoder: Decoder[ChatAdministratorRights] = deriveDecoder[ChatAdministratorRights]
77+
implicit val sentWebAppMessageDecoder: Decoder[SentWebAppMessage] = deriveDecoder[SentWebAppMessage]
7478
// for v5.1 support
7579
implicit val chatInviteLinkDecoder: Decoder[ChatInviteLink] = deriveDecoder[ChatInviteLink]
7680
implicit val chatMemberUpdatedDecoder: Decoder[ChatMemberUpdated] = deriveDecoder[ChatMemberUpdated]
@@ -82,6 +86,8 @@ trait CirceDecoders extends StrictLogging {
8286
implicit val chatDecoder: Decoder[Chat] = deriveDecoder[Chat]
8387
implicit val chatPhotoDecoder: Decoder[ChatPhoto] = deriveDecoder[ChatPhoto]
8488

89+
implicit val KeyboardButtonPollTypeDecoder: Decoder[KeyboardButtonPollType] = deriveDecoder[KeyboardButtonPollType]
90+
8591
implicit val contactDecoder: Decoder[Contact] = deriveDecoder[Contact]
8692
implicit val documentDecoder: Decoder[Document] = deriveDecoder[Document]
8793
implicit val fileDecoder: Decoder[File] = deriveDecoder[File]
@@ -120,6 +126,11 @@ trait CirceDecoders extends StrictLogging {
120126
implicit val videoDecoder: Decoder[Video] = deriveDecoder[Video]
121127
implicit val videoNoteDecoder: Decoder[VideoNote] = deriveDecoder[VideoNote]
122128
implicit val voiceDecoder: Decoder[Voice] = deriveDecoder[Voice]
129+
implicit val videoChatEndedDecoder: Decoder[VideoChatEnded] = deriveDecoder[VideoChatEnded]
130+
implicit val videoChatParticipantsInvitedDecoder: Decoder[VideoChatParticipantsInvited] =
131+
deriveDecoder[VideoChatParticipantsInvited]
132+
implicit val videoChatScheduledDecoder: Decoder[VideoChatScheduled] = deriveDecoder[VideoChatScheduled]
133+
implicit val videoChatStartedDecoder: Decoder[VideoChatStarted.type] = deriveDecoder[VideoChatStarted.type]
123134

124135
implicit val gameHighScoreDecoder: Decoder[GameHighScore] = deriveDecoder[GameHighScore]
125136
implicit val animationDecoder: Decoder[Animation] = deriveDecoder[Animation]
@@ -177,6 +188,7 @@ trait CirceDecoders extends StrictLogging {
177188
val r: Decoder[Either[A, B]] = decB.map(Right.apply)
178189
l or r
179190
}
191+
180192
}
181193

182194
object CirceDecoders extends CirceDecoders

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,23 @@ trait CirceEncoders {
214214

215215
implicit val answerInlineQueryEncoder: Encoder[AnswerInlineQuery] = deriveConfiguredEncoder[AnswerInlineQuery]
216216

217+
// MenuButton
218+
219+
implicit val menuButtonDefaultEncoder: Encoder[MenuButtonDefault] =
220+
deriveConfiguredEncoder[MenuButtonDefault]
221+
222+
implicit val menuButtonWebAppEncoder: Encoder[MenuButtonWebApp] =
223+
deriveConfiguredEncoder[MenuButtonWebApp]
224+
225+
implicit val menuButtonCommandsEncoder: Encoder[MenuButtonCommands] =
226+
deriveConfiguredEncoder[MenuButtonCommands]
227+
228+
implicit val menuButtonEncoder: Encoder[MenuButton] = Encoder.instance {
229+
case q: MenuButtonDefault => q.asJson
230+
case q: MenuButtonWebApp => q.asJson
231+
case q: MenuButtonCommands => q.asJson
232+
}
233+
217234
// Methods
218235
implicit val getMeEncoder: Encoder[GetMe.type] = Encoder.instance(_ => io.circe.Json.Null)
219236
implicit val deleteWebhookEncoder: Encoder[DeleteWebhook.type] = Encoder.instance(_ => io.circe.Json.Null)
@@ -229,6 +246,14 @@ trait CirceEncoders {
229246
implicit val getUpdatesEncoder: Encoder[GetUpdates] = deriveConfiguredEncoder[GetUpdates]
230247

231248
implicit val chatLocationEncoder: Encoder[ChatLocation] = deriveConfiguredEncoder[ChatLocation]
249+
// for v6.0 support
250+
implicit val webAppInfoEncoder: Encoder[WebAppInfo] = deriveConfiguredEncoder[WebAppInfo]
251+
implicit val webAppDataEncoder: Encoder[WebAppData] = deriveConfiguredEncoder[WebAppData]
252+
implicit val chatAdminRightsEncoder: Encoder[ChatAdministratorRights] =
253+
deriveConfiguredEncoder[ChatAdministratorRights]
254+
implicit val answerWebAppQueryEncoder: Encoder[AnswerWebAppQuery] = deriveConfiguredEncoder[AnswerWebAppQuery]
255+
implicit val sentWebAppMessageEncoder: Encoder[SentWebAppMessage] = deriveConfiguredEncoder[SentWebAppMessage]
256+
232257
// for v5.1 support
233258
implicit val chatInviteLinkEncoder: Encoder[ChatInviteLink] = deriveConfiguredEncoder[ChatInviteLink]
234259
implicit val chatMemberUpdatedEncoder: Encoder[ChatMemberUpdated] = deriveConfiguredEncoder[ChatMemberUpdated]
@@ -289,6 +314,7 @@ trait CirceEncoders {
289314
implicit val getChatMemberCountEncoder: Encoder[GetChatMemberCount] = deriveConfiguredEncoder[GetChatMemberCount]
290315
implicit val getChatMembersCountEncoder: Encoder[GetChatMembersCount] = deriveConfiguredEncoder[GetChatMembersCount]
291316
implicit val getChatMemberEncoder: Encoder[GetChatMember] = deriveConfiguredEncoder[GetChatMember]
317+
implicit val getChatMenuButtonEncoder: Encoder[GetChatMenuButton] = deriveConfiguredEncoder[GetChatMenuButton]
292318
implicit val answerCallbackQueryEncoder: Encoder[AnswerCallbackQuery] = deriveConfiguredEncoder[AnswerCallbackQuery]
293319

294320
implicit val editMessageTextEncoder: Encoder[EditMessageText] = deriveConfiguredEncoder[EditMessageText]
@@ -327,7 +353,8 @@ trait CirceEncoders {
327353

328354
implicit val setChatStickerSetEncoder: Encoder[SetChatStickerSet] = deriveConfiguredEncoder[SetChatStickerSet]
329355

330-
implicit val setChatTitleEncoder: Encoder[SetChatTitle] = deriveConfiguredEncoder[SetChatTitle]
356+
implicit val setChatTitleEncoder: Encoder[SetChatTitle] = deriveConfiguredEncoder[SetChatTitle]
357+
implicit val setChatButtonEncoder: Encoder[SetChatMenuButton] = deriveConfiguredEncoder[SetChatMenuButton]
331358

332359
implicit val setStickerPositionInSetEncoder: Encoder[SetStickerPositionInSet] =
333360
deriveConfiguredEncoder[SetStickerPositionInSet]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.bot4s.telegram.methods
2+
3+
import com.bot4s.telegram.models.{ InlineQueryResult, SentWebAppMessage }
4+
5+
/**
6+
* Use this method to set the result of an interaction with a Web App and send a corresponding message on behalf of the user to the chat from which the query originated. On success, a SentWebAppMessage object is returned.
7+
*
8+
* @param webAppQueryId Unique identifier for the query to be answered
9+
* @param result A JSON-serialized object describing the message to be sent
10+
*/
11+
case class AnswerWebAppQuery(
12+
webAppQueryId: String,
13+
result: Option[InlineQueryResult] = None
14+
) extends JsonRequest[SentWebAppMessage]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.bot4s.telegram.methods
2+
3+
import com.bot4s.telegram.models.{ ChatId, MenuButton }
4+
5+
/**
6+
* Use this method to get the current value of the bot's menu button in a private chat, or the default menu button.
7+
* Returns MenuButton on success.
8+
*
9+
* @param chatId Integer or String Unique identifier for the target chat or username of the target channel (in the format @channelusername)
10+
*/
11+
case class GetChatMenuButton(
12+
chatId: ChatId
13+
) extends JsonRequest[MenuButton]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.bot4s.telegram.methods
2+
3+
import com.bot4s.telegram.models.ChatAdministratorRights
4+
5+
/**
6+
* Use this method to get the current default administrator rights of the bot. Returns ChatAdministratorRights on success.
7+
*
8+
* @param forChannels Optional Boolean. Pass True to change the default administrator rights of the bot in channels.
9+
* Otherwise, the default administrator rights of the bot for groups and supergroups will be changed.
10+
*/
11+
case class GetMyDefaultAdministratorRights(
12+
forChannels: Option[Boolean] = None
13+
) extends JsonRequest[ChatAdministratorRights]

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,16 @@ import com.bot4s.telegram.models.ChatId
1111
* @param chatId Integer or String Unique identifier for the target chat or username of the target channel
1212
* (in the format @channelusername)
1313
* @param userId Long Unique identifier of the target user
14+
* @param isAnonymous Boolean Optional Pass True, if the administrator's presence in the chat is hidden
15+
* @param canManageChat Boolean Optional Pass True, if the administrator can access the chat event log,
16+
* chat statistics, message statistics in channels, see channel members, see anonymous administrators in supergroups and ignore slow mode.
17+
* Implied by any other administrator privilege
1418
* @param canChangeInfo Boolean Optional Pass True, if the administrator can change chat title, photo and other settings
1519
* @param canPostMessages Boolean Optional Pass True, if the administrator can create channel posts, channels only
1620
* @param canEditMessages Boolean Optional Pass True, if the administrator can edit messages of other users, channels only
1721
* @param canDeleteMessages Boolean Optional Pass True, if the administrator can delete messages of other users
1822
* @param canInviteUsers Boolean Optional Pass True, if the administrator can invite new users to the chat
23+
* @param canManageVideoChats Boolean Optional Pass True, if the administrator can manage video chats
1924
* @param canRestrictMembers Boolean Optional Pass True, if the administrator can restrict, ban or unban chat members
2025
* @param canPinMessages Boolean Optional Pass True, if the administrator can pin messages, supergroups only
2126
* @param canPromoteMembers Boolean Optional Pass True, if the administrator can add new administrators with a subset
@@ -25,11 +30,14 @@ import com.bot4s.telegram.models.ChatId
2530
case class PromoteChatMember(
2631
chatId: ChatId,
2732
userId: Long,
33+
isAnonymous: Option[Boolean] = None,
34+
canManageChat: Option[Boolean] = None,
2835
canChangeInfo: Option[Boolean] = None,
2936
canPostMessages: Option[Boolean] = None,
3037
canEditMessages: Option[Boolean] = None,
3138
canDeleteMessages: Option[Boolean] = None,
3239
canInviteUsers: Option[Boolean] = None,
40+
canManageVideoChats: Option[Boolean] = None,
3341
canRestrictMembers: Option[Boolean] = None,
3442
canPinMessages: Option[Boolean] = None,
3543
canPromoteMembers: Option[Boolean] = None
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.bot4s.telegram.methods
2+
3+
import com.bot4s.telegram.models.{ ChatId, MenuButton, MenuButtonDefault }
4+
5+
/**
6+
* Use this method to change the bot's menu button in a private chat, or the default menu button. Returns True on success.
7+
*
8+
* @param chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
9+
* @param menuButton A JSON-serialized object for the bot's new menu button. Defaults to MenuButtonDefault
10+
*/
11+
case class SetChatMenuButton(
12+
chatId: ChatId,
13+
menuButton: Option[MenuButton] = Some(MenuButtonDefault())
14+
) extends JsonRequest[Boolean]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.bot4s.telegram.methods
2+
3+
import com.bot4s.telegram.models.ChatAdministratorRights
4+
5+
/**
6+
* Use this method to change the default administrator rights requested by the bot when it's added as an administrator to groups or channels.
7+
* These rights will be suggested to users, but they are are free to modify the list before adding the bot.
8+
* Returns True on success.
9+
*
10+
* @param rights Optional ChatAdministratorRights. A JSON-serialized object describing new default administrator rights.
11+
* If not specified, the default administrator rights will be cleared.
12+
* @param forChannels Optional Boolean. Pass True to change the default administrator rights of the bot in channels.
13+
* Otherwise, the default administrator rights of the bot for groups and supergroups will be changed.
14+
*/
15+
case class SetMyDefaultAdministratorRights(
16+
rights: Option[ChatAdministratorRights] = None,
17+
forChannels: Option[Boolean] = None
18+
) extends JsonRequest[Boolean]
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.bot4s.telegram.models
2+
3+
/**
4+
* Represents the rights of an administrator in a chat.
5+
*
6+
* @param isAnonymous Boolean True, if the user's presence in the chat is hidden
7+
* @param canManageChat Boolean True, if the administrator can access the chat event log, chat statistics, message statistics in channels, see channel members, see anonymous administrators in supergroups and ignore slow mode. Implied by any other administrator privilege
8+
* @param canDeleteMessages Boolean True, if the administrator can delete messages of other users
9+
* @param canManageVideoChats Boolean True, if the administrator can manage video chats
10+
* @param canRestrictMembers Boolean True, if the administrator can restrict, ban or unban chat members
11+
* @param canPromoteMembers Boolean True, if the administrator can add new administrators with a subset of their own privileges or demote administrators that he has promoted, directly or indirectly (promoted by administrators that were appointed by the user)
12+
* @param canChangeInfo Boolean True, if the user is allowed to change the chat title, photo and other settings
13+
* @param canInviteUsers Boolean True, if the user is allowed to invite new users to the chat
14+
* @param canPostMessages Boolean Optional. True, if the administrator can post in the channel; channels only
15+
* @param canEditMessages Boolean Optional. True, if the administrator can edit messages of other users and can pin messages; channels only
16+
* @param canPinMessages Boolean Optional. True, if the user is allowed to pin messages; groups and supergroups only
17+
* @param from Performer of the action, which resulted in the change
18+
* @param date Date the change was done in Unix time
19+
* @param chat Chat the user belongs to
20+
* @param oldChatMember Previous information about the chat member
21+
* @param newChatMember New information about the chat member
22+
* @param inviteLink Optional. Chat invite link, which was used by the user to join the chat; for joining by invite link events only.
23+
*/
24+
case class ChatAdministratorRights(
25+
isAnonymous: Boolean,
26+
canManageChat: Boolean,
27+
canDeleteMessages: Boolean,
28+
canManageVideoChats: Boolean,
29+
canRestrictMembers: Boolean,
30+
canPromoteMembers: Boolean,
31+
canChangeInfo: Boolean,
32+
canInviteUsers: Boolean,
33+
canPostMessages: Option[Boolean],
34+
canEditMessages: Option[Boolean],
35+
canPinMessages: Option[Boolean]
36+
)

0 commit comments

Comments
 (0)