convertlib

package
v1.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 7, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const ThreadRepliesPerThread = 50

ThreadRepliesPerThread is the default max replies fetched per thread in auto-expand.

View Source
const ThreadRepliesTotalLimit = 500

ThreadRepliesTotalLimit is the default max total thread replies across all threads.

Variables

This section is empty.

Functions

func AttachSenderNames

func AttachSenderNames(messages []map[string]interface{}, nameMap map[string]string)

AttachSenderNames enriches message sender objects with resolved display names. Senders whose name could not be resolved are left unchanged (id is preserved).

func BuildMentionKeyMap

func BuildMentionKeyMap(mentions []interface{}) map[string]string

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 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

func FormatMergeForwardTimestamp(tsStr string) string

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

func IndentLines(text, indent string) string

IndentLines prefixes every line of text with the given indent string.

func ParseJSONObject

func ParseJSONObject(raw string) (map[string]interface{}, error)

ParseJSONObject parses a raw JSON string into a map.

func ParseMergeForwardIDs

func ParseMergeForwardIDs(raw string) []string

ParseMergeForwardIDs extracts message IDs from a merge_forward content JSON.

func ResolveMentionKeys

func ResolveMentionKeys(text string, mentionMap map[string]string) string

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

func TruncateContent(s string, max int) string

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL