Skip to content

Commit

Permalink
Add API methods for forum group topics
Browse files Browse the repository at this point in the history
  • Loading branch information
frececroka committed Mar 27, 2023
1 parent c41efdf commit 99e30e9
Show file tree
Hide file tree
Showing 12 changed files with 760 additions and 2 deletions.
28 changes: 26 additions & 2 deletions telegram/api/telegram.api
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,26 @@ public final class com/github/kotlintelegrambot/Bot {
public final fun banChatMember (Lcom/github/kotlintelegrambot/entities/ChatId;JLjava/lang/Long;)Lkotlin/Pair;
public static synthetic fun banChatMember$default (Lcom/github/kotlintelegrambot/Bot;Lcom/github/kotlintelegrambot/entities/ChatId;JLjava/lang/Long;ILjava/lang/Object;)Lkotlin/Pair;
public final fun close ()Lkotlin/Pair;
public final fun closeForumTopic (Lcom/github/kotlintelegrambot/entities/ChatId;J)Lcom/github/kotlintelegrambot/types/TelegramBotResult;
public final fun copyMessage (Lcom/github/kotlintelegrambot/entities/ChatId;Lcom/github/kotlintelegrambot/entities/ChatId;JLjava/lang/String;Lcom/github/kotlintelegrambot/entities/ParseMode;Ljava/util/List;Ljava/lang/Boolean;Ljava/lang/Long;Ljava/lang/Boolean;Lcom/github/kotlintelegrambot/entities/ReplyMarkup;)Lkotlin/Pair;
public static synthetic fun copyMessage$default (Lcom/github/kotlintelegrambot/Bot;Lcom/github/kotlintelegrambot/entities/ChatId;Lcom/github/kotlintelegrambot/entities/ChatId;JLjava/lang/String;Lcom/github/kotlintelegrambot/entities/ParseMode;Ljava/util/List;Ljava/lang/Boolean;Ljava/lang/Long;Ljava/lang/Boolean;Lcom/github/kotlintelegrambot/entities/ReplyMarkup;ILjava/lang/Object;)Lkotlin/Pair;
public final fun createForumTopic (Lcom/github/kotlintelegrambot/entities/ChatId;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/String;)Lcom/github/kotlintelegrambot/types/TelegramBotResult;
public static synthetic fun createForumTopic$default (Lcom/github/kotlintelegrambot/Bot;Lcom/github/kotlintelegrambot/entities/ChatId;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/String;ILjava/lang/Object;)Lcom/github/kotlintelegrambot/types/TelegramBotResult;
public final fun createNewStickerSet (JLjava/lang/String;Ljava/lang/String;Ljava/io/File;Ljava/lang/String;Ljava/lang/Boolean;Lcom/github/kotlintelegrambot/entities/stickers/MaskPosition;)Lkotlin/Pair;
public final fun createNewStickerSet (JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Boolean;Lcom/github/kotlintelegrambot/entities/stickers/MaskPosition;)Lkotlin/Pair;
public static synthetic fun createNewStickerSet$default (Lcom/github/kotlintelegrambot/Bot;JLjava/lang/String;Ljava/lang/String;Ljava/io/File;Ljava/lang/String;Ljava/lang/Boolean;Lcom/github/kotlintelegrambot/entities/stickers/MaskPosition;ILjava/lang/Object;)Lkotlin/Pair;
public static synthetic fun createNewStickerSet$default (Lcom/github/kotlintelegrambot/Bot;JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Boolean;Lcom/github/kotlintelegrambot/entities/stickers/MaskPosition;ILjava/lang/Object;)Lkotlin/Pair;
public final fun deleteChatPhoto (Lcom/github/kotlintelegrambot/entities/ChatId;)Lkotlin/Pair;
public final fun deleteChatStickerSet (Lcom/github/kotlintelegrambot/entities/ChatId;)Lcom/github/kotlintelegrambot/types/TelegramBotResult;
public final fun deleteForumTopic (Lcom/github/kotlintelegrambot/entities/ChatId;J)Lcom/github/kotlintelegrambot/types/TelegramBotResult;
public final fun deleteMessage (Lcom/github/kotlintelegrambot/entities/ChatId;J)Lcom/github/kotlintelegrambot/types/TelegramBotResult;
public final fun deleteStickerFromSet (Ljava/lang/String;)Lkotlin/Pair;
public final fun deleteWebhook (Ljava/lang/Boolean;)Lkotlin/Pair;
public static synthetic fun deleteWebhook$default (Lcom/github/kotlintelegrambot/Bot;Ljava/lang/Boolean;ILjava/lang/Object;)Lkotlin/Pair;
public final fun downloadFile (Ljava/lang/String;)Lkotlin/Pair;
public final fun downloadFileBytes (Ljava/lang/String;)[B
public final fun editForumTopic (Lcom/github/kotlintelegrambot/entities/ChatId;JLjava/lang/String;Ljava/lang/String;)Lcom/github/kotlintelegrambot/types/TelegramBotResult;
public static synthetic fun editForumTopic$default (Lcom/github/kotlintelegrambot/Bot;Lcom/github/kotlintelegrambot/entities/ChatId;JLjava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Lcom/github/kotlintelegrambot/types/TelegramBotResult;
public final fun editMessageCaption (Lcom/github/kotlintelegrambot/entities/ChatId;Ljava/lang/Long;Ljava/lang/String;Ljava/lang/String;Lcom/github/kotlintelegrambot/entities/ParseMode;Lcom/github/kotlintelegrambot/entities/ReplyMarkup;)Lkotlin/Pair;
public static synthetic fun editMessageCaption$default (Lcom/github/kotlintelegrambot/Bot;Lcom/github/kotlintelegrambot/entities/ChatId;Ljava/lang/Long;Ljava/lang/String;Ljava/lang/String;Lcom/github/kotlintelegrambot/entities/ParseMode;Lcom/github/kotlintelegrambot/entities/ReplyMarkup;ILjava/lang/Object;)Lkotlin/Pair;
public final fun editMessageLiveLocation (Lcom/github/kotlintelegrambot/entities/ChatId;Ljava/lang/Long;Ljava/lang/String;FFLcom/github/kotlintelegrambot/entities/ReplyMarkup;Ljava/lang/Integer;)Lkotlin/Pair;
Expand Down Expand Up @@ -63,6 +69,7 @@ public final class com/github/kotlintelegrambot/Bot {
public final fun processUpdate (Ljava/lang/String;)V
public final fun promoteChatMember (Lcom/github/kotlintelegrambot/entities/ChatId;JLjava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/Boolean;)Lcom/github/kotlintelegrambot/types/TelegramBotResult;
public static synthetic fun promoteChatMember$default (Lcom/github/kotlintelegrambot/Bot;Lcom/github/kotlintelegrambot/entities/ChatId;JLjava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/Boolean;ILjava/lang/Object;)Lcom/github/kotlintelegrambot/types/TelegramBotResult;
public final fun reopenForumTopic (Lcom/github/kotlintelegrambot/entities/ChatId;J)Lcom/github/kotlintelegrambot/types/TelegramBotResult;
public final fun restrictChatMember (Lcom/github/kotlintelegrambot/entities/ChatId;JLcom/github/kotlintelegrambot/entities/ChatPermissions;Ljava/lang/Long;)Lkotlin/Pair;
public static synthetic fun restrictChatMember$default (Lcom/github/kotlintelegrambot/Bot;Lcom/github/kotlintelegrambot/entities/ChatId;JLcom/github/kotlintelegrambot/entities/ChatPermissions;Ljava/lang/Long;ILjava/lang/Object;)Lkotlin/Pair;
public final fun sendAnimation (Lcom/github/kotlintelegrambot/entities/ChatId;Lcom/github/kotlintelegrambot/entities/TelegramFile;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/String;Lcom/github/kotlintelegrambot/entities/ParseMode;Ljava/lang/Boolean;Ljava/lang/Long;Ljava/lang/Boolean;Lcom/github/kotlintelegrambot/entities/ReplyMarkup;)Lkotlin/Pair;
Expand Down Expand Up @@ -98,8 +105,8 @@ public final class com/github/kotlintelegrambot/Bot {
public static synthetic fun sendLocation$default (Lcom/github/kotlintelegrambot/Bot;Lcom/github/kotlintelegrambot/entities/ChatId;FFLjava/lang/Integer;Ljava/lang/Boolean;Ljava/lang/Long;Ljava/lang/Boolean;Lcom/github/kotlintelegrambot/entities/ReplyMarkup;Ljava/lang/Integer;ILjava/lang/Object;)Lkotlin/Pair;
public final fun sendMediaGroup (Lcom/github/kotlintelegrambot/entities/ChatId;Lcom/github/kotlintelegrambot/entities/inputmedia/MediaGroup;Ljava/lang/Boolean;Ljava/lang/Long;Ljava/lang/Boolean;)Lcom/github/kotlintelegrambot/types/TelegramBotResult;
public static synthetic fun sendMediaGroup$default (Lcom/github/kotlintelegrambot/Bot;Lcom/github/kotlintelegrambot/entities/ChatId;Lcom/github/kotlintelegrambot/entities/inputmedia/MediaGroup;Ljava/lang/Boolean;Ljava/lang/Long;Ljava/lang/Boolean;ILjava/lang/Object;)Lcom/github/kotlintelegrambot/types/TelegramBotResult;
public final fun sendMessage (Lcom/github/kotlintelegrambot/entities/ChatId;Ljava/lang/String;Lcom/github/kotlintelegrambot/entities/ParseMode;Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/Long;Ljava/lang/Boolean;Lcom/github/kotlintelegrambot/entities/ReplyMarkup;)Lcom/github/kotlintelegrambot/types/TelegramBotResult;
public static synthetic fun sendMessage$default (Lcom/github/kotlintelegrambot/Bot;Lcom/github/kotlintelegrambot/entities/ChatId;Ljava/lang/String;Lcom/github/kotlintelegrambot/entities/ParseMode;Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/Long;Ljava/lang/Boolean;Lcom/github/kotlintelegrambot/entities/ReplyMarkup;ILjava/lang/Object;)Lcom/github/kotlintelegrambot/types/TelegramBotResult;
public final fun sendMessage (Lcom/github/kotlintelegrambot/entities/ChatId;Ljava/lang/String;Lcom/github/kotlintelegrambot/entities/ParseMode;Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/Long;Ljava/lang/Long;Ljava/lang/Boolean;Lcom/github/kotlintelegrambot/entities/ReplyMarkup;)Lcom/github/kotlintelegrambot/types/TelegramBotResult;
public static synthetic fun sendMessage$default (Lcom/github/kotlintelegrambot/Bot;Lcom/github/kotlintelegrambot/entities/ChatId;Ljava/lang/String;Lcom/github/kotlintelegrambot/entities/ParseMode;Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/Long;Ljava/lang/Long;Ljava/lang/Boolean;Lcom/github/kotlintelegrambot/entities/ReplyMarkup;ILjava/lang/Object;)Lcom/github/kotlintelegrambot/types/TelegramBotResult;
public final fun sendPhoto (Lcom/github/kotlintelegrambot/entities/ChatId;Lcom/github/kotlintelegrambot/entities/TelegramFile;Ljava/lang/String;Lcom/github/kotlintelegrambot/entities/ParseMode;Ljava/lang/Boolean;Ljava/lang/Long;Ljava/lang/Boolean;Lcom/github/kotlintelegrambot/entities/ReplyMarkup;)Lkotlin/Pair;
public final fun sendPhoto (Lcom/github/kotlintelegrambot/entities/ChatId;Ljava/io/File;Ljava/lang/String;Lcom/github/kotlintelegrambot/entities/ParseMode;Ljava/lang/Boolean;Ljava/lang/Long;Ljava/lang/Boolean;Lcom/github/kotlintelegrambot/entities/ReplyMarkup;)Lkotlin/Pair;
public final fun sendPhoto (Lcom/github/kotlintelegrambot/entities/ChatId;Ljava/lang/String;Ljava/lang/String;Lcom/github/kotlintelegrambot/entities/ParseMode;Ljava/lang/Boolean;Ljava/lang/Long;Ljava/lang/Boolean;Lcom/github/kotlintelegrambot/entities/ReplyMarkup;)Lkotlin/Pair;
Expand Down Expand Up @@ -724,6 +731,23 @@ public final class com/github/kotlintelegrambot/entities/ForceReplyMarkup : com/
public fun toString ()Ljava/lang/String;
}

public final class com/github/kotlintelegrambot/entities/ForumTopic {
public fun <init> (JLjava/lang/String;ILjava/lang/String;)V
public final fun component1 ()J
public final fun component2 ()Ljava/lang/String;
public final fun component3 ()I
public final fun component4 ()Ljava/lang/String;
public final fun copy (JLjava/lang/String;ILjava/lang/String;)Lcom/github/kotlintelegrambot/entities/ForumTopic;
public static synthetic fun copy$default (Lcom/github/kotlintelegrambot/entities/ForumTopic;JLjava/lang/String;ILjava/lang/String;ILjava/lang/Object;)Lcom/github/kotlintelegrambot/entities/ForumTopic;
public fun equals (Ljava/lang/Object;)Z
public final fun getIconColor ()I
public final fun getIconCustomEmojiId ()Ljava/lang/String;
public final fun getMessageThreadId ()J
public final fun getName ()Ljava/lang/String;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class com/github/kotlintelegrambot/entities/Game {
public fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Ljava/lang/String;Ljava/util/List;Lcom/github/kotlintelegrambot/entities/files/Animation;)V
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Ljava/lang/String;Ljava/util/List;Lcom/github/kotlintelegrambot/entities/files/Animation;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
Expand Down
118 changes: 118 additions & 0 deletions telegram/src/main/kotlin/com/github/kotlintelegrambot/Bot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.github.kotlintelegrambot.entities.ChatAction
import com.github.kotlintelegrambot.entities.ChatId
import com.github.kotlintelegrambot.entities.ChatMember
import com.github.kotlintelegrambot.entities.ChatPermissions
import com.github.kotlintelegrambot.entities.ForumTopic
import com.github.kotlintelegrambot.entities.InlineKeyboardMarkup
import com.github.kotlintelegrambot.entities.Message
import com.github.kotlintelegrambot.entities.MessageEntity
Expand Down Expand Up @@ -245,6 +246,8 @@ class Bot private constructor(
* @param disableNotification sends the message silently - users will receive a notification
* with no sound.
* @param replyToMessageId if the message is a reply, ID of the original message.
* @param messageThreadId to send the message to a specific topic. Works only for forum
* supergroups.
* @param replyMarkup additional options - inline keyboard, custom reply keyboard,
* instructions to remove reply keyboard or to force a reply from the user.
*
Expand All @@ -257,6 +260,7 @@ class Bot private constructor(
disableWebPagePreview: Boolean? = null,
disableNotification: Boolean? = null,
replyToMessageId: Long? = null,
messageThreadId: Long? = null,
allowSendingWithoutReply: Boolean? = null,
replyMarkup: ReplyMarkup? = null
): TelegramBotResult<Message> = apiClient.sendMessage(
Expand All @@ -266,6 +270,7 @@ class Bot private constructor(
disableWebPagePreview,
disableNotification,
replyToMessageId,
messageThreadId,
allowSendingWithoutReply,
replyMarkup
)
Expand Down Expand Up @@ -1435,6 +1440,119 @@ class Bot private constructor(
chatId: ChatId
): TelegramBotResult<Boolean> = apiClient.deleteChatStickerSet(chatId)

/**
* Use this method to create a topic in a forum supergroup chat. The bot must be an
* administrator in the chat for this to work and must have the can_manage_topics administrator
* rights. Returns information about the created topic as a ForumTopic object.
*
* @param chatId Unique identifier for the target chat or username of the target supergroup (in
* the format @supergroupusername).
* @param name Topic name, 1-128 characters.
* @param iconColor Color of the topic icon in RGB format. Currently, must be one of 7322096
* (0x6FB9F0), 16766590 (0xFFD67E), 13338331 (0xCB86DB), 9367192 (0x8EEE98), 16749490
* (0xFF93B2), or 16478047 (0xFB6F5F).
* @param iconCustomEmojiId Unique identifier of the custom emoji shown as the topic icon. Use
* getForumTopicIconStickers to get all allowed custom emoji identifiers.
*/
fun createForumTopic(
chatId: ChatId,
name: String,
iconColor: Int? = null,
iconCustomEmojiId: String? = null,
): TelegramBotResult<ForumTopic> {
return apiClient.createForumTopic(
chatId,
name,
iconColor,
iconCustomEmojiId,
)
}

/**
* Use this method to edit name and icon of a topic in a forum supergroup chat. The bot must be
* an administrator in the chat for this to work and must have can_manage_topics administrator
* rights, unless it is the creator of the topic. Returns True on success.
*
* @param chatId Unique identifier for the target chat or username of the target supergroup (in
* the format @supergroupusername).
* @param messageThreadId Unique identifier for the target message thread of the forum topic.
* @param name New topic name, 0-128 characters. If not specified or empty, the current name of
* the topic will be kept.
* @param iconCustomEmojiId New unique identifier of the custom emoji shown as the topic icon.
* Use getForumTopicIconStickers to get all allowed custom emoji identifiers. Pass an empty
* string to remove the icon. If not specified, the current icon will be kept.
*/
fun editForumTopic(
chatId: ChatId,
messageThreadId: Long,
name: String? = null,
iconCustomEmojiId: String? = null,
): TelegramBotResult<Boolean> {
return apiClient.editForumTopic(
chatId,
messageThreadId,
name,
iconCustomEmojiId,
)
}

/**
* Use this method to close an open topic in a forum supergroup chat. The bot must be an
* administrator in the chat for this to work and must have the can_manage_topics administrator
* rights, unless it is the creator of the topic. Returns True on success.
*
* @param chatId Unique identifier for the target chat or username of the target supergroup (in
* the format @supergroupusername).
* @param messageThreadId Unique identifier for the target message thread of the forum topic.
*/
fun closeForumTopic(
chatId: ChatId,
messageThreadId: Long,
): TelegramBotResult<Boolean> {
return apiClient.closeForumTopic(
chatId,
messageThreadId,
)
}

/**
* Use this method to reopen a closed topic in a forum supergroup chat. The bot must be an
* administrator in the chat for this to work and must have the can_manage_topics administrator
* rights, unless it is the creator of the topic. Returns True on success.
*
* @param chatId Unique identifier for the target chat or username of the target supergroup (in
* the format @supergroupusername).
* @param messageThreadId Unique identifier for the target message thread of the forum topic.
*/
fun reopenForumTopic(
chatId: ChatId,
messageThreadId: Long,
): TelegramBotResult<Boolean> {
return apiClient.reopenForumTopic(
chatId,
messageThreadId,
)
}

/**
* Use this method to delete a forum topic along with all its messages in a forum supergroup
* chat. The bot must be an administrator in the chat for this to work and must have the
* can_delete_messages administrator rights. Returns True on success.
*
* @param chatId Unique identifier for the target chat or username of the target supergroup (in
* the format @supergroupusername).
* @param messageThreadId Unique identifier for the target message thread of the forum topic.
*/
fun deleteForumTopic(
chatId: ChatId,
messageThreadId: Long,
): TelegramBotResult<Boolean> {
return apiClient.deleteForumTopic(
chatId,
messageThreadId,
)
}

/**
* Use this method to send answers to callback queries sent from inline keyboards. The answer
* will be displayed to the user as a notification at the top of the chat screen or as an
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.github.kotlintelegrambot.entities

import com.google.gson.annotations.SerializedName as Name

data class ForumTopic(
@Name("message_thread_id") val messageThreadId: Long,
val name: String,
@Name("icon_color") val iconColor: Int,
@Name("icon_custom_emoji_id") val iconCustomEmojiId: String,
)

0 comments on commit 99e30e9

Please sign in to comment.