### Untitled No description -------------------------------- ### Add KOOK Spring Boot Starter Gradle Dependency Source: https://context7.com/enaium/kook-spring-boot-starter/llms.txt Adds the KOOK Spring Boot Starter to your Gradle project. This setup enables your Gradle build to include the starter library, providing access to KOOK bot integration features. Supports both Groovy and Kotlin DSLs. ```groovy // build.gradle implementation 'cn.enaium:kook-spring-boot-starter:latest-version' ``` ```kotlin // build.gradle.kts implementation("cn.enaium:kook-spring-boot-starter:latest-version") ``` -------------------------------- ### Send Various Message Types using MessageService in Java Source: https://context7.com/enaium/kook-spring-boot-starter/llms.txt Demonstrates how to send different types of messages (text, KMarkdown, replies, temporary messages) to KOOK channels using the `MessageService`. This example requires a configured `MessageService` bean and valid channel/user IDs. It showcases the flexibility of the KOOK API via the starter. ```java @Component public class MessageBot { private final MessageService messageService; public MessageBot(MessageService messageService) { this.messageService = messageService; } public void sendMessage() { // Send simple text message (type=1) MessageCreateBody textMessage = new MessageCreateBody( 1, // type: 1=text "channel-id-here", // target channel ID "Hello, KOOK!", // message content null, // no quote "unique-nonce-123", // nonce for deduplication null // not a temporary message ); MessageCreateResponse response = messageService.messageCreate(textMessage); // Send KMarkdown message (type=9) MessageCreateBody kmarkdownMsg = new MessageCreateBody( 9, "channel-id-here", "**Bold text** and *italic text*", null, null, null ); messageService.messageCreate(kmarkdownMsg); // Send reply to another message MessageCreateBody replyMsg = new MessageCreateBody( 1, "channel-id-here", "This is a reply!", "original-message-id", // quote the original message null, null ); messageService.messageCreate(replyMsg); // Send temporary message visible only to specific user MessageCreateBody tempMsg = new MessageCreateBody( 1, "channel-id-here", "Only you can see this message", null, null, "target-user-id" // temporary message for this user only ); messageService.messageCreate(tempMsg); } } ``` -------------------------------- ### Listen to Kook Message Events with Spring Listeners Source: https://context7.com/enaium/kook-spring-boot-starter/llms.txt This Java code snippet demonstrates how to use Spring's @EventListener to handle various types of incoming messages from Kook channels. It includes listeners for text, KMarkdown, image, video, file, and card messages, extracting relevant information and logging it. For KMarkdown messages, it also shows an example of sending a direct message reply using a DirectMessageService. ```java @SpringBootApplication public class KookBot { private static final Logger LOGGER = LoggerFactory.getLogger(KookBot.class); private final DirectMessageService directMessageService; public KookBot(DirectMessageService directMessageService) { this.directMessageService = directMessageService; } public static void main(String[] args) { SpringApplication.run(KookBot.class, args); } // Handle text messages (type 1) @EventListener public void onTextMessage(MessageEvent.Message1 message) { String content = message.d().content(); String authorId = message.d().authorId(); String channelId = message.d().targetId(); LOGGER.info("Text message in channel {}: {}", channelId, content); } // Handle KMarkdown messages (type 9) @EventListener public void onKMarkdownMessage(MessageEvent.Message9 message) { String nickname = message.d().extra().author().nickname(); String content = message.d().extra().kmarkdown().rawContent(); LOGGER.info("{} said: {}", nickname, content); // Auto-reply via direct message directMessageService.directMessageCreate( new DirectMessageCreateBody( null, message.d().extra().author().id(), null, "Thanks for your message!", null, null ) ); } // Handle image messages (type 2) @EventListener public void onImageMessage(MessageEvent.Message2 message) { String imageUrl = message.d().extra().attachments().url(); String authorNickname = message.d().extra().author().nickname(); LOGGER.info("{} sent image: {}", authorNickname, imageUrl); } // Handle video messages (type 3) @EventListener public void onVideoMessage(MessageEvent.Message3 message) { String videoUrl = message.d().extra().attachments().url(); int duration = message.d().extra().attachments().duration(); LOGGER.info("Video received: {} ({}s)", videoUrl, duration); } // Handle file messages (type 4) @EventListener public void onFileMessage(MessageEvent.Message4 message) { String fileName = message.d().extra().attachments().name(); int fileSize = message.d().extra().attachments().size(); String fileUrl = message.d().extra().attachments().url(); LOGGER.info("File received: {} ({}bytes) - {}", fileName, fileSize, fileUrl); } // Handle card messages (type 10) @EventListener public void onCardMessage(MessageEvent.Message10 message) { String cardContent = message.d().content(); String guildId = message.d().extra().guildId(); LOGGER.info("Card message in guild {}: {}", guildId, cardContent); } } ``` -------------------------------- ### Update and Delete Messages with Kook Spring Boot Starter Source: https://context7.com/enaium/kook-spring-boot-starter/llms.txt Provides examples for modifying and removing messages using the MessageService. Includes updating message content and deleting a message by its ID. Requires MessageUpdateBody, MessageDeleteBody, and their corresponding response objects. ```java import org.springframework.stereotype.Component; // Assuming MessageService, MessageUpdateBody, MessageUpdateResponse, MessageDeleteBody, MessageDeleteResponse are defined elsewhere @Component public class MessageManager { private final MessageService messageService; public MessageManager(MessageService messageService) { this.messageService = messageService; } public void manageMessages() { // Update message content MessageUpdateBody updateBody = new MessageUpdateBody( "message-id-to-update", "Updated message content", null, // quote (optional) null // temp_target_id (optional) ); MessageUpdateResponse updateResponse = messageService.messageUpdate(updateBody); // Delete a message MessageDeleteBody deleteBody = new MessageDeleteBody("message-id-to-delete"); MessageDeleteResponse deleteResponse = messageService.messageDelete(deleteBody); } } ``` -------------------------------- ### Untitled No description -------------------------------- ### Build a Full-Featured KOOK Bot Application with Spring Boot Source: https://context7.com/enaium/kook-spring-boot-starter/llms.txt This Java code demonstrates a complete KOOK bot application using Spring Boot. It includes event listeners for different message types and implements command handling for basic bot interactions such as responding to pings, providing bot info, sending direct messages, and adding reactions. It relies on services provided by the KOOK Spring Boot Starter for interacting with the KOOK API. ```java @SpringBootApplication public class KookBotApplication { private static final Logger LOGGER = LoggerFactory.getLogger(KookBotApplication.class); private final MessageService messageService; private final DirectMessageService directMessageService; private final GuildService guildService; private final UserService userService; public KookBotApplication( MessageService messageService, DirectMessageService directMessageService, GuildService guildService, UserService userService) { this.messageService = messageService; this.directMessageService = directMessageService; this.guildService = guildService; this.userService = userService; } public static void main(String[] args) { SpringApplication.run(KookBotApplication.class, args); } @EventListener public void handleMessage(MessageEvent.Message9 message) { String content = message.d().extra().kmarkdown().rawContent(); String authorId = message.d().extra().author().id(); String channelId = message.d().targetId(); String guildId = message.d().extra().guildId(); // Command: !ping if (content.trim().equals("!ping")) { messageService.messageCreate(new MessageCreateBody( 9, channelId, "Pong! Bot is online.", message.d().msgId(), // quote original message null, null )); } // Command: !info else if (content.trim().equals("!info")) { UserMeResponse botInfo = userService.userMe(); GuildViewResponse guildInfo = guildService.guildView(guildId); String infoMessage = String.format( "**Bot Info**\nUsername: %s\nGuild: %s\nMembers: %d", botInfo.data().username(), guildInfo.data().name(), guildInfo.data().userCount() ); messageService.messageCreate(new MessageCreateBody(9, channelId, infoMessage, null, null, null)); } // Command: !dm - send direct message to user else if (content.trim().startsWith("!dm ")) { String dmContent = content.substring(4); directMessageService.directMessageCreate(new DirectMessageCreateBody( 1, authorId, null, dmContent, null, null )); // Confirm with temporary message messageService.messageCreate(new MessageCreateBody( 1, channelId, "Sent you a DM!", null, null, authorId // temporary message for user only )); } // Command: !react else if (content.trim().equals("!react")) { messageService.messageAddReaction(new MessageAddReactionBody( message.d().msgId(), "👍" // thumbs up emoji )); } } // Log all image uploads @EventListener public void onImageUpload(MessageEvent.Message2 imageMessage) { String imageUrl = imageMessage.d().extra().attachments().url(); String uploader = imageMessage.d().extra().author().nickname(); LOGGER.info("Image uploaded by {}: {}", uploader, imageUrl); } } ``` -------------------------------- ### List and View Guilds with GuildService Source: https://context7.com/enaium/kook-spring-boot-starter/llms.txt This snippet demonstrates how to retrieve a list of guilds the bot has joined and fetch detailed information for a specific guild using the `GuildService`. It also shows how to retrieve a list of guild members and search for members by nickname. The primary dependency is `GuildService`. ```java import org.springframework.stereotype.Component; @Component public class GuildManager { private final GuildService guildService; public GuildManager(GuildService guildService) { this.guildService = guildService; } public void manageGuilds() { // Get list of guilds the bot is in GuildListResponse guilds = guildService.guildList( 1, // page number 50, // page size "-id" // sort by ID descending ); // Get detailed information about specific guild GuildViewResponse guildDetails = guildService.guildView("guild-id-here"); // Get guild member list GuildUserListResponse members = guildService.guildUserList( "guild-id-here", // guild ID null, // channel_id (filter by channel) null, // search keyword null, // role_id (filter by role) null, // mobile_verified (0=no, 1=yes) null, // active_time sort (0=asc, 1=desc) null, // joined_at sort (0=asc, 1=desc) 1, // page 50, // page size null // filter by specific user ID ); // Search for members by nickname GuildUserListResponse searchResults = guildService.guildUserList( "guild-id-here", null, "search-keyword", // search in username/nickname null, null, null, null, 1, 50, null ); } } ``` -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### List and View Messages with Kook Spring Boot Starter Source: https://context7.com/enaium/kook-spring-boot-starter/llms.txt Demonstrates how to retrieve message history from channels using the MessageService. Supports pagination, filtering by reference message (before/after), and retrieving pinned messages. Also shows how to view details of a specific message. ```java import org.springframework.stereotype.Component; // Assuming MessageService, MessageListResponse, and MessageViewResponse are defined elsewhere @Component public class MessageReader { private final MessageService messageService; public MessageReader(MessageService messageService) { this.messageService = messageService; } public void readMessages() { // Get latest messages from channel MessageListResponse latest = messageService.messageList( "channel-id-here", // target channel ID null, // no reference message (get latest) null, // not querying pinned messages null, // default flag (latest messages) 50 // page size (default 50) ); // Get messages before a specific message MessageListResponse beforeMsg = messageService.messageList( "channel-id-here", "reference-message-id", null, "before", // get messages before reference 30 ); // Get messages after a specific message MessageListResponse afterMsg = messageService.messageList( "channel-id-here", "reference-message-id", null, "after", // get messages after reference 30 ); // Get only pinned messages MessageListResponse pinnedMsgs = messageService.messageList( "channel-id-here", null, 1, // 1=pinned messages only null, 50 ); // View specific message details MessageViewResponse msgDetails = messageService.messageView("message-id-here"); } } ``` -------------------------------- ### Add Kook Spring Boot Starter Dependency (Kotlin DSL) Source: https://github.com/enaium/kook-spring-boot-starter/blob/master/README.md This snippet shows the Kotlin DSL (build.gradle.kts) syntax for adding the Kook Spring Boot Starter dependency. Remember to substitute '最新版本' with the actual latest version number. ```kts implementation("cn.enaium:kook-spring-boot-starter:最新版本") ``` -------------------------------- ### Java: Voice Channel User Operations Source: https://context7.com/enaium/kook-spring-boot-starter/llms.txt Manages users within voice channels, including listing users and moving them between channels. It utilizes the ChannelService for these operations. Dependencies include ChannelService, ChannelUserListResponse, ChannelMoveUserBody, and ChannelMoveUserResponse. ```java @Component public class VoiceChannelManager { private final ChannelService channelService; public VoiceChannelManager(ChannelService channelService) { this.channelService = channelService; } public void manageVoiceChannels() { // List users in voice channel ChannelUserListResponse voiceUsers = channelService.channelUserList("voice-channel-id"); // Move user between voice channels ChannelMoveUserBody moveUser = new ChannelMoveUserBody( "target-voice-channel-id", // destination channel "user-id-to-move" ); ChannelMoveUserResponse moveResponse = channelService.channelMoveUser(moveUser); } } ``` -------------------------------- ### Manage User Information and Bot Status with Java Source: https://context7.com/enaium/kook-spring-boot-starter/llms.txt This Java code illustrates how to retrieve user information and manage the bot's online status using the UserManager. It includes fetching the bot's own information, retrieving specific user details (with and without guild context), and setting the bot's status to offline. Dependencies include UserService and data classes like UserMeResponse, UserViewResponse, etc. ```java import org.springframework.stereotype.Component; @Component public class UserManager { private final UserService userService; public UserManager(UserService userService) { this.userService = userService; } public void manageUsers() { // Get current bot's user information UserMeResponse botInfo = userService.userMe(); System.out.println("Bot ID: " + botInfo.data().id()); System.out.println("Bot Username: " + botInfo.data().username()); // Get target user information UserViewResponse userInfo = userService.userView( "user-id-here", null // guild_id (optional, for guild-specific info) ); // Get user info with guild context UserViewResponse guildUserInfo = userService.userView( "user-id-here", "guild-id-here" // includes guild nickname, roles, etc. ); // Set bot offline UserOfflineBody offline = new UserOfflineBody(); UserOfflineResponse offlineResponse = userService.userOffline(offline); } } ``` -------------------------------- ### Java: Create and Manage Guild Channels Source: https://context7.com/enaium/kook-spring-boot-starter/llms.txt Manages guild channels by listing, viewing, creating, updating, and deleting them. It utilizes the ChannelService for these operations. Dependencies include ChannelService, ChannelListResponse, ChannelViewResponse, ChannelCreateBody, ChannelCreateResponse, ChannelUpdateBody, ChannelUpdateResponse, ChannelDeleteBody, and ChannelDeleteResponse. ```java @Component public class ChannelManager { private final ChannelService channelService; public ChannelManager(ChannelService channelService) { this.channelService = channelService; } public void manageChannels() { // List all channels in a guild ChannelListResponse channels = channelService.channelList( 1, // page 50, // page size "guild-id-here", // guild ID 1 // type: 1=text, 2=voice ); // Get channel details ChannelViewResponse channelDetails = channelService.channelView( "channel-id-here", // channel ID false // include child channels ); // Create new text channel ChannelCreateBody newChannel = new ChannelCreateBody( "guild-id-here", null, // parent_id (null = top level) "new-channel-name", 1, // type: 1=text, 2=voice null, // limit_amount (user limit for voice) null // voice_quality (1=smooth, 2=normal, 3=HD) ); ChannelCreateResponse createResponse = channelService.channelCreate(newChannel); // Create voice channel with user limit ChannelCreateBody voiceChannel = new ChannelCreateBody( "guild-id-here", null, "Voice Chat", 2, // voice channel 10, // max 10 users 2 // normal quality ); channelService.channelCreate(voiceChannel); // Update channel ChannelUpdateBody updateChannel = new ChannelUpdateBody( "channel-id-here", "updated-channel-name", null, // topic null // slow_mode (seconds) ); ChannelUpdateResponse updateResponse = channelService.channelUpdate(updateChannel); // Delete channel ChannelDeleteBody deleteChannel = new ChannelDeleteBody("channel-id-here"); ChannelDeleteResponse deleteResponse = channelService.channelDelete(deleteChannel); } } ``` -------------------------------- ### Manage Channel Role Permissions with Java Source: https://context7.com/enaium/kook-spring-boot-starter/llms.txt This Java code demonstrates how to manage role-based permissions for specific channels using the ChannelPermissionManager. It covers retrieving, creating, updating, syncing, and deleting channel role permissions. Dependencies include ChannelService, and data classes like ChannelRoleIndexResponse, ChannelRoleCreateBody, etc. ```java import org.springframework.stereotype.Component; @Component public class ChannelPermissionManager { private final ChannelService channelService; public ChannelPermissionManager(ChannelService channelService) { this.channelService = channelService; } public void managePermissions() { // Get channel role permissions ChannelRoleIndexResponse permissions = channelService.channelRoleIndex("channel-id-here"); // Create role permission override for channel ChannelRoleCreateBody createPerm = new ChannelRoleCreateBody( "channel-id-here", null, // type (role or user override) "role-id-here", // role ID null, // allow permissions (bitwise) null // deny permissions (bitwise) ); ChannelRoleCreateResponse createResponse = channelService.channelRoleCreate(createPerm); // Update channel role permissions ChannelRoleUpdateBody updatePerm = new ChannelRoleUpdateBody( "channel-id-here", "role-id-here", 2048, // allow: send messages permission 8 // deny: read messages permission ); ChannelRoleUpdateResponse updateResponse = channelService.channelRoleUpdate(updatePerm); // Sync channel permissions with parent/category ChannelRoleSyncBody syncPerm = new ChannelRoleSyncBody("channel-id-here"); ChannelRoleSyncResponse syncResponse = channelService.channelRoleSync(syncPerm); // Delete channel role override ChannelRoleDeleteBody deletePerm = new ChannelRoleDeleteBody( "channel-id-here", "role-id-here" ); ChannelRoleDeleteResponse deleteResponse = channelService.channelRoleDelete(deletePerm); } } ``` -------------------------------- ### Manage WebSocket Connection to KOOK Gateway using Java Source: https://context7.com/enaium/kook-spring-boot-starter/llms.txt This snippet shows how the DefaultClient automatically manages WebSocket connections to the KOOK gateway. No manual configuration is needed beyond setting the kook.token property. The BotInitializer component ensures the connection is established upon application startup, with an option to manually trigger reconnection. ```java import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.springframework.stereotype.Component; // WebSocket connection is automatically managed by the starter // No manual configuration needed - just set kook.token in properties @Component public class BotInitializer implements ApplicationRunner { private final DefaultClient defaultClient; public BotInitializer(DefaultClient defaultClient) { this.defaultClient = defaultClient; } @Override public void run(ApplicationArguments args) { // Connection is established automatically // But you can manually trigger reconnection if needed defaultClient.connect().subscribe(); } } ``` -------------------------------- ### Manage Guild Members with GuildService Source: https://context7.com/enaium/kook-spring-boot-starter/llms.txt This snippet illustrates how to perform various operations on guild members using the `GuildService`, including changing nicknames, kicking users, leaving guilds, muting/unmuting users in voice channels, and retrieving mute lists. It requires the `GuildService` and related request/response bodies. ```java import org.springframework.stereotype.Component; @Component public class GuildMemberManager { private final GuildService guildService; public GuildMemberManager(GuildService guildService) { this.guildService = guildService; } public void manageMember() { // Change user's nickname in guild GuildNicknameBody nicknameChange = new GuildNicknameBody( "guild-id-here", "new-nickname", "user-id-here" // null = change bot's own nickname ); GuildNicknameResponse nicknameResponse = guildService.guildNickname(nicknameChange); // Kick user from guild GuildKickoutBody kickout = new GuildKickoutBody( "guild-id-here", "user-id-to-kick" ); GuildKickoutResponse kickResponse = guildService.guildKickout(kickout); // Leave guild (bot leaves) GuildLeaveBody leave = new GuildLeaveBody("guild-id-here"); GuildLeaveResponse leaveResponse = guildService.guildLeave(leave); // Mute or deafen user in voice channel GuildMuteCreateBody mute = new GuildMuteCreateBody( "guild-id-here", "user-id-here", 1 // type: 1=mute, 2=deafen ); GuildMuteCreateResponse muteResponse = guildService.guildMuteCreate(mute); // Unmute/undeafen user GuildMuteDeleteBody unmute = new GuildMuteDeleteBody( "guild-id-here", "user-id-here", 1 // type: 1=unmute, 2=undeafen ); GuildMuteDeleteResponse unmuteResponse = guildService.guildMuteDelete(unmute); // Get mute/deafen list GuildMuteListResponse muteList = guildService.guildMuteList( "guild-id-here", "detail" // return format ); } } ``` -------------------------------- ### Add Kook Spring Boot Starter Dependency (Gradle) Source: https://github.com/enaium/kook-spring-boot-starter/blob/master/README.md This snippet demonstrates how to include the Kook Spring Boot Starter in your Gradle project using the 'implementation' configuration. Replace '最新版本' with the current latest version. ```groovy implementation 'cn.enaium:kook-spring-boot-starter:最新版本' ``` -------------------------------- ### Upload Media Files to KOOK using Java Source: https://context7.com/enaium/kook-spring-boot-starter/llms.txt This snippet demonstrates how to upload media files (images, videos, etc.) to KOOK using the AssetUploader component. It takes file data and a filename as input and returns a URL for the uploaded asset. It relies on the AssetService for the actual upload process. ```java import org.springframework.stereotype.Component; @Component public class AssetUploader { private final AssetService assetService; public AssetUploader(AssetService assetService) { this.assetService = assetService; } public String uploadAsset(byte[] fileData, String fileName) { // Upload file to KOOK AssetCreateBody uploadBody = new AssetCreateBody(fileData, fileName); AssetCreateResponse response = assetService.assetCreate(uploadBody); // Returns URL that can be used in messages return response.data().url(); } } ``` -------------------------------- ### Add KOOK Spring Boot Starter Maven Dependency Source: https://context7.com/enaium/kook-spring-boot-starter/llms.txt Integrates the KOOK Spring Boot Starter into your Maven project. This dependency declaration allows Maven to download and manage the starter library, making its functionalities available for use in your application. ```xml cn.enaium kook-spring-boot-starter latest-version ``` -------------------------------- ### Add Kook Spring Boot Starter Dependency (Maven) Source: https://github.com/enaium/kook-spring-boot-starter/blob/master/README.md This snippet shows how to add the Kook Spring Boot Starter dependency to your Maven project. Ensure you replace '最新版本' with the actual latest version available in the Maven repository. ```xml cn.enaium kook-spring-boot-starter 最新版本 ``` -------------------------------- ### List and Manage Direct Messages in Java Source: https://context7.com/enaium/kook-spring-boot-starter/llms.txt Provides functionality to retrieve direct message history, view a specific message, update its content, and delete it. Supports listing messages by user ID or chat code. Requires a configured DirectMessageService. ```java @Component public class DirectMessageReader { private final DirectMessageService directMessageService; public DirectMessageReader(DirectMessageService directMessageService) { this.directMessageService = directMessageService; } public void readDirectMessages() { // List direct messages by target user ID DirectMessageListResponse dmsByUser = directMessageService.directMessageList( null, // chat_code "target-user-id", // creates/uses existing chat null, // msg_id (reference message) null, // flag (query mode) 1, // page number 50 // page size ); // List direct messages by chat code DirectMessageListResponse dmsByChat = directMessageService.directMessageList( "chat-code-here", null, null, "before", // get messages before reference 1, 30 ); // View specific direct message DirectMessageViewResponse dmView = directMessageService.directMessageView( "chat-code-here", "message-id-here" ); // Update direct message DirectMessageUpdateBody updateDm = new DirectMessageUpdateBody( "message-id-here", "Updated DM content", null ); DirectMessageUpdateResponse updateResponse = directMessageService.directMessageUpdate(updateDm); // Delete direct message DirectMessageDeleteBody deleteDm = new DirectMessageDeleteBody("message-id-here"); DirectMessageDeleteResponse deleteResponse = directMessageService.directMessageDelete(deleteDm); } } ``` -------------------------------- ### Message Service API - Send Channel Message Source: https://context7.com/enaium/kook-spring-boot-starter/llms.txt This section details how to send various types of messages to KOOK channels using the Message Service. It covers sending plain text, KMarkdown, replies, and temporary messages. ```APIDOC ## POST /message/create ### Description Sends a message to a specified KOOK channel. Supports various message types including text, KMarkdown, replies, and temporary messages. ### Method POST ### Endpoint /message/create ### Parameters #### Request Body - **type** (Integer) - Required - The type of the message (e.g., 1 for text, 9 for KMarkdown). - **target_id** (String) - Required - The ID of the channel to send the message to. - **content** (String) - Required - The content of the message. - **quote** (String) - Optional - The ID of the message to quote for replies. - **nonce** (String) - Optional - A unique identifier for the message to prevent duplication. - **temp_target_id** (String) - Optional - The user ID for whom the temporary message is intended. ### Request Example ```json { "type": 1, "target_id": "channel-id-here", "content": "Hello, KOOK!", "nonce": "unique-nonce-123" } ``` ### Response #### Success Response (200) - **msg_id** (String) - The unique identifier of the sent message. - **msg_timestamp** (Long) - The timestamp when the message was sent. - **nonce** (String) - The nonce used for the message. #### Response Example ```json { "msg_id": "message-id-here", "msg_timestamp": 1678886400000, "nonce": "unique-nonce-123" } ``` ``` -------------------------------- ### Manage Message Reactions with Kook Spring Boot Starter Source: https://context7.com/enaium/kook-spring-boot-starter/llms.txt Illustrates how to add, list, and delete emoji reactions on messages using the MessageService. It covers adding reactions with specified emoji, retrieving users who have reacted to a message with a specific emoji, and removing a reaction. ```java import org.springframework.stereotype.Component; // Assuming MessageService, MessageAddReactionBody, MessageAddReactionResponse, MessageReactionListResponse, MessageDeleteReactionBody, MessageDeleteReactionResponse are defined elsewhere @Component public class ReactionManager { private final MessageService messageService; public ReactionManager(MessageService messageService) { this.messageService = messageService; } public void handleReactions() { // Add reaction to message MessageAddReactionBody addReaction = new MessageAddReactionBody( "message-id-here", "emoji-id-or-unicode" // emoji ID or unicode emoji ); MessageAddReactionResponse addResponse = messageService.messageAddReaction(addReaction); // Get list of users who reacted with specific emoji MessageReactionListResponse reactionList = messageService.messageReactionList( "message-id-here", "emoji-id-or-unicode" // URL-encoded emoji ); // Delete reaction from message MessageDeleteReactionBody deleteReaction = new MessageDeleteReactionBody( "message-id-here", "emoji-id-or-unicode", null // user_id (null = remove bot's reaction) ); MessageDeleteReactionResponse deleteResponse = messageService.messageDeleteReaction(deleteReaction); } } ``` -------------------------------- ### Send Direct Messages in Java Source: https://context7.com/enaium/kook-spring-boot-starter/llms.txt Demonstrates how to send direct messages to users via their user ID or chat code. Supports text and KMarkdown message types. Requires a configured DirectMessageService. ```java @Component public class DirectMessageBot { private final DirectMessageService directMessageService; public DirectMessageBot(DirectMessageService directMessageService) { this.directMessageService = directMessageService; } public void sendDirectMessage() { // Send direct message using target user ID (auto-creates chat session) DirectMessageCreateBody dmByUserId = new DirectMessageCreateBody( null, // type (1=text, 9=kmarkdown, 10=card) "target-user-id", // target user ID null, // chat_code (not needed when using target_id) "Hello from bot!", // message content null, // quote (reply to message) null // nonce ); DirectMessageCreateResponse response = directMessageService.directMessageCreate(dmByUserId); // Send direct message using chat code DirectMessageCreateBody dmByChatCode = new DirectMessageCreateBody( 9, // KMarkdown message null, "existing-chat-code", // chat session code "**Bold message**", null, null ); directMessageService.directMessageCreate(dmByChatCode); } } ``` -------------------------------- ### Configure KOOK Bot Token in Spring Boot Properties Source: https://context7.com/enaium/kook-spring-boot-starter/llms.txt Sets the authentication token for your KOOK bot within your Spring Boot application. This is a basic configuration step required for the starter to connect to the KOOK platform. It can be configured using either `.properties` or `.yml` files. ```properties # application.properties kook.token=YOUR_BOT_TOKEN_HERE ``` ```yaml # application.yml kook: token: YOUR_BOT_TOKEN_HERE ``` -------------------------------- ### Define Custom Kook Events in Spring Boot Source: https://context7.com/enaium/kook-spring-boot-starter/llms.txt This Java code defines custom event types for Kook messages, specifically for KMarkdown messages, by mapping them to custom Java record classes. It uses Spring's @Component and @Bean annotations to register these custom event definitions. This allows for more structured parsing and handling of specific message formats. ```java @Component public class CustomEventConfig { // Define custom event for KMarkdown messages with specific structure @Bean public Event customKMarkdownEvent() { return new Event(CustomKMarkdown.class, "9"); } // Custom event model public record CustomKMarkdown(D d) { public record D(Extra extra) { public record Extra(Author author, KMarkdown kmarkdown) { public record Author(String nickname, Boolean bot, String id) { } public record KMarkdown(String rawContent) { } } } } } ``` -------------------------------- ### Handle Custom Kook Events with Spring Listeners Source: https://context7.com/enaium/kook-spring-boot-starter/llms.txt This Java code demonstrates how to create a custom event listener in Spring Boot to handle the custom KMarkdown event defined in `CustomEventConfig`. The `@EventListener` annotation is used to trigger the `onCustomKMarkdown` method when an instance of `CustomEventConfig.CustomKMarkdown` is published. The handler extracts information like nickname, bot status, and message content, and includes logic to ignore messages from bots. ```java @Component public class CustomEventHandler { private static final Logger LOGGER = LoggerFactory.getLogger(CustomEventHandler.class); // Handle custom event @EventListener public void onCustomKMarkdown(CustomEventConfig.CustomKMarkdown event) { String nickname = event.d().extra().author().nickname(); boolean isBot = event.d().extra().author().bot(); String content = event.d().extra().kmarkdown().rawContent(); LOGGER.info("{} (bot={}) said: {}", nickname, isBot, content); // Ignore messages from bots if (!isBot) { // Process user message LOGGER.info("Processing user message: {}", content); } } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.