English | 中文
Since claude2 is free to use, this script may not be useful and will not be updated.
Since the claude will not be available for free slack workspaces, this repo may not be updated anymore
After several tests 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.
This graph may not be professional but i hope it makes it much easier for you to understand the code
This graph may not be professional but i hope it makes it much easier for you to understand the code
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.
use 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 baseurl
in config.js
and run this to start the nodejs server:
// static html
$ node ./web/index.js
// vue3
$ cd ./web_vue/claude_vue
$ serve
fastapi server:
$ pip3 install -r requirements.txt
$ python3 ./server/main_fastapi.py
Here's another version that provides a command-line usage:
Claude in command line
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.
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:
xoxd.Login_init()
xoxd.Login_sendCode(code)
teamlist = xoxd.teamlist
option = teamlist[index] # choose a team
xoxd.Login_selTeam(option)
xoxd.Login_getDAndSave()
After this, the login status will be saved.
use connect()
in ClaudeApp, this will automatically match the channel which claude is in and connect to the wss that slack provides
use 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 ClaudeApp.getHistory()
.