Skip to content

Migrate to Slack's Events API - #418

Open
MrScribblesChess wants to merge 86 commits into
Lichess4545:mainfrom
MrScribblesChess:main
Open

Migrate to Slack's Events API#418
MrScribblesChess wants to merge 86 commits into
Lichess4545:mainfrom
MrScribblesChess:main

Conversation

@MrScribblesChess

@MrScribblesChess MrScribblesChess commented Mar 25, 2025

Copy link
Copy Markdown
Contributor

Migrating to Slack's Events API.

The problem this solves:
-Previously, chesster ran on Slack's RTM API
-But, the RTM API will be shut down on April 1, 2025
-So we're migrating chesster and adminSlack to the Events API

Details:
-Updated environment variables in code and README
-Updated chesster.start() to connect using the new API
-Updated various listeners and utils to be compatible with the change

QA:
-Tested for all three leagues for these items:
-Chesster listens in #-scheduling and updates scheduled times accordingly
-Chesster picks up on game starts and results in #-games
-Chesster responds appropriately to its normall array of commands (source, rating, summon mods etc)
-Chesster forwards messages
-Some other stuff I'm probably forgetting

Sticking points:
-@rating (without a specified username) crashes chesster if the sender of the message isn't in the db
-My local heltour was only sending one message at a time to be forwarded, so I don't know for sure if Chesster will forward bulk messages

TODO:
This was done in a fairly intense time crunch because I only found out about the RTM API deprecation in late February. Once things are settled down, I'd like to:
-Abstract chesster stuff in to utils functions, particularly this.app.event... and this.message... processing of messages to Chesster
-Write unit tests for the utils. Test the logic, not the API

@lakinwecker lakinwecker left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small changes to consider.

Comment thread package.json
"codeclimate-test-reporter": "^0.5.1",
"dotenv": "^8.2.0",
"ee-ts": "^1.0.1",
"f": "^1.4.0",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This library was last published 8 years ago, and the github repository no longer exists for it, meaning it's a ripe for attack, do we need it? Is there not another library we can use instead?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't look like we use it, we should remove it

Comment thread test/test_config.ts
clock: {
initial: 45,
increment: 45,
initial: 1,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't matter too much, but probably these shouldn't change

@@ -0,0 +1,629 @@
[ 0.000000] Linux version 4.15.0-212-generic (buildd@lcy02-amd64-083) (gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)) #223-Ubuntu SMP Tue May 23 13:09:22 UTC 2023 (Ubuntu 4.15.0-212.223-generic 4.15.18)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should not be added

Comment thread package.json
"q": "^1.5.1",
"sequelize": "^5.21.5",
"sequelize-cli": "5.5.0",
"sqlite3": "^5.1.7",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't depend on this in prod, so probably best for us to remove this as well

})
.then(() =>
resolve(
.then(([subscription, created]) => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The subscription/created parameters here are not necessary, are they?

Comment thread src/slack.ts
// here.
_.map(listener.middleware, (m) => m(this, message))
// SAME FIX HERE
this.log.info(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix makes no sense, same as before, do you know why?

Comment thread src/slack.ts
// Find command listeners first
for (const listener of this.listeners) {
if (
listener.type === 'command' &&

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit: if you invert the condition in this if, and you use continue instead, you can un-indent the following code and it makes things easier to understand

Comment thread src/slack.ts
)
if (options.event === 'member_joined_channel') {
this.app.event('member_joined_channel', async ({ event }) => {
// @ts-ignore hope I don't regret this lol

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I hope we don't too

@@ -0,0 +1,218 @@
// -----------------------------------------------------------------------------

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this actually used aside from the tests? If not, let's remove it.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can put it back in with a PR that causes it to be used, this sort of refactoring and tests is quite a good step towards what we want, but I don't like having unused code in master

Comment thread test/test_config.ts
clock: {
initial: 30,
increment: 30,
initial: 1,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, all of these changes should be ignored. this config is setup to test on the live slack

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can feel free to make and commit another config that you use for your slack, if you'd like

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants