指南
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" }'