Inbound events from a chat platform (Effect's effect/chat/ChatEvent).
Adapters deliver a ChatEvent to the consumer's ChatHandler.
Delivery is at-least-once: dedupe_key gives two deliveries of one event
the same key, and the library keeps no seen-store. The union is open:
later releases add members, so a match over it needs a case _.
Values#
| Attribute | Type | Description |
|---|---|---|
THREAD_KIND | LiteralsSchema[Literal['channel', 'thread', 'direct']] | |
CHAT_EVENT | S.Bottom[ChatEvent] | The schema of an inbound chat event. |
Types#
| Type | Definition | Description |
|---|---|---|
ThreadKind | type ThreadKind = Literal['channel', 'thread', 'direct'] | What an address turned out to be. |
ChatEvent | type ChatEvent = MessageCreated | ReactionAdded | ReactionRemoved | StopRequested | An inbound chat event. |
Classes#
Functions#
dedupe_key#
dedupe_key(event) -> strThe key two deliveries of one event share: message/{thread}/{id},
reaction/{message_id}/{user_id}/{emoji}/{added|removed} or
stop/{thread}/{id}, with a thread in its {platform}:{id} form.
Slack's message and app_mention for one message share a key.
| Parameter | Type | Description |
|---|---|---|
event | ChatEvent |
Returns str
def dedupe_key(event: ChatEvent) -> str:
"""The key two deliveries of one event share: ``message/{thread}/{id}``,
``reaction/{message_id}/{user_id}/{emoji}/{added|removed}`` or
``stop/{thread}/{id}``, with a thread in its ``{platform}:{id}`` form.
Slack's ``message`` and ``app_mention`` for one message share a key."""
match event:
case MessageCreated():
return f"message/{chat_thread.to_string(event.message.thread)}/{event.message.id}"
case ReactionAdded():
return f"reaction/{event.message_id}/{event.user_id}/{event.emoji}/added"
case ReactionRemoved():
return f"reaction/{event.message_id}/{event.user_id}/{event.emoji}/removed"
case StopRequested():
return f"stop/{chat_thread.to_string(event.thread)}/{event.id}"