指南
SDK
30+ 种语言客户端——主流平台手工打造,其余自动生成。
AskAIs 智能客服系统 采用协议优先的方式:一份 OpenAPI 3.1 规范、一套 WebSocket 协议,以及任何想要的语言的客户端。
第 1 梯队 —— 手工打造的 SDK
由我们维护,符合各平台习惯用法,并在适用处提供完整 UI 组件:
- Web —
@singlink/web-widget(原生 JS 包,可直接放入 script 标签,约 30 kB gzip) - iOS — Swift Package,原生 UIKit + SwiftUI 组件 (路线图)
- Android — Kotlin 库 + Jetpack Compose 组件 (路线图)
- Flutter — pub.dev 包 (路线图)
- React Native — npm 包 (路线图)
第 2 梯队 —— 自动生成的 SDK
由 openapi-generator 基于我们的规范生成的 12 种语言——每次 API 变更时重新生成:
- Python · Go · Rust · Java · C# / .NET / Unity · PHP
- Ruby · Dart · Kotlin · Swift(服务端)· TypeScript · C++(Unreal)
在本地重新生成:
# from repo root, with web app running
pnpm sdks:generate
# subset
./scripts/generate-sdks.sh python go rust第 3 梯队 —— 协议文档
对于 Lua / Perl / Crystal / Elixir / Haskell 或任何我们未预先构建的语言,直接遵循规范:
- OpenAPI:
GET /api/v1/openapi.json - WebSocket:事件 JSON 见 Web 挂件文档
快速示例
Python
from singlink_sdk import ApiClient, AuthApi, MessagesApi
from singlink_sdk.models import IdentifyRequest, SendMessageRequest
client = ApiClient()
auth = AuthApi(client)
identity = auth.identify(
IdentifyRequest(
app_id="ws_abc123",
external_id="user_42",
email="ada@example.com",
)
)
client.set_default_header("Authorization", f"Bearer {identity.token}")
msgs = MessagesApi(client)
conv = msgs.create_conversation()
msgs.send_message(
conv.id,
SendMessageRequest(content="Hi from Python!")
)Go
import (
"context"
singlink "github.com/singlink/singlink-go"
)
cfg := singlink.NewConfiguration()
api := singlink.NewAPIClient(cfg)
resp, _, _ := api.AuthApi.Identify(context.Background()).
IdentifyRequest(singlink.IdentifyRequest{
AppId: "ws_abc123",
Email: singlink.PtrString("ada@example.com"),
}).Execute()
cfg.AddDefaultHeader("Authorization", "Bearer "+resp.Token)Rust
use singlink_sdk::apis::{auth_api, configuration::Configuration};
use singlink_sdk::models::IdentifyRequest;
let mut cfg = Configuration::new();
let identity = auth_api::identify(&cfg, IdentifyRequest {
app_id: "ws_abc123".into(),
email: Some("ada@example.com".into()),
..Default::default()
}).await?;
cfg.bearer_access_token = Some(identity.token);C# / Unity
using SingChat.Sdk.Api;
using SingChat.Sdk.Client;
using SingChat.Sdk.Model;
var cfg = new Configuration();
var auth = new AuthApi(cfg);
var identity = await auth.IdentifyAsync(new IdentifyRequest(
appId: "ws_abc123",
email: "ada@example.com"
));
cfg.DefaultHeaders.Add("Authorization", $"Bearer {identity.Token}");原始 curl
# identify (no library at all)
curl https://cs.askais.com/api/v1/auth/identify \
-H "Content-Type: application/json" \
-d '{ "appId": "ws_abc123", "email": "ada@example.com" }'