Messages read from a chat platform (Effect's effect/chat/ChatMessage).
A ChatMessage has the same shape on every read path: inbound events,
Chat.fetch_message and Chat.history. Its text is the platform's
own content string, verbatim, and its mentions are data with offsets into
that text. text is a different format from outbound Markdown and cannot
be posted back as is.
Types#
| Type | Definition | Description |
|---|---|---|
MentionKind | type MentionKind = Literal['user', 'role', 'channel', 'broadcast'] |
Classes#
Functions#
mentions_self#
mentions_self(message) -> boolWhether the message mentions the bot. A reply to the bot is not a
mention (see replies_to_self).
| Parameter | Type | Description |
|---|---|---|
message | ChatMessage |
Returns bool
def mentions_self(message: ChatMessage) -> bool:
"""Whether the message mentions the bot. A reply to the bot is not a
mention (see ``replies_to_self``)."""
return any(mention.is_self for mention in message.mentions)replies_to_self#
replies_to_self(message) -> boolWhether the message replies to one of the bot's own messages. False
when the platform does not say who wrote the message replied to; a Slack
thread reply carries no reply_to.
| Parameter | Type | Description |
|---|---|---|
message | ChatMessage |
Returns bool
def replies_to_self(message: ChatMessage) -> bool:
"""Whether the message replies to one of the bot's own messages. False
when the platform does not say who wrote the message replied to; a Slack
thread reply carries no ``reply_to``."""
return message.reply_to is not None and message.reply_to.is_self is Trueutf16_slice#
utf16_slice(text, start, end) -> strtext[start:end] with start and end in UTF-16 code units,
the unit of Mention offsets.
| Parameter | Type | Description |
|---|---|---|
text | str | |
start | int | |
end | int |
Returns str
def utf16_slice(text: str, start: int, end: int) -> str:
"""``text[start:end]`` with ``start`` and ``end`` in UTF-16 code units,
the unit of ``Mention`` offsets."""
encoded = text.encode("utf-16-le", "surrogatepass")
return encoded[start * 2 : end * 2].decode("utf-16-le", "surrogatepass")utf16_length#
utf16_length(text) -> intHow many UTF-16 code units text takes (JavaScript's length).
| Parameter | Type | Description |
|---|---|---|
text | str |
Returns int
def utf16_length(text: str) -> int:
"""How many UTF-16 code units ``text`` takes (JavaScript's ``length``)."""
return len(text) + sum(1 for c in text if ord(c) > 0xFFFF)