Package: async-claude-client
Claude Client中文文档Table of ContentsClaude ClientClaude Ai1. Initialize Client2. Get All Chats3. Get Chat History4. Create a New Chat5. Delete a Chat6. Rename Chat7. Stream Ask ClaudeSlack Claude1. Create Client2. Create a New Chat Message dict3. Ask Claude in a Streaming MannerQA1. How to Get Slack User Token?2. Why is Slack Claude not responding?Claude Ai1. Initialize ClientFunction:ClaudeAiClient(cookie).init()Parameters:cookie:str | Path | list[dict]- It can be a string or a Path to a file, or a direct json.The cookie can be extracted as a JSON format using a browser extension called "cookie-editor".fromasync_claude_clientimportClaudeAiClientclaude_ai_client=awaitClaudeAiClient(cookie="cookies.json").init()2. Get All ChatsFunction:get_all_chats()Returns:A dictionary containing all chat windows.chats=awaitclaude_ai_client.get_all_chats()3. Get Chat HistoryFunction:get_chat_history()Parameters:chat_id:str- The chat_id of the chat window. It can be extracted from the last UUID in the chat window's link or
from the 'uuid' value in the data returned by the create_new_chat() function.Returns:A dictionary containing the chat history of the specified chat window.history=awaitclaude_ai_client.get_chat_history(chat_id)4. Create a New ChatFunction:create_new_chat()Returns:A dictionary containing the information of the newly created chat window. The value corresponding to the key 'uuid' is
the chat_id of the new window.new_chat=awaitclaude_ai_client.create_new_chat()5. Delete a ChatFunction:delete_chat()Parameters:chat_id:str- The chat_id of the chat window. It can be extracted from the last UUID in the chat window's link or
from the 'uuid' value in the data returned by the create_new_chat() function.awaitclaude_ai_client.delete_chat(chat_id)6. Rename ChatFunction:rename_chat()Parameters:title:str- The new name for the chat window.chat_id:str- The chat_id of the chat window. It can be extracted from the last UUID in the chat window's link or
from the 'uuid' value in the data returned by the create_new_chat() function.awaitclaude_ai_client.rename_chat(title,chat_id)7. Stream Ask ClaudeFunction:ask_stream()Parameters:question:str- The question to ask Claude.chat_id:str- The chat_id of the chat window. It can be extracted from the last UUID in the chat window's link or
from the 'uuid' value in the data returned by the create_new_chat() function.attachment:str | Path- The address string or Path of the file attachment to upload.new_chat=awaitclaude_ai_client.create_new_chat()asyncfortextinclaude_ai_client.ask_stream("Are you there?",new_chat["uuid"]):print(text,end="")Slack Claude1. Create ClientFunction:ClaudeAiClient(cookie).init()Parameters:slack_user_token:str- User token for the official Slack API. Refer
toHow to Get Slack User Tokenfor obtaining the token.claude_id:str- Member ID of the Claude app added in Slack. To obtain the Member ID, open Claude in the app and click
on Claude's avatar.channel_id:str- ID of the channel to communicate with Claude through the client. To obtain the channel ID, open the
desired channel and extract the concatenated address string before '/thread/' in the URL. It usually starts with 'C',
for example, C0579MZR3LH.pre_msg:str- Prefix for the messages sent to Claude. This is a workaround because Slack adds '@claude' to the
messages sent to Claude in the channel. This prefix is used to make Claude ignore the '@claude' mention.fromasync_claude_clientimportSlack_Claude_Client,Text,ChatUpdateslack_claude_client=Slack_Claude_Client(slack_user_token,claude_id,channel_id,"<Ignore '@Claude', neither say 'not seen' nor say 'seen'>")2. Create a New Chat Message dictFunction:create_new_chat()Return:A new dict for the chat messagechat=slack_claude_client.create_new_chat()3. Ask Claude in a Streaming MannerFunction:ask_stream_raw()Parameters:question:str- The question to askchat:dict- The chat message dictReturn Types:ChatUpdate: Updated chat message dictText: Text reply messageNote:
After each question, the chat message dict (chat) will be updated. The updatedchatshould be used for the next
interaction.chat=slack_claude_client.create_new_chat()asyncfordatainclient.ask_stream_raw("Are you there?",chat):ifisinstance(data,Text):print(data.content,end="")elifisinstance(data,ChatUpdate):# Update the chat with the new contentchat=data.contentasyncfordatainclient.ask_stream_raw("Who are you talking about?",chat):ifisinstance(data,Text):print(data.content,end="")elifisinstance(data,ChatUpdate):chat=data.contentQA1. How to Get Slack User Token?Go to https://api.slack.com  
Create a bot API  
Go to the Options

Add the following permissions to OAuth & Permissions

Bot Token Scopes require the following permissions:
channels:history
channels:join
channels:manage
channels:read
channels:write.invites
channels:write.topic
chat:write
chat:write.customize
chat:write.public
groups:history
groups:read
groups:write
groups:write.invites
groups:write.topic
im:history
im:read
im:write
im:write.invites
im:write.topic
usergroups:write
users:read
users:write

User Token Scopes require the following permissions:
admin
Administer a workspace
channels:history
channels:read
channels:write
channels:write.invites
channels:write.topic
chat:write
groups:history
groups:read
groups:write
groups:write.invites
groups:write.topic
im:history
im:read
im:write
im:write.invites
im:write.topic
mpim:history
mpim:read
mpim:write
usergroups:write
users:read
users:write

After adding all the permissions, select Install App to proceed with the installation.

Once installed, you will receive a token starting with 'xoxp', which is the Slack user token.2. Why is Slack Claude not responding?It could be an issue with the Slack server itself, and developers cannot fix it. You can try creating a new chat window to resolve the issue.