Skip to content

聊天地址与会话

源码路径: nahida_bot_sdk.chat_address

ChatAddress and SessionKey — typed identity for chats and sessions.


ChatAddress

External platform address for sending/receiving messages.

Canonical string form: channel:target_type:target_id[:thread_id].

字段类型默认值描述
channelstr
target_typeTargetType
target_idstr
thread_idstr''
is_typedboolTrue when target_type is a known standard type (not 'unknown').
chat_keystrCanonical typed chat key for session lookup.
legacy_keystrLegacy 2-segment key for backward compatibility.

方法:

parse(value: str)

Parse a colon-separated address string.

Handles typed (channel:type:id) and legacy (channel:id) formats.

from_inbound(platform: str, chat_id: str, is_group: bool = False, chat_type: str = '')

Construct a ChatAddress from inbound message metadata.

SessionKey

Session identity derived from a ChatAddress with an optional suffix.

String form: channel:type:id[:suffix...].

字段类型默认值描述
addressChatAddress
suffixstr''
is_derivedboolTrue when this key has a suffix (/new, cron isolated, etc.).

方法:

parse(value: str)

Parse a colon-separated session key string.

函数

is_valid_target_type(value: str)

Return whether a raw string is a valid ChatAddress target type.

normalize_target_type(value: str)

Convert a raw string into a TargetType, raising for invalid values.

classify_session_key(value: str)

Classify a persisted session id for migration/status displays.

类型别名

  • KNOWN_TARGET_TYPES

  • TARGET_TYPE_UNKNOWN

  • VALID_TARGET_TYPES