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.
Getters
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
messageandapp_mentionfor 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;}): stringModels
An inbound chat event.
Signature
type ChatEvent = typeof ChatEvent.TypeA message that arrived in a thread.
Signature
type MessageCreated = typeof MessageCreated.TypeA reaction a user added to a message.
Signature
type ReactionAdded = typeof ReactionAdded.TypeA reaction a user removed from a message.
Signature
type ReactionRemoved = typeof ReactionRemoved.TypeA user asking the bot to stop working in a thread.
Signature
type StopRequested = typeof StopRequested.TypeWhat an address turned out to be: a channel, a thread or a direct conversation.
Signature
type ThreadKind = typeof ThreadKind.TypeSchemas
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;}>]>MessageCreated
unstableSchema 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; }>;}>ReactionAdded
unstableSchema for a reaction a user added to a message.
Details
threadis where the platform says it happened. On Slack this is the channel, even for a message in a thread;Chat.fetchMessagereturns the message with its real address.emojiis a Unicode emoji, orcustom:{name}for one the adapter's table does not know.messageAuthorIdandtimestampare 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;}>ReactionRemoved
unstableSchema 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;}>StopRequested
unstableSchema 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.
messageIdsholds 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.idis the platform's id for the request, Slack'sevent_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
unstableSchema 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"]>