Chat class is the central orchestrator that manages adapters, event handlers, and webhook processing.
Constructor
ChatConfig<TAdapters>
required
Configuration object for the Chat instance
Chat<TAdapters, TState>
Initialized Chat instance with type-safe adapter access and webhook handlers
Example
Properties
webhooks
Event Handler Methods
onNewMention()
(thread: Thread<TState>, message: Message) => void | Promise<void>
required
Handler called when the bot is @-mentioned in an unsubscribed thread
onNewMessage()
RegExp
required
Regular expression to match against message text
(thread: Thread<TState>, message: Message) => void | Promise<void>
required
Handler called when pattern matches
onSubscribedMessage()
(thread: Thread<TState>, message: Message) => void | Promise<void>
required
Handler called for all messages in subscribed threads
Does NOT fire for:
- The message that triggered the subscription (e.g., the initial @mention)
- Messages sent by the bot itself
onReaction()
Array<EmojiValue | string>
Optional array of emoji to filter. Empty or omitted means all emoji.
(event: ReactionEvent) => void | Promise<void>
required
Handler called when reaction is added/removed
onAction()
string | string[]
Optional action ID(s) to filter. Empty or omitted means all actions.
(event: ActionEvent) => void | Promise<void>
required
Handler called when button is clicked
onSlashCommand()
string | string[]
Optional command(s) to filter (e.g., “/help” or [“help”, “/help”]). Empty or omitted means all commands.
(event: SlashCommandEvent<TState>) => void | Promise<void>
required
Handler called when command is invoked
onModalSubmit()
string | string[]
Optional callback ID(s) to filter. Empty or omitted means all modals.
(event: ModalSubmitEvent) => void | Promise<ModalResponse | undefined>
required
Handler called when modal is submitted. Can return ModalResponse to update/close the modal.
onModalClose()
string | string[]
Optional callback ID(s) to filter. Empty or omitted means all modals.
(event: ModalCloseEvent) => void | Promise<void>
required
Handler called when modal is closed/cancelled
Utility Methods
initialize()
shutdown()
getAdapter()
K extends keyof TAdapters
required
Adapter name (key from the adapters config)
TAdapters[K]
The adapter instance
openDM()
string | Author
required
Platform-specific user ID string, or an Author object from message.author or event.user
Thread<TState>
A Thread that can be used to post messages
- Slack:
U...(e.g., “U00FAKEUSER1”) - Teams:
29:...(e.g., “29:198PbJuw…”) - Google Chat:
users/...(e.g., “users/100000000000000000001”) - Discord: numeric snowflake (e.g., “1033044521375764530”)
channel()
string
required
Channel ID (e.g., “slack:C123ABC”, “gchat:spaces/ABC123”)
Channel<TState>
A Channel that can be used to list threads, post messages, etc.
reviver()
(key: string, value: unknown) => unknown
Reviver function for JSON.parse
registerSingleton()
Chat<TAdapters, TState>
Returns the Chat instance for chaining
Static Methods
getSingleton()
hasSingleton()
Type Parameters
Record<string, Adapter>
default:"Record<string, Adapter>"
Map of adapter names to Adapter instances for type-safe webhook access
object
default:"Record<string, unknown>"
Custom state type stored per-thread and per-channel
See Also
- Thread API - Thread interface for message posting and state
- Channel API - Channel interface for channel-level operations
- Message API - Message structure and metadata
- Event Handlers - Detailed handler documentation