serokell / tzbot

Timezone bot for Slack
Mozilla Public License 2.0
7 stars 2 forks source link

Websockets main loop #3

Closed dcastro closed 2 years ago

dcastro commented 2 years ago

UPDATE:

It seems there's a (work in progress) library that implements an interface for Slack's SocketMode called slacker. It implements some of the features we need (e.g. handle "disconnect" events).

We should try replacing our websocket loop with slacker.


Clarification and motivation

Right now, we have a websockets application that consists of a simple loop (see TzBot.Slack.SocketMode.Client.wsApp): it waits for a message, reads it as Text, prints it to stdout, repeat.

Here's what the loop should do:


Parsing events

Example jsons:

All messages delivered via websockets (aka Slack's "Socket Mode") are wrapped in an "envelope" (docs).

Inside that envelope, you'll find an "event wrapper", whose format is described here.

Inside that event wrapper, we'll find the actual event info. In this case, we're only interested in "message" events (see docs).

Some of those "message" events may have an optional "subtype": "message_changed", indicating that a message has been edited (see docs). Those events will have a previous_message field with the "old text" before it was edited. The docs seem to be incomplete in this regard, they don't mention this field, but you can see it in the example jsons above.

Note that we don't have to parse all the fields. Only the ones necessary to build an EventSummary.

Acceptance criteria