MCPcopy Index your code
hub / github.com/bincooo/claude-api

github.com/bincooo/claude-api @v1.0.4

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.0.4 ↗ · + Follow
80 symbols 184 edges 13 files 14 documented · 18% 1 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

ClaudeAI for Node.js/GoLang

Slack Conversation Library for ClaudeAI.

Web Conversation Library for ClaudeAI. link

Usage

npm install claude-api
// or
yarn install claude-api
import Authenticator, { type ChatResponse } from 'claude-api'
// ==========
let
    // user-token
    token = 'xoxp-xxxxx',
    // claude appid
    bot = 'U0xxxx',
    text = '讲个故事'

  const authenticator = new Authenticator(token, bot)
  // 创建一个频道,已存在则直接返回频道ID
  const channel = await authenticator.newChannel('chat-7890')
  let result: ChatResponse = await authenticator.sendMessage({
    text, channel, onMessage: (originalMessage: ChatResponse) => {
      // console.log(originalMessage)
    }
  })
  console.log('==============1\n', result)

  text = '接着讲,接下来进入修仙情节'
  result = await authenticator.sendMessage({
    text, channel,
    conversationId: result.conversationId,
    onMessage: (originalMessage: ChatResponse) => {
      // console.log(originalMessage)
    }
  })

New 🎉🎉🎉

添加了web新出的claude-2 🎉

食用方法,在浏览器内登陆,打开开发者工具(F12),复制Cookie中的sessionKey即可。

sessionKey便是程序中的token,appid就不需要了,具体使用参考示例:examples/claude-2/main.go

授权以及获取user-token

网页(登录)后, 进入api配置页面(点我跳转)。

〉》点击 【Create an app】

​ 〉》主页看见Your Apps并弹出窗口【Create an app】 〉》 点击【From scratch】

​ 〉》填写app名称以及选择工作空间(例:name: Bot, workspace: chat) 〉》 点击【Create App】

​ 〉》点击左侧边栏上的【OAuth & Permissions】 〉》 下拉至【Scopes】卡片,在 【User Token Scopes】 项下添加权限,如下:

​ channels:history, channels:read, channels:write, groups:history, groups:read, groups:write,

​ chat:write, im:history, im:write, mpim:history, mpim:write

​ 〉》回到顶部【OAuth Tokens for Your Workspace】栏,点击【Install to Workspace】,然后确认授权即可

至此,获得拥有一定权限的user-token

截屏2023-04-18 09.10.56

截屏2023-04-18 09.14.41

获取 claude appid

截屏2023-04-18 08.49.20

注意事项

由于是Slack转接Claude,Slack是有限流机制读我。 目前使用的是web协议对接,文档说明似乎是1秒一个请求,后面可以尝试使用sock对接可拥有更多的请求流量。

Credits Thank you to:

  • https://github.com/ikechan8370/chatgpt-plugin original NodeJS implementation

Extension points exported contracts — how you extend this code

Core symbols most depended-on inside this repo

Shape

Function 31
Method 28
Struct 16
Class 4
Interface 1

Languages

Go81%
TypeScript19%

Modules by API surface

internal/web-claude2.go15 symbols
internal/slack.go15 symbols
src/index.ts12 symbols
util/login.go11 symbols
types/types.go10 symbols
util/smailpro.go8 symbols
src/types.ts2 symbols
examples/main.go2 symbols
examples/claude-2/claude2_test.go2 symbols
chat.go2 symbols
examples/demo.ts1 symbols

Used by 1 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add claude-api \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page