Class FeishuInboundMapper

java.lang.Object
io.agentscope.extensions.channel.feishu.FeishuInboundMapper

public final class FeishuInboundMapper extends Object
Parses a decrypted Feishu Event Subscription v2 envelope into an InboundMessage.

Schema 2.0 envelope shape:

 {
   "schema": "2.0",
   "header": {"event_id":"...","event_type":"im.message.receive_v1","tenant_key":"...", ...},
   "event": {
     "sender": {"sender_id":{"open_id":"...","user_id":"...","union_id":"..."}, "sender_type":"user"},
     "message": {
       "message_id":"om_...",
       "chat_id":"oc_...",
       "chat_type":"p2p|group",
       "message_type":"text|...",
       "content":"{\"text\":\"@_user_1 hello\"}"
     }
   }
 }
 

Text messages (message_type=text) map to their content; the inner content field is a JSON-encoded string and is re-parsed to read the text field. Media messages (image / file / folder / audio / media) map to a neutral marker text plus the ChannelMediaMetadata contract: the image_key / file_key material identifiers and per-kind metadata are preserved verbatim, and fetching the bytes (a token-authenticated message-resource download) is left to the application. Other message types (post, sticker, interactive, share cards, ...) are returned as Optional.empty() so the caller can ack without dispatching.

  • Constructor Details

    • FeishuInboundMapper

      public FeishuInboundMapper(String channelId)
  • Method Details

    • extractEventId

      public static Optional<String> extractEventId(com.fasterxml.jackson.databind.JsonNode envelope)
      Returns the header.event_id, used by the idempotency store.
    • extractUrlChallenge

      public static Optional<String> extractUrlChallenge(com.fasterxml.jackson.databind.JsonNode envelope)
      Returns the URL verification challenge if the envelope is a verification request.
    • extractSenderOpenId

      public static Optional<String> extractSenderOpenId(com.fasterxml.jackson.databind.JsonNode envelope)
      Returns the event.sender.sender_id.open_id for bot-loop self-detection.
    • extractTenantKey

      public static Optional<String> extractTenantKey(com.fasterxml.jackson.databind.JsonNode envelope)
      Returns the header.tenant_key (multi-tenant id).
    • map

      public Optional<io.agentscope.harness.agent.gateway.channel.InboundMessage> map(com.fasterxml.jackson.databind.JsonNode envelope)
      Maps a decrypted Schema 2.0 envelope into an InboundMessage. Text messages map to their content; media messages map to a neutral marker plus ChannelMediaMetadata entries. Returns empty for other message types or malformed events so the caller can ack without dispatching.