Class DingTalkInboundMapper

java.lang.Object
io.agentscope.extensions.channel.dingtalk.DingTalkInboundMapper

public final class DingTalkInboundMapper extends Object
Parses a DingTalk bot-message payload (Stream topic /v1.0/im/bot/messages/get or the HTTP callback body of the same protocol) into an InboundMessage.

Text messages (msgtype=text) map to their content. Media messages (picture / audio / video / file) map to a neutral marker text plus the ChannelMediaMetadata contract: the downloadCode and per-kind metadata are preserved verbatim, and exchanging the code for bytes (a server-side API call yielding a temporary download URL) is left to the application. Note the platform delivers audio/video/file to the robot in single chat only, not on group @-mention. richText and unknown types are returned as Optional.empty() so the caller can ack the event without dispatching to the agent.

Conversation kinds:

  • conversationType="1" → DM (PeerKind.DIRECT). Peer id = sender staff id.
  • conversationType="2" → group (PeerKind.GROUP). Peer id = conversation id.

Group messages typically arrive only when the bot is @-mentioned (DingTalk's bot SDK dispatches mention-triggered events only); the leading @bot text is preserved by the platform in text.content.

  • Constructor Details

    • DingTalkInboundMapper

      public DingTalkInboundMapper(String channelId, String accountId)
  • Method Details

    • map

      public Optional<io.agentscope.harness.agent.gateway.channel.InboundMessage> map(com.fasterxml.jackson.databind.JsonNode payload)
      Builds an InboundMessage from a DingTalk bot-message JSON payload. Text messages map to their content; media messages map to a neutral marker plus ChannelMediaMetadata entries. Returns empty for other payload kinds or malformed events so the caller can ack without dispatching.
    • extractMsgId

      public static Optional<String> extractMsgId(com.fasterxml.jackson.databind.JsonNode payload)
      Returns the msgId field if present, used by the idempotency store.