The project took advantage of the claude service on slack and extracted it to be a perfect alternative to claude's official api service.
1.First you need to configure the config.py file. All you need to do is configure slack's token,claude's user id, and your channel_id. Whether channel_id is configured depends on whether you want to carry a custom channel_id on request. If channel_id is not configured, a channel_id must be passed in to the api requesting the message. If this parameter is specified, if channel_id is missing in the request, the specified channel_id is used by default. If channel_id in the request is not empty, the requested channel_id value is always used.
For instructions on how to sign up and configure parameters such as slack, you can refer to this video(PS: Chinese video): [SLACK CONFIG VIDEO]
However, in addition to the permissions in the video, users:read permissions need to be configured when configuring permissions, which is used to detect whether the configured claude_id exists. Summary:[channels:history,channels:read,channels:write,groups:history,groups:read,groups:write,chat:write, im:history, im:write, mpi,users:read]
channel_id should be the channel id, please do not use private chat, and please add claude to the channel.
WORKERS indicates the number of requests that can be processed at the same time. The value can be adjusted based on the actual situation.
Related links:
token Obtain: https://api.slack.com/
The API documentation: https://api.slack.com/methods
Websocket document: https://api.slack.com/apis/connections
2.Once you have configured config.py and installed python correctly, you can start the service by clicking start_service.bat, which will automatically install the dependencies and start.
Related interfaces:
- Send and receive replies:
URL: 127.0.0.1:8000/claude/send
REQUEST BODY:
{ "channel_id" : "", "conversation_key" : "", "message": "Write a story for me" }
channel_id is optional. It can send messages to different channels, or not send messages to the channels configured in config.py.
conversation_key represents the key of a conversation. If you want to start a new conversation, you can leave it blank. The conversation_key generated by the new conversation will be displayed in the response.
- Query the specified reply:
URL: 127.0.0.1:8000/claude/receive_reply
REQUEST BODY:
{ "channel_id" : "channel_id", "conversation_key" : "conversation_key", "message_key": "message_key" }
The parameter part is basically the same as that of interface 1. message_key can be obtained in the response of interface 1.