Skip to content
// EFFECT DAYS 2026

ChatEvent unstable

Inbound events from a chat platform.

Adapters deliver a ChatEvent to the consumer's ChatHandler. Delivery is at-least-once: dedupeKey gives two deliveries of one event the same key, and the library keeps no seen-store.

13 exports Since v4.1.5 Source

Getters

dedupeKey

unstable
Since v4.1.5

Returns the key two deliveries of one event share.

When to use

Use to drop redelivered events: delivery is at-least-once and the library keeps no seen-store.

Details

  • A message is message/{thread}/{id}, with the thread in its {platform}:{id} form.
  • A reaction is reaction/{messageId}/{userId}/{emoji}/{added|removed}.
  • A stop request is stop/{thread}/{id}.
  • Slack's message and app_mention for one message share a key.

Signature

declare function dedupeKey(event: {
readonly _tag: "MessageCreated";
readonly kind: "channel" | "thread" | "direct";
readonly 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;
};
readonly raw: Json;
readonly thread: {
readonly id: string;
readonly platform: string;
};
} | {
readonly _tag: "ReactionAdded";
readonly emoji: string;
readonly messageAuthorId?: string;
readonly messageId: string;
readonly raw: Json;
readonly thread: {
readonly id: string;
readonly platform: string;
};
readonly timestamp?: Utc;
readonly userId: string;
} | {
readonly _tag: "ReactionRemoved";
readonly emoji: string;
readonly messageAuthorId?: string;
readonly messageId: string;
readonly raw: Json;
readonly thread: {
readonly id: string;
readonly platform: string;
};
readonly timestamp?: Utc;
readonly userId: string;
} | {
readonly _tag: "StopRequested";
readonly id: string;
readonly messageIds: readonly Array<string>;
readonly raw: Json;
readonly thread: {
readonly id: string;
readonly platform: string;
};
readonly userId: string;
}): string

Models

ChatEvent

type unstable
Since v4.1.5

An inbound chat event.

Signature

type ChatEvent = typeof ChatEvent.Type

MessageCreated

type unstable
Since v4.1.5

A message that arrived in a thread.

Signature

type MessageCreated = typeof MessageCreated.Type

ReactionAdded

type unstable
Since v4.1.5

A reaction a user added to a message.

Signature

type ReactionAdded = typeof ReactionAdded.Type

ReactionRemoved

type unstable
Since v4.1.5

A reaction a user removed from a message.

Signature

type ReactionRemoved = typeof ReactionRemoved.Type

StopRequested

type unstable
Since v4.1.5

A user asking the bot to stop working in a thread.

Signature

type StopRequested = typeof StopRequested.Type

ThreadKind

type unstable
Since v4.1.5

What an address turned out to be: a channel, a thread or a direct conversation.

Signature

type ThreadKind = typeof ThreadKind.Type

Schemas

ChatEvent

unstable
Since v4.1.5

Schema for an inbound chat event.

Gotchas

The union is open: later releases add members such as edits and deletes, so a switch over _tag needs a default.

Signature

declare const ChatEvent: Union<readonly [Struct<{
readonly _tag: tag<"MessageCreated">;
readonly kind: Literals<readonly ["channel", "thread", "direct"]>;
readonly message: 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 [..., ..., ..., ...]>;
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;
}>;
readonly raw: Codec<Json, Json, never, never>;
readonly thread: Struct<{
readonly id: String;
readonly platform: String;
}>;
}>, Struct<{
readonly _tag: tag<"ReactionAdded">;
emoji: String;
messageAuthorId: optionalKey<String>;
messageId: String;
raw: Codec<Json, Json, never, never>;
thread: Struct<{
readonly id: String;
readonly platform: String;
}>;
timestamp: optionalKey<DateTimeUtc>;
userId: String;
}>, Struct<{
readonly _tag: tag<"ReactionRemoved">;
emoji: String;
messageAuthorId: optionalKey<String>;
messageId: String;
raw: Codec<Json, Json, never, never>;
thread: Struct<{
readonly id: String;
readonly platform: String;
}>;
timestamp: optionalKey<DateTimeUtc>;
userId: String;
}>, Struct<{
readonly _tag: tag<"StopRequested">;
readonly id: String;
readonly messageIds: $Array<String>;
readonly raw: Codec<Json, Json, never, never>;
readonly thread: Struct<{
readonly id: String;
readonly platform: String;
}>;
readonly userId: String;
}>]>
Since v4.1.5

Schema for a message that arrived in a thread.

Details

thread equals message.thread. raw is the delivery envelope; the message payload is on message.raw.

Signature

declare const MessageCreated: Struct<{
readonly _tag: tag<"MessageCreated">;
readonly kind: Literals<readonly ["channel", "thread", "direct"]>;
readonly message: 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;
}>;
readonly raw: Codec<Json, Json, never, never>;
readonly thread: Struct<{
readonly id: String;
readonly platform: String;
}>;
}>
Since v4.1.5

Schema for a reaction a user added to a message.

Details

  • thread is where the platform says it happened. On Slack this is the channel, even for a message in a thread; Chat.fetchMessage returns the message with its real address.
  • emoji is a Unicode emoji, or custom:{name} for one the adapter's table does not know.
  • messageAuthorId and timestamp are missing when the platform does not send them.

Signature

declare const ReactionAdded: Struct<{
readonly _tag: tag<"ReactionAdded">;
emoji: String;
messageAuthorId: optionalKey<String>;
messageId: String;
raw: Codec<Json, Json, never, never>;
thread: Struct<{
readonly id: String;
readonly platform: String;
}>;
timestamp: optionalKey<DateTimeUtc>;
userId: String;
}>
Since v4.1.5

Schema for a reaction a user removed from a message.

Details

The fields mean the same as on ReactionAdded.

Signature

declare const ReactionRemoved: Struct<{
readonly _tag: tag<"ReactionRemoved">;
emoji: String;
messageAuthorId: optionalKey<String>;
messageId: String;
raw: Codec<Json, Json, never, never>;
thread: Struct<{
readonly id: String;
readonly platform: String;
}>;
timestamp: optionalKey<DateTimeUtc>;
userId: String;
}>
Since v4.1.5

Schema for a user asking the bot to stop working in a thread, as Slack's stop button does.

Details

  • Nothing has been stopped. The thread's streams stay open and keep taking text until the consumer ends them, and the platform shows a disabled button until then.
  • messageIds holds the streams the platform named. It is empty when no stream was open, but an empty list does not mean none is: Slack names the stream only on the first click in a thread. End the thread's reply whatever it holds.
  • id is the platform's id for the request, Slack's event_ts. Two deliveries of one request share it.
  • It has no kind.

Signature

declare const StopRequested: Struct<{
readonly _tag: tag<"StopRequested">;
readonly id: String;
readonly messageIds: $Array<String>;
readonly raw: Codec<Json, Json, never, never>;
readonly thread: Struct<{
readonly id: String;
readonly platform: String;
}>;
readonly userId: String;
}>

ThreadKind

unstable
Since v4.1.5

Schema for what an address turned out to be: a channel, a thread or a direct conversation.

Signature

declare const ThreadKind: Literals<readonly ["channel", "thread", "direct"]>