Call the Claude method directly through the API, which has been applied to the one-click film AI painting software. For GPT, the speed is a bit slower, but it is acceptable to be similar to GPT35, and the most important thing is that it does not cost money.
Let's first look at my application in the project.
Create a Slack workbench
Slack registration URL , please use Google Mail, click to log in to use Google Mail.
Once logged in, select Create Workspace.
After the workspace is created, fill in the basic information to create.
Team members can skip here.
What the team is doing here is followed by the channel name, which is optional here.
Associate Claude AI
Log in to claude-in-slack and click Add Application.
Association is allowed.
Prompt the following to prove it.
Jump to the workbench again and you will see the Claude icon in the lower left.
If you want to use Claude in the channel, you can add it to the specified channel, and the use needs to be @claude
valid.
Configure the Slack API
Go to the Slack workbench and start the project.
Then go to the Slack API configuration , create your project and connect to your Slack workbench.
Click Your apps in the upper right corner of the page , click Create an App, and click From scratsh. Here you need to create an application.
After creating the project, enter the workbench management and select your project.
Find User Token Scopes under the Scopes module, click the Add an OAuth Scopes button, and search to add the following permissions in turn.
channels:history
channels:read
channels:write
groups:history
groups:read
groups:write
chat:write
im:history
im:write
mpim:history
mpim:write
Finally, click the Install to Workspace button under OAuth Tokens for Your Workspace to confirm the authorization.
Upgrade Slack
There is no way to use the API to connect to Claude without upgrading, that is to say, there is no response to any text you enter.
Before the upgrade, the red part did not respond, and after the upgrade, the green part just finished.
Bonus API call code
More API functions can visit URL Slack API calls .
Only the most basic question and answer request functions are introduced here. Some functions need to be upgraded to enterprise users to access, try it yourself.
# coding=utf-8
import requests
import json
import time
import pandas as pd
token = '换成你的token'
channel = "换成你的Claude频道ID,查询频道ID看视频"
def send_msg(msg):
send_url = "https://slack.com/api/chat.postMessage"
claude = ''
data = {
"token": token,
"channel": channel,
"text": claude + msg
}
response = requests.post(url=send_url, data=data)
text = json.loads(response.text)
return text
def receive_msg(ts):
send_url = "https://slack.com/api/conversations.history"
data = {
"token": token,
"channel": channel,
"ts": ts,
"oldest":ts
}
response = requests.post(url=send_url, data=data)
text = json.loads(response.text)
return text
msg_list = [
"please help me",
# "please say how to study English?",
# "please say how to study English?",
]
list_data = []
for msg in msg_list:
data = send_msg(msg)
ts = data["ts"]
list_data.append((ts, data))
df = pd.DataFrame(list_data, columns=["ts", "data"])
df.to_excel("data.xlsx")
for i in list_data:
ts = i[0]
print(ts)
print(receive_msg(ts))
ts = "换成你要查询的时间戳"
print(receive_msg(ts))
Use result display.