CLaude-in-slack web api
Recently I found that claude can not be installed into slack anymore due to high demand. Maybe releasing this script now is a bit late.
After test it for a few times on my server, i’ve fixed most of the bugs and convert ‘match’ to ‘elif’, it now works just fine. please let me know if there’s something wrong on your computer.
This project is for study purposes only, if you just want claude-in-slack’s API, then slack_sdk would be a pretty good option.
Login for the first time
Saved login status
Every time after a successful login, the cookies, api-token, user_id, team_id will be saved into a json file named by your email.
checkEnv() to see if it’s been saved and use
getEnv() to load it.
Setup fastapi and nodejs server’s host and port in config.json:
"HOST": "fastapi server's host, default to 127.0.0.1",
"API_PORT": fastapi server's port, default to 8011,
"WEB_PORT": nodejs server's port, default to 80
and if you decides to use the vue app in
web_vue/claude_vue remember to change the
and run this to start the nodejs server:
// static html
$ node ./web/index.js
$ cd ./web_vue/claude_vue
$ pip3 install -r requirements.txt
$ python3 ./server/main_fastapi.py
Here’s another version that provides a command-line usage: Claude in command line
Create a ClaudeApp
After a ClaudeApp is created using
createApp(), it will setup a WebSocketServer and returns the websocket url and a ClaudeApp which hasn’t been connected to the slack.
Login or load login status
For now, it only supports email login, which requires a verification code, login by password may be supported soon.
For email login, each login process will take place in XOXD.py:
teamlist = xoxd.teamlist
option = teamlist[index] # choose a team
After this, the login status will be saved.
Match channel and connect to wss
connect() in ClaudeApp, this will automatically match the channel which claude is in and connect to the wss that slack provides
postMessage to send a message to claude. Every chat message will be received through wss and then be parsed and forward to WebSocketServer.
Claude has only one command
/reset, but i manage to make a function for that just in case it updates some new commands.
To do it, you just have to call the function under the ClaudeApp
execCmd(cmd), if it’s “/reset”, it will be noticed in wss.
I got the API but I haven’t done anything to it, haven’t figured out how to write it. the responses depend on timestamp and fp(i set it to 30), it returns a maximum of 30 messages which happens before a specific timestamp.
you can try to do it on your own, the function is