[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill-fd7ecbd2-6b55-4d66-ad07-1dcc1ff129c3":3,"$fx5ekH359hTa_qyMmx0mTx6DThDtO7-8e2dD9LSjwzyU":43},{"id":4,"title":5,"description":6,"categoryId":7,"moduleId":8,"tags":9,"prompt":10,"icon":11,"source":12,"sourceUrl":13,"authorId":14,"authorName":15,"isPublic":16,"stars":17,"runs":18,"createdAt":19,"updatedAt":19,"module":20,"category":27,"packages":34},"fd7ecbd2-6b55-4d66-ad07-1dcc1ff129c3","azure-communication-chat-java","构建具有线程管理、消息、参与者和已读回执的实时聊天应用程序。","cat_coding_devops","mod_coding","sickn33,coding","---\nname: azure-communication-chat-java\ndescription: \"Build real-time chat applications with thread management, messaging, participants, and read receipts.\"\nrisk: unknown\nsource: community\ndate_added: \"2026-02-27\"\n---\n\n# Azure Communication Chat (Java)\n\nBuild real-time chat applications with thread management, messaging, participants, and read receipts.\n\n## Installation\n\n```xml\n\u003Cdependency>\n    \u003CgroupId>com.azure\u003C\u002FgroupId>\n    \u003CartifactId>azure-communication-chat\u003C\u002FartifactId>\n    \u003Cversion>1.6.0\u003C\u002Fversion>\n\u003C\u002Fdependency>\n```\n\n## Client Creation\n\n```java\nimport com.azure.communication.chat.ChatClient;\nimport com.azure.communication.chat.ChatClientBuilder;\nimport com.azure.communication.chat.ChatThreadClient;\nimport com.azure.communication.common.CommunicationTokenCredential;\n\n\u002F\u002F ChatClient requires a CommunicationTokenCredential (user access token)\nString endpoint = \"https:\u002F\u002F\u003Cresource>.communication.azure.com\";\nString userAccessToken = \"\u003Cuser-access-token>\";\n\nCommunicationTokenCredential credential = new CommunicationTokenCredential(userAccessToken);\n\nChatClient chatClient = new ChatClientBuilder()\n    .endpoint(endpoint)\n    .credential(credential)\n    .buildClient();\n\n\u002F\u002F Async client\nChatAsyncClient chatAsyncClient = new ChatClientBuilder()\n    .endpoint(endpoint)\n    .credential(credential)\n    .buildAsyncClient();\n```\n\n## Key Concepts\n\n| Class | Purpose |\n|-------|---------|\n| `ChatClient` | Create\u002Fdelete chat threads, get thread clients |\n| `ChatThreadClient` | Operations within a thread (messages, participants, receipts) |\n| `ChatParticipant` | User in a chat thread with display name |\n| `ChatMessage` | Message content, type, sender info, timestamps |\n| `ChatMessageReadReceipt` | Read receipt tracking per participant |\n\n## Create Chat Thread\n\n```java\nimport com.azure.communication.chat.models.*;\nimport com.azure.communication.common.CommunicationUserIdentifier;\nimport java.util.ArrayList;\nimport java.util.List;\n\n\u002F\u002F Define participants\nList\u003CChatParticipant> participants = new ArrayList\u003C>();\n\nChatParticipant participant1 = new ChatParticipant()\n    .setCommunicationIdentifier(new CommunicationUserIdentifier(\"\u003Cuser-id-1>\"))\n    .setDisplayName(\"Alice\");\n\nChatParticipant participant2 = new ChatParticipant()\n    .setCommunicationIdentifier(new CommunicationUserIdentifier(\"\u003Cuser-id-2>\"))\n    .setDisplayName(\"Bob\");\n\nparticipants.add(participant1);\nparticipants.add(participant2);\n\n\u002F\u002F Create thread\nCreateChatThreadOptions options = new CreateChatThreadOptions(\"Project Discussion\")\n    .setParticipants(participants);\n\nCreateChatThreadResult result = chatClient.createChatThread(options);\nString threadId = result.getChatThread().getId();\n\n\u002F\u002F Get thread client for operations\nChatThreadClient threadClient = chatClient.getChatThreadClient(threadId);\n```\n\n## Send Messages\n\n```java\n\u002F\u002F Send text message\nSendChatMessageOptions messageOptions = new SendChatMessageOptions()\n    .setContent(\"Hello, team!\")\n    .setSenderDisplayName(\"Alice\")\n    .setType(ChatMessageType.TEXT);\n\nSendChatMessageResult sendResult = threadClient.sendMessage(messageOptions);\nString messageId = sendResult.getId();\n\n\u002F\u002F Send HTML message\nSendChatMessageOptions htmlOptions = new SendChatMessageOptions()\n    .setContent(\"\u003Cstrong>Important:\u003C\u002Fstrong> Meeting at 3pm\")\n    .setType(ChatMessageType.HTML);\n\nthreadClient.sendMessage(htmlOptions);\n```\n\n## Get Messages\n\n```java\nimport com.azure.core.util.paging.PagedIterable;\n\n\u002F\u002F List all messages\nPagedIterable\u003CChatMessage> messages = threadClient.listMessages();\n\nfor (ChatMessage message : messages) {\n    System.out.println(\"ID: \" + message.getId());\n    System.out.println(\"Type: \" + message.getType());\n    System.out.println(\"Content: \" + message.getContent().getMessage());\n    System.out.println(\"Sender: \" + message.getSenderDisplayName());\n    System.out.println(\"Created: \" + message.getCreatedOn());\n    \n    \u002F\u002F Check if edited or deleted\n    if (message.getEditedOn() != null) {\n        System.out.println(\"Edited: \" + message.getEditedOn());\n    }\n    if (message.getDeletedOn() != null) {\n        System.out.println(\"Deleted: \" + message.getDeletedOn());\n    }\n}\n\n\u002F\u002F Get specific message\nChatMessage message = threadClient.getMessage(messageId);\n```\n\n## Update and Delete Messages\n\n```java\n\u002F\u002F Update message\nUpdateChatMessageOptions updateOptions = new UpdateChatMessageOptions()\n    .setContent(\"Updated message content\");\n\nthreadClient.updateMessage(messageId, updateOptions);\n\n\u002F\u002F Delete message\nthreadClient.deleteMessage(messageId);\n```\n\n## Manage Participants\n\n```java\n\u002F\u002F List participants\nPagedIterable\u003CChatParticipant> participants = threadClient.listParticipants();\n\nfor (ChatParticipant participant : participants) {\n    CommunicationUserIdentifier user = \n        (CommunicationUserIdentifier) participant.getCommunicationIdentifier();\n    System.out.println(\"User: \" + user.getId());\n    System.out.println(\"Display Name: \" + participant.getDisplayName());\n}\n\n\u002F\u002F Add participants\nList\u003CChatParticipant> newParticipants = new ArrayList\u003C>();\nnewParticipants.add(new ChatParticipant()\n    .setCommunicationIdentifier(new CommunicationUserIdentifier(\"\u003Cnew-user-id>\"))\n    .setDisplayName(\"Charlie\")\n    .setShareHistoryTime(OffsetDateTime.now().minusDays(7))); \u002F\u002F Share last 7 days\n\nthreadClient.addParticipants(newParticipants);\n\n\u002F\u002F Remove participant\nCommunicationUserIdentifier userToRemove = new CommunicationUserIdentifier(\"\u003Cuser-id>\");\nthreadClient.removeParticipant(userToRemove);\n```\n\n## Read Receipts\n\n```java\n\u002F\u002F Send read receipt\nthreadClient.sendReadReceipt(messageId);\n\n\u002F\u002F Get read receipts\nPagedIterable\u003CChatMessageReadReceipt> receipts = threadClient.listReadReceipts();\n\nfor (ChatMessageReadReceipt receipt : receipts) {\n    System.out.println(\"Message ID: \" + receipt.getChatMessageId());\n    System.out.println(\"Read by: \" + receipt.getSenderCommunicationIdentifier());\n    System.out.println(\"Read at: \" + receipt.getReadOn());\n}\n```\n\n## Typing Notifications\n\n```java\nimport com.azure.communication.chat.models.TypingNotificationOptions;\n\n\u002F\u002F Send typing notification\nTypingNotificationOptions typingOptions = new TypingNotificationOptions()\n    .setSenderDisplayName(\"Alice\");\n\nthreadClient.sendTypingNotificationWithResponse(typingOptions, Context.NONE);\n\n\u002F\u002F Simple typing notification\nthreadClient.sendTypingNotification();\n```\n\n## Thread Operations\n\n```java\n\u002F\u002F Get thread properties\nChatThreadProperties properties = threadClient.getProperties();\nSystem.out.println(\"Topic: \" + properties.getTopic());\nSystem.out.println(\"Created: \" + properties.getCreatedOn());\n\n\u002F\u002F Update topic\nthreadClient.updateTopic(\"New Project Discussion Topic\");\n\n\u002F\u002F Delete thread\nchatClient.deleteChatThread(threadId);\n```\n\n## List Threads\n\n```java\n\u002F\u002F List all chat threads for the user\nPagedIterable\u003CChatThreadItem> threads = chatClient.listChatThreads();\n\nfor (ChatThreadItem thread : threads) {\n    System.out.println(\"Thread ID: \" + thread.getId());\n    System.out.println(\"Topic: \" + thread.getTopic());\n    System.out.println(\"Last message: \" + thread.getLastMessageReceivedOn());\n}\n```\n\n## Pagination\n\n```java\nimport com.azure.core.http.rest.PagedResponse;\n\n\u002F\u002F Paginate through messages\nint maxPageSize = 10;\nListChatMessagesOptions listOptions = new ListChatMessagesOptions()\n    .setMaxPageSize(maxPageSize);\n\nPagedIterable\u003CChatMessage> pagedMessages = threadClient.listMessages(listOptions);\n\npagedMessages.iterableByPage().forEach(page -> {\n    System.out.println(\"Page status code: \" + page.getStatusCode());\n    page.getElements().forEach(msg -> \n        System.out.println(\"Message: \" + msg.getContent().getMessage()));\n});\n```\n\n## Error Handling\n\n```java\nimport com.azure.core.exception.HttpResponseException;\n\ntry {\n    threadClient.sendMessage(messageOptions);\n} catch (HttpResponseException e) {\n    switch (e.getResponse().getStatusCode()) {\n        case 401:\n            System.out.println(\"Unauthorized - check token\");\n            break;\n        case 403:\n            System.out.println(\"Forbidden - user not in thread\");\n            break;\n        case 404:\n            System.out.println(\"Thread not found\");\n            break;\n        default:\n            System.out.println(\"Error: \" + e.getMessage());\n    }\n}\n```\n\n## Message Types\n\n| Type | Description |\n|------|-------------|\n| `TEXT` | Regular chat message |\n| `HTML` | HTML-formatted message |\n| `TOPIC_UPDATED` | System message - topic changed |\n| `PARTICIPANT_ADDED` | System message - participant joined |\n| `PARTICIPANT_REMOVED` | System message - participant left |\n\n## Environment Variables\n\n```bash\nAZURE_COMMUNICATION_ENDPOINT=https:\u002F\u002F\u003Cresource>.communication.azure.com\nAZURE_COMMUNICATION_USER_TOKEN=\u003Cuser-access-token>\n```\n\n## Best Practices\n\n1. **Token Management** - User tokens expire; implement refresh logic with `CommunicationTokenRefreshOptions`\n2. **Pagination** - Use `listMessages(options)` with `maxPageSize` for large threads\n3. **Share History** - Set `shareHistoryTime` when adding participants to control message visibility\n4. **Message Types** - Filter system messages (`PARTICIPANT_ADDED`, etc.) from user messages\n5. **Read Receipts** - Send receipts only when messages are actually viewed by user\n\n## Trigger Phrases\n\n- \"chat application Java\", \"real-time messaging Java\"\n- \"chat thread\", \"chat participants\", \"chat messages\"\n- \"read receipts\", \"typing notifications\"\n- \"Azure Communication Services chat\"\n\n## When to Use\nThis skill is applicable to execute the workflow or actions described in the overview.\n\n## Limitations\n- Use this skill only when the task clearly matches the scope described above.\n- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.\n- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.\n","","imported","https:\u002F\u002Fgithub.com\u002Fsickn33\u002Fantigravity-awesome-skills","user_system_seed","SkillOPIC",true,62,459,"2026-05-16 13:05:56",{"id":8,"name":21,"slug":22,"icon":23,"description":24,"sort":25,"createdAt":26},"编程开发","coding","mdi-code-braces","代码生成、调试、审查，提升开发效率",2,"2026-05-16 12:53:40",{"id":7,"name":28,"slug":29,"icon":30,"description":31,"moduleId":8,"sort":32,"skillCount":33,"createdAt":26},"DevOps","devops","mdi-cog-outline","CI\u002FCD、容器化、部署运维",3,162,[35],{"id":36,"skillId":4,"version":37,"fileName":38,"fileSize":39,"filePath":40,"fileHash":41,"manifest":42,"createdAt":19},"9a7f1a17-53be-4e39-860f-c59d00f1d2fe","1.0.0","azure-communication-chat-java.zip",3028,"uploads\u002Fskills\u002Ffd7ecbd2-6b55-4d66-ad07-1dcc1ff129c3\u002Fazure-communication-chat-java.zip","36c47ce4460a420ed7bc2e375bec18415174e0f3dcd1d018de019fe4ea09f0a4","[{\"path\":\"SKILL.md\",\"isDirectory\":false,\"size\":9816}]",{"code":44,"message":45,"data":46},200,"success",{"items":47,"stats":48,"page":51},[],{"averageRating":49,"totalRatings":49,"ratingCounts":50},0,[49,49,49,49,49],{"limit":52,"offset":49,"hasMore":53,"nextOffset":52,"ratedOnly":16},15,false]