public class LarkChannel extends Object
The channel is intentionally layered on top of the generated raw SDK:
it owns inbound event normalization, safety gates, outbound sending,
streaming replies, resource download/upload helpers and policy hot updates.
Use getRawClient() as the escape hatch when an API is not yet
wrapped by this facade.
| 构造器和说明 |
|---|
LarkChannel(LarkChannelOptions options) |
| 限定符和类型 | 方法和说明 |
|---|---|
CompletableFuture<String> |
addReaction(String messageId,
String emojiType)
Add a reaction and return the Feishu
reaction_id. |
CompletableFuture<BotIdentity> |
connect()
Resolve the current bot identity and start the WebSocket transport when
configured.
|
BotIdentity |
connectSync()
Blocking variant of
connect() for command-line tools and
traditional servlet applications that do not want to manage futures. |
EventDispatcher |
createWebhookDispatcher()
Return the dispatcher that should be plugged into the user's HTTP
webhook endpoint when
transport("webhook") is used. |
CompletableFuture<Void> |
disconnect()
Stop the underlying transport and release queued safety-pipeline work.
|
void |
disconnectSync()
Blocking variant of
disconnect(). |
CompletableFuture<byte[]> |
downloadResource(String fileKey,
String type)
Download an image or file resource as bytes.
|
CompletableFuture<Void> |
editMessage(String messageId,
String text)
Edit a text message using
im.v1.message.update. |
BotIdentity |
getBotIdentity()
Bot identity resolved by
connect(), or null before the
channel is connected. |
CompletableFuture<ChatInfo> |
getChatInfo(String chatId)
Fetch basic chat metadata using open_id as user id type.
|
LarkChannelOptions.PolicyConfig |
getPolicy()
Current policy settings used by the safety gate.
|
Client |
getRawClient()
Raw SDK client used by the channel.
|
Client |
getRawWsClient()
Raw WebSocket client used by websocket transport, or
null for
webhook transport. |
boolean |
isConnected()
Whether
connect() has completed and disconnect() has
not been called. |
ChannelSubscription |
on(Map<String,ChannelEventHandler<?>> batchHandlers)
Register several handlers as one subscription.
|
<T> ChannelSubscription |
on(String eventName,
ChannelEventHandler<T> handler)
Register an event handler and replace any previous handler for the same
event name, matching the NodeJS channel subscription semantics.
|
CompletableFuture<Void> |
recallMessage(String messageId)
Recall a message sent by the bot.
|
CompletableFuture<Void> |
removeReaction(String messageId,
String reactionId)
Remove a reaction by
reaction_id. |
CompletableFuture<Boolean> |
removeReactionByEmoji(String messageId,
String emojiType)
Convenience helper that lists reactions for an emoji, finds the bot's own
reaction and removes it.
|
CompletableFuture<SendResult> |
send(String to,
SendInput input)
Send a new message or reply according to
SendOptions. |
CompletableFuture<SendResult> |
send(String to,
SendInput input,
SendOptions sendOptions) |
SendResult |
sendSync(String to,
SendInput input)
Blocking variant of
send(String, SendInput). |
SendResult |
sendSync(String to,
SendInput input,
SendOptions sendOptions)
Blocking variant of
send(String, SendInput, SendOptions). |
CompletableFuture<SendResult> |
stream(String to,
StreamInput input)
Start a streaming reply.
|
CompletableFuture<SendResult> |
stream(String to,
StreamInput input,
SendOptions sendOptions) |
SendResult |
streamSync(String to,
StreamInput input)
Blocking variant of
stream(String, StreamInput). |
SendResult |
streamSync(String to,
StreamInput input,
SendOptions sendOptions)
Blocking variant of
stream(String, StreamInput, SendOptions). |
CompletableFuture<Void> |
updateCard(String messageId,
Map<String,Object> card)
Patch an interactive card message.
|
void |
updatePolicy(LarkChannelOptions.PolicyConfig partial)
Hot-update policy settings used by the safety gate.
|
public LarkChannel(LarkChannelOptions options)
public CompletableFuture<BotIdentity> connect()
The Java facade returns BotIdentity so callers can read the
bot open_id immediately after connection. Once the future completes, bot
identity is known and the first WebSocket handshake has completed.
public BotIdentity connectSync()
connect() for command-line tools and
traditional servlet applications that do not want to manage futures.public CompletableFuture<Void> disconnect()
public void disconnectSync()
disconnect().public boolean isConnected()
connect() has completed and disconnect() has
not been called.public <T> ChannelSubscription on(String eventName, ChannelEventHandler<T> handler)
The canonical card action event name is cardAction.
public ChannelSubscription on(Map<String,ChannelEventHandler<?>> batchHandlers)
public EventDispatcher createWebhookDispatcher()
transport("webhook") is used.public Client getRawClient()
public Client getRawWsClient()
null for
webhook transport.public BotIdentity getBotIdentity()
connect(), or null before the
channel is connected.public CompletableFuture<SendResult> send(String to, SendInput input)
SendOptions.public CompletableFuture<SendResult> send(String to, SendInput input, SendOptions sendOptions)
public SendResult sendSync(String to, SendInput input)
send(String, SendInput).public SendResult sendSync(String to, SendInput input, SendOptions sendOptions)
send(String, SendInput, SendOptions).public CompletableFuture<SendResult> stream(String to, StreamInput input)
public CompletableFuture<SendResult> stream(String to, StreamInput input, SendOptions sendOptions)
public SendResult streamSync(String to, StreamInput input)
stream(String, StreamInput).public SendResult streamSync(String to, StreamInput input, SendOptions sendOptions)
stream(String, StreamInput, SendOptions).public CompletableFuture<Void> editMessage(String messageId, String text)
im.v1.message.update. Feishu only
supports editing text/post message content through this API; use
updateCard(String, Map) for interactive cards.public CompletableFuture<Void> updateCard(String messageId, Map<String,Object> card)
im.v1.message.patch; editMessage(String, String) would
hit the wrong Feishu endpoint for cards.public CompletableFuture<Void> recallMessage(String messageId)
public CompletableFuture<byte[]> downloadResource(String fileKey, String type)
public CompletableFuture<String> addReaction(String messageId, String emojiType)
reaction_id. Store the id if
you need to remove this exact reaction later.public CompletableFuture<Void> removeReaction(String messageId, String reactionId)
reaction_id. Feishu only allows the bot to
remove reactions it created.public CompletableFuture<Boolean> removeReactionByEmoji(String messageId, String emojiType)
public CompletableFuture<ChatInfo> getChatInfo(String chatId)
public void updatePolicy(LarkChannelOptions.PolicyConfig partial)
public LarkChannelOptions.PolicyConfig getPolicy()
Copyright © 2026. All rights reserved.