ChatMessage unstable
Messages read from a chat platform.
A ChatMessage has the same shape on every read path: inbound events,
Chat.fetchMessage and Chat.history. Its text is the platform's own
content string, verbatim, and its mentions are data with offsets into that
text.
Models
A file attached to a message.
Signature
type Attachment = typeof Attachment.TypeThe author of a message.
Signature
type Author = typeof Author.TypeA message read from a chat platform.
Signature
type ChatMessage = typeof ChatMessage.TypeA mention inside a message's text.
Signature
type Mention = typeof Mention.TypeThe message a message replies to.
Signature
type ReplyTo = typeof ReplyTo.TypePredicates
mentionsSelf
unstableReturns whether the message mentions the bot.
Gotchas
A reply to the bot is not a mention. Whether it counts as one is the consumer's policy.
See
- repliesToSelf for a reply to one of the bot's messages
Signature
declare function mentionsSelf(message: { readonly attachments: readonly Array<{ readonly contentType?: string; readonly id: string; readonly name?: string; readonly size?: number; }>; readonly author: { readonly id: string; readonly isBot: boolean; readonly isSelf: boolean; readonly name?: string; }; readonly id: string; readonly mentions: readonly Array<{ readonly end: number; readonly id: string; readonly isSelf: boolean; readonly kind: "role" | "user" | "channel" | "broadcast"; readonly start: number; }>; readonly raw: Json; readonly replyTo?: { readonly authorId?: string; readonly isSelf?: boolean; readonly messageId: string; }; readonly text: string; readonly thread: { readonly id: string; readonly platform: string; }; readonly timestamp: Utc;}): booleanrepliesToSelf
unstableReturns whether the message replies to one of the bot's own messages.
When to use
Use with mentionsSelf when a reply to the bot should count as addressed
to it, whether or not the reply pings.
Gotchas
- It reads
replyTo.isSelf, so it is false when the platform does not say who wrote the message replied to. - A message in a Slack thread is not a reply to the thread's first
message: Slack messages carry no
replyTo.
See
- mentionsSelf for a mention of the bot
Signature
declare function repliesToSelf(message: { readonly attachments: readonly Array<{ readonly contentType?: string; readonly id: string; readonly name?: string; readonly size?: number; }>; readonly author: { readonly id: string; readonly isBot: boolean; readonly isSelf: boolean; readonly name?: string; }; readonly id: string; readonly mentions: readonly Array<{ readonly end: number; readonly id: string; readonly isSelf: boolean; readonly kind: "role" | "user" | "channel" | "broadcast"; readonly start: number; }>; readonly raw: Json; readonly replyTo?: { readonly authorId?: string; readonly isSelf?: boolean; readonly messageId: string; }; readonly text: string; readonly thread: { readonly id: string; readonly platform: string; }; readonly timestamp: Utc;}): booleanSchemas
Attachment
unstableSchema for a file attached to a message.
Gotchas
An attachment never carries a URL. Chat.download resolves the id again.
Signature
declare const Attachment: Struct<{ readonly contentType: optionalKey<String>; readonly id: String; readonly name: optionalKey<String>; readonly size: optionalKey<Int>;}>Schema for the author of a message.
Details
name is a best-effort display name: whatever the payload carries. There
is no lookup, so inbound messages and history can differ. Other bots'
messages are delivered with isBot: true; isSelf marks the bot's own.
Signature
declare const Author: Struct<{ readonly id: String; readonly isBot: Boolean; readonly isSelf: Boolean; readonly name: optionalKey<String>;}>ChatMessage
unstableSchema for a message read from a chat platform.
Details
threadis the address the message was posted to, the same on every read path. It never changes: a message a thread hangs off stays in the parent, also once it has replies.Chat.startThread(message.thread, message.id)is the way from such a message to its thread.textis the platform's own content string, verbatim, with mention tokens and code fences in place. One exception: Slack renders the bot's own messages withrich_textblocks from those blocks as Markdown.rawis the platform's message payload, as a JSON value.
Gotchas
text is a different format from outbound Markdown and cannot be posted
back as is.
Signature
declare const ChatMessage: Struct<{ readonly attachments: $Array<Struct<{ readonly contentType: optionalKey<String>; readonly id: String; readonly name: optionalKey<String>; readonly size: optionalKey<Int>; }>>; readonly author: Struct<{ readonly id: String; readonly isBot: Boolean; readonly isSelf: Boolean; readonly name: optionalKey<String>; }>; readonly id: String; readonly mentions: $Array<Struct<{ readonly end: Int; readonly id: String; readonly isSelf: Boolean; readonly kind: Literals<readonly ["user", "role", "channel", "broadcast"]>; readonly start: Int; }>>; readonly raw: Codec<Json, Json, never, never>; readonly replyTo: optionalKey<Struct<{ readonly authorId: optionalKey<String>; readonly isSelf: optionalKey<Boolean>; readonly messageId: String; }>>; readonly text: String; readonly thread: Struct<{ readonly id: String; readonly platform: String; }>; readonly timestamp: DateTimeUtc;}>Schema for a mention inside a message's text.
Details
start and end are offsets into ChatMessage.text, in UTF-16 code
units, so text.slice(start, end) is the platform's own token for the
mention. id is the platform id, or here, channel or everyone for
a broadcast.
Signature
declare const Mention: Struct<{ readonly end: Int; readonly id: String; readonly isSelf: Boolean; readonly kind: Literals<readonly ["user", "role", "channel", "broadcast"]>; readonly start: Int;}>Schema for the message a message replies to.
Details
authorIdis there when the platform says who wrote the message replied to. Discord leaves it out once that message is deleted.isSelfsays whether that author is the bot. An adapter sets it on every message it reads that has anauthorId. A write ignores both.
Signature
declare const ReplyTo: Struct<{ readonly authorId: optionalKey<String>; readonly isSelf: optionalKey<Boolean>; readonly messageId: String;}>