Documentation
¶
Index ¶
- Constants
- func AttachSenderNames(messages []map[string]interface{}, nameMap map[string]string)
- func BuildMentionKeyMap(mentions []interface{}) map[string]string
- func BuildMergeForwardChildrenMap(items []map[string]interface{}, rootMessageID string) map[string][]map[string]interface{}
- func ConvertBodyContent(msgType string, ctx *ConvertContext) string
- func EnrichReactions(runtime *common.RuntimeContext, messages []map[string]interface{})
- func ExpandThreadReplies(runtime *common.RuntimeContext, messages []map[string]interface{}, ...)
- func FormatEventMessage(msgType, rawContent, messageID string, mentions []interface{}) map[string]interface{}
- func FormatMergeForwardSubTree(parentID string, childrenMap map[string][]map[string]interface{}) string
- func FormatMergeForwardTimestamp(tsStr string) string
- func FormatMessageItem(m map[string]interface{}, runtime *common.RuntimeContext, ...) map[string]interface{}
- func IndentLines(text, indent string) string
- func ParseJSONObject(raw string) (map[string]interface{}, error)
- func ParseMergeForwardIDs(raw string) []string
- func ResolveMentionKeys(text string, mentionMap map[string]string) string
- func ResolveSenderNames(runtime *common.RuntimeContext, messages []map[string]interface{}, ...) map[string]string
- func TruncateContent(s string, max int) string
- type ContentConverter
- type ConvertContext
Constants ¶
const ThreadRepliesPerThread = 50
ThreadRepliesPerThread is the default max replies fetched per thread in auto-expand.
const ThreadRepliesTotalLimit = 500
ThreadRepliesTotalLimit is the default max total thread replies across all threads.
Variables ¶
This section is empty.
Functions ¶
func AttachSenderNames ¶
AttachSenderNames enriches message sender objects with resolved display names. Senders whose name could not be resolved are left unchanged (id is preserved).
func BuildMentionKeyMap ¶
BuildMentionKeyMap builds a key→name lookup from the message "mentions" array.
func BuildMergeForwardChildrenMap ¶
func BuildMergeForwardChildrenMap(items []map[string]interface{}, rootMessageID string) map[string][]map[string]interface{}
BuildMergeForwardChildrenMap builds a parent→children map from a flat items list. Items without upper_message_id are treated as direct children of rootMessageID. The root container message itself is skipped.
func ConvertBodyContent ¶
func ConvertBodyContent(msgType string, ctx *ConvertContext) string
ConvertBodyContent converts body.content (a raw JSON string) to human-readable text.
func EnrichReactions ¶ added in v1.0.42
func EnrichReactions(runtime *common.RuntimeContext, messages []map[string]interface{})
EnrichReactions enriches messages with their reactions by calling the im.reactions.batch_query API. Messages are modified in place: each message that the server returns reactions for gets a "reactions" map attached.
Failure modes (warning to stderr + skip; never aborts main message output):
- batch_query call fails (network, 5xx, scope insufficient, rate limited): each message in the failed batch is marked with "reactions_error": true so callers can distinguish "fetch failed" from "no reactions exist".
- batch_query returns a partial result: only messages the server failed on get "reactions_error": true; the successful ones get the reactions block.
The "reactions_error" flag mirrors the "thread_replies_error" pattern in thread.go so downstream consumers handle both enrichment failures uniformly.
Output shape (only on messages that the server actually returned data for):
"reactions": {
"counts": [{"reaction_type": "SMILE", "count": 3}],
"details": [{"reaction_id": "...", "emoji_type": "SMILE",
"operator": {...}, "action_time": "..."}]
}
The server caps queries[] at 20 per call, so messages are split into batches of size <= 20 before invoking the API.
func ExpandThreadReplies ¶
func ExpandThreadReplies(runtime *common.RuntimeContext, messages []map[string]interface{}, nameCache map[string]string, perThread, totalLimit int)
ExpandThreadReplies fetches and embeds thread replies for messages that contain a thread_id. For each unique thread_id found in messages, it fetches up to perThread replies (asc order) and attaches them as "thread_replies" on the message. Expansion stops once totalLimit cumulative replies have been fetched. nameCache is the shared open_id→name map.
func FormatEventMessage ¶
func FormatEventMessage(msgType, rawContent, messageID string, mentions []interface{}) map[string]interface{}
FormatEventMessage converts an event-pushed message to a human-readable map. Event messages have a different structure from API responses:
- message_type (not msg_type), content is a direct JSON string (not under body.content)
- mentions are nested under message.mentions
This is the entry point for im.message.receive_v1 event processors.
func FormatMergeForwardSubTree ¶
func FormatMergeForwardSubTree(parentID string, childrenMap map[string][]map[string]interface{}) string
FormatMergeForwardSubTree recursively formats a sub-tree rooted at parentID. For merge_forward children it recurses via the tree (no extra API calls). For other types it delegates to the provided convert callback.
func FormatMergeForwardTimestamp ¶
FormatMergeForwardTimestamp formats a millisecond timestamp string to local RFC3339 with offset.
func FormatMessageItem ¶
func FormatMessageItem(m map[string]interface{}, runtime *common.RuntimeContext, senderNames ...map[string]string) map[string]interface{}
FormatMessageItem converts a raw API message item to a human-readable map. senderNames is an optional shared cache (open_id -> name) accumulated across messages; pass nil to disable sender name caching.
func IndentLines ¶
IndentLines prefixes every line of text with the given indent string.
func ParseJSONObject ¶
ParseJSONObject parses a raw JSON string into a map.
func ParseMergeForwardIDs ¶
ParseMergeForwardIDs extracts message IDs from a merge_forward content JSON.
func ResolveMentionKeys ¶
ResolveMentionKeys replaces mention keys in text with @name format.
func ResolveSenderNames ¶
func ResolveSenderNames(runtime *common.RuntimeContext, messages []map[string]interface{}, cache map[string]string) map[string]string
ResolveSenderNames batch-resolves sender open_ids to display names. The cache map is used to share already-resolved IDs across calls; newly resolved names are written back into it. Pass an empty map if no prior cache exists.
Step 1: extract names from message mentions (free, no API call). Step 2: for remaining unresolved IDs, call contact batch API (requires contact:user.base:readonly). Silently returns partial results on API error.
[#22] Changed from variadic `cache ...map[string]string` to a required parameter. The variadic form was misleading: every caller passed exactly one map, and the function body both modified it and returned it, making the dual semantics confusing.
func TruncateContent ¶
TruncateContent truncates a string for table display.
Types ¶
type ContentConverter ¶
type ContentConverter interface {
Convert(ctx *ConvertContext) string
}
ContentConverter defines the interface for converting a message type's raw content to human-readable text.
type ConvertContext ¶
type ConvertContext struct {
RawContent string
MentionMap map[string]string
// MessageID and Runtime are used by merge_forward to fetch and expand sub-messages via API.
// For other message types these can be zero values.
MessageID string
Runtime *common.RuntimeContext
// SenderNames is a shared cache of open_id -> display name, accumulated across messages
// to avoid redundant contact API calls. May be nil.
SenderNames map[string]string
}
ConvertContext holds all context needed for content conversion.