GitHub

chat_event

API reference for chat_event.

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

AttributeTypeDescription
THREAD_KINDLiteralsSchema[Literal['channel', 'thread', 'direct']]
CHAT_EVENTS.Bottom[ChatEvent]

The schema of an inbound chat event.

Types

TypeDefinitionDescription
ThreadKindtype ThreadKind = Literal['channel', 'thread', 'direct']

What an address turned out to be.

ChatEventtype ChatEvent = MessageCreated | ReactionAdded | ReactionRemoved | StopRequested

An inbound chat event.

Classes

Functions

dedupe_key

dedupe_key(event) -> 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.

ParameterTypeDescription
eventChatEvent

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}"