通話
建立通話
目前僅支援 WhatsApp 一對一語音和視訊外撥。 準備保密的一次性 join_url。開啟連結並點擊 Start call 後才向對方撥號。
https://api.unifyport.ai/v1/calls支援渠道
呼叫前準備
在伺服器端使用資源所屬工作區的 X-Api-Key,執行範例前替換所有預留位置。
建立通話前完成 WhatsApp 授權,並檢查 runtime_status=running。目標使用目前帳號下私人對話的 conversation_id。
在瀏覽器發起通話時須允許麥克風,攝影機權限可選。
請求參數
請求標頭
X-Api-Key工作區 API Key,工作區會由此標頭解析得到。
Content-Type傳送 JSON 請求內容時請使用 application/json。
請求內容
account_id目前工作區的帳號 ID。
pattern: ^acc_[A-Za-z0-9][A-Za-z0-9_-]*$
toobject必填一對一通話對象。
to一對一通話對象。
id填入目前帳號下目標會話的 conversation_id,使用介面傳回的原始值。
minLength: 1
type目前僅支援 user;group/channel 會傳回不支援錯誤。
enum: user, group, channel
media_typevoice 為語音,video 為支援視訊的通話。
enum: voice, video
如何理解結果
201 且 state=preparing 表示通話已準備,尚未撥號。儲存 call_id,在回傳的 expires_at 前開啟保密的 join_url 並點擊 Start call;透過通話狀態或 call.answered 確認接通。
備註
準備 WhatsApp 單聊語音或視訊通話(media_type 為 voice/video)。to.id 使用 conversation_id,to.type 為 user;不接受電話號碼字串,暫不支援群組通話。準備期自建立起預設 2 分鐘,實際截止時間以傳回的 expires_at 為準;到期前開啟 join_url 並點擊 Start call 才撥號,不限制已接通的通話時長。必須允許麥克風,攝影機可選;請勿公開一次性連結。
回應 201 · 201
{
"request_id": "req_example",
"data": {
"call_id": "call_example",
"direction": "outbound",
"media_type": "video",
"state": "preparing",
"join_url": "https://calls.example.com/call/call_example#ticket=example-only",
"expires_at": "2026-09-07T12:02:00Z"
}
}
回應內容
call_id通話識別碼,掛斷時使用。
direction通話方向。
enum: outbound
media_typevoice 為語音,video 為支援視訊的通話。
enum: voice, video
state目前通話狀態。
enum: preparing
join_url短期一次性 HTTPS 連結,請勿記錄或公開。
format: uri
expires_at準備階段到期時間,RFC3339 格式。
format: date-time
回應
201201 · 201
請求成功,回應內容範例如上。
400請求錯誤
請求內容、路徑或參數無效。
401未授權
X-Api-Key 請求標頭缺少或無效。
403禁止存取
請求已識別,但不允許執行此操作。
404找不到資源
找不到請求的資源;請結合 error.code 和目前操作核對。
409衝突
目前操作與既有的渠道帳號或資源衝突。
500伺服器錯誤
服務遇到了未預期的錯誤。
501渠道尚未實作
所選渠道尚未實作此操作。
502上游閘道錯誤
渠道轉接器或上游渠道未能完成此操作。
503服務無法使用
所需的後端服務暫時無法使用。
失敗後如何處理
檢查 HTTP 狀態和 error.code/numeric_code,保留 request_id。核對帳號與 call_id;建立衝突時先查詢目前通話。重試建立或掛斷前確認目前通話狀態。 錯誤碼參考
結合目前操作讀取 HTTP 狀態、error.code 和 error.numeric_code。數字碼以字串處理。保留 request_id 排查;它不是冪等鍵或任務識別碼。
- invalid_request · 10000 · 400
檢查 JSON 請求本文與必填欄位。
處理與重試: 按目前操作與渠道條件修正參數後再請求。重複提交相同的無效請求不會解決錯誤。
示意 JSON;message 隨實際原因變化 · 400 · 10000
{ "request_id": "req_example", "error": { "code": "invalid_request", "numeric_code": "10000", "message": "Invalid request parameters" } }- invalid_target_workspace · 11003 · 400
工作區覆寫目標為空或格式無效。移除覆寫請求標頭,改用目標工作區所屬的 API Key。
觸發條件: 適用於帶有 X-Workspace-Id 工作區覆寫請求標頭的請求。
處理與重試: 按目前操作與渠道條件修正參數後再請求。重複提交相同的無效請求不會解決錯誤。
示意 JSON;message 隨實際原因變化 · 400 · 11003
{ "request_id": "req_example", "error": { "code": "invalid_target_workspace", "numeric_code": "11003", "message": "Invalid target workspace" } }- provider_invalid_request · 30001 · 400
檢查管道專屬欄位及格式。
處理與重試: 按目前操作與渠道條件修正參數後再請求。重複提交相同的無效請求不會解決錯誤。
示意 JSON;message 隨實際原因變化 · 400 · 30001
{ "request_id": "req_example", "error": { "code": "provider_invalid_request", "numeric_code": "30001", "message": "Provider rejected the request" } }- invalid_api_key · 11001 · 401
檢查 API Key 是否正確且已啟用。
處理與重試: 保留 request_id 與結構化錯誤碼,先排查目前操作,再決定下一步。
示意 JSON;message 隨實際原因變化 · 401 · 11001
{ "request_id": "req_example", "error": { "code": "invalid_api_key", "numeric_code": "11001", "message": "Invalid API key" } }- missing_api_key · 11000 · 401
請加入 X-Api-Key 請求標頭。
處理與重試: 保留 request_id 與結構化錯誤碼,先排查目前操作,再決定下一步。
範例 · 401 · 11000
{ "request_id": "req_xxx", "error": { "code": "missing_api_key", "numeric_code": "11000", "message": "Missing X-Api-Key header" } }- workspace_override_forbidden · 11002 · 403
請求嘗試使用此 API Key 無權使用的工作區覆寫。移除覆寫請求標頭,改用目標工作區所屬的 API Key。
觸發條件: 適用於帶有 X-Workspace-Id 工作區覆寫請求標頭的請求。
處理與重試: 保留 request_id 與結構化錯誤碼,先排查目前操作,再決定下一步。
範例 · 403 · 11002
{ "request_id": "req_example", "error": { "code": "workspace_override_forbidden", "numeric_code": "11002", "message": "Workspace override is not allowed" } }- account_not_found · 20020 · 404
核對 account_id,並使用帳號所屬工作區的 X-Api-Key。此工作區下未找到的帳號無法使用目前 Key 存取。
處理與重試: 核對目標識別碼、資源歸屬與目前工作區。不要將已確認缺失或無法存取的目標當作暫時服務故障自動重試。
示意 JSON;message 隨實際原因變化 · 404 · 20020
{ "request_id": "req_example", "error": { "code": "account_not_found", "numeric_code": "20020", "message": "Account not found" } }- call_not_found · 38003 · 404
目前帳號與工作區下不存在該通話。
處理與重試: 核對目標識別碼、資源歸屬與目前工作區。不要將已確認缺失或無法存取的目標當作暫時服務故障自動重試。
示意 JSON;message 隨實際原因變化 · 404 · 38003
{ "request_id": "req_example", "error": { "code": "call_not_found", "numeric_code": "38003", "message": "Call not found" } }- target_workspace_not_found · 11004 · 404
覆寫指定的工作區不存在或不可用。核對工作區歸屬,移除覆寫請求標頭並使用目標工作區 API Key;重複請求不會增加存取權限。
觸發條件: 適用於帶有 X-Workspace-Id 工作區覆寫請求標頭的請求。
處理與重試: 核對目標識別碼、資源歸屬與目前工作區。不要將已確認缺失或無法存取的目標當作暫時服務故障自動重試。
示意 JSON;message 隨實際原因變化 · 404 · 11004
{ "request_id": "req_example", "error": { "code": "target_workspace_not_found", "numeric_code": "11004", "message": "Target workspace not found" } }- account_binding_not_found · 30006 · 409
帳號尚無有效的管道連線綁定,請檢查帳號狀態。
處理與重試: 查詢授權與執行狀態,再按目標狀態和渠道支援選擇重新整理、啟動或重新連線。連線問題本身不證明已登出;執行依賴連線的業務操作前確認 running。
範例 · 409 · 30006
{ "request_id": "req_example", "error": { "code": "account_binding_not_found", "numeric_code": "30006", "message": "Account is not bound to an available server" } }- call_already_active · 38000 · 409
帳號已有受管理的活躍通話。核對已知通話與本次動作意圖;此錯誤本身不要求掛斷,也不要求反覆呼叫同一個失敗查詢。
處理與重試: 建立或結束通話前,查詢目前受管理通話及 call_id/state。preparing 不表示撥號或接通;ended 與 failed 都是終態,不要僅因 failed 重複掛斷。
範例 · 409 · 38000
{ "request_id": "req_example", "error": { "code": "call_already_active", "numeric_code": "38000", "message": "Account already has an active call" } }- egress_configuration_pending · 20032 · 409
目前無法確認或讀取平台預設網路設定;這不代表帳號已登出。
觸發條件: 此操作使用平台分配的網路容量或帳號固定的預設網路設定。
處理與重試: 保留 request_id,再次寫入前確認帳號或建立結果。等待容量或設定恢復,或聯絡支援;不要自動反覆建立帳號、更換網路或重新啟動帳號。
示意 JSON;message 隨實際原因變化 · 409 · 20032
{ "request_id": "req_example", "error": { "code": "egress_configuration_pending", "numeric_code": "20032", "message": "Account network configuration is pending verification" } }- provider_not_ready · 30009 · 409
連線尚未就緒,請檢查授權及 runtime_status 後再決定是否重試。
處理與重試: 查詢授權與執行狀態,再按目標狀態和渠道支援選擇重新整理、啟動或重新連線。連線問題本身不證明已登出;執行依賴連線的業務操作前確認 running。
示意 JSON;message 隨實際原因變化 · 409 · 30009
{ "request_id": "req_example", "error": { "code": "provider_not_ready", "numeric_code": "30009", "message": "Provider client is not ready" } }- provider_not_ready · 30014 · 409
此帳號所需的渠道執行個體缺失。這是執行個體可用性問題,不證明授權已過期。
處理與重試: 查詢授權與執行狀態,再按目標狀態和渠道支援選擇重新整理、啟動或重新連線。連線問題本身不證明已登出;執行依賴連線的業務操作前確認 running。
適用渠道: WhatsApp
範例 · 409 · 30014
{ "request_id": "req_example", "error": { "code": "provider_not_ready", "numeric_code": "30014", "message": "Provider instance is missing" } }- provider_not_ready · 30015 · 409
渠道執行程序已停止。啟動前確認這是否為預期狀態;執行狀態停止本身不等於已登出。
處理與重試: 查詢授權與執行狀態,再按目標狀態和渠道支援選擇重新整理、啟動或重新連線。連線問題本身不證明已登出;執行依賴連線的業務操作前確認 running。
適用渠道: WhatsApp
範例 · 409 · 30015
{ "request_id": "req_example", "error": { "code": "provider_not_ready", "numeric_code": "30015", "message": "Provider runtime is stopped" } }- call_control_failed · 38004 · 500
未能查詢或結束通話;依本次動作核對通話狀態。
處理與重試: 建立或結束通話前,查詢目前受管理通話及 call_id/state。preparing 不表示撥號或接通;ended 與 failed 都是終態,不要僅因 failed 重複掛斷。
示意 JSON;message 隨實際原因變化 · 500 · 38004
{ "request_id": "req_example", "error": { "code": "call_control_failed", "numeric_code": "38004", "message": "Failed to control call" } }- create_call_failed · 30010 · 500
渠道未能完成本次操作。message 可能在「Provider operation failed:」後附帶原始原因;原因文字可變,不是穩定的程式介面。
觸發條件: 適用於渠道未提供更具體失敗分類的情況,保留目前操作的錯誤。
處理與重試: 建立或結束通話前,查詢目前受管理通話及 call_id/state。preparing 不表示撥號或接通;ended 與 failed 都是終態,不要僅因 failed 重複掛斷。
適用渠道: WhatsApp
示意 JSON;message 隨實際原因變化 · 500 · 30010
{ "request_id": "req_example", "error": { "code": "create_call_failed", "numeric_code": "30010", "message": "Provider operation failed" } }- create_call_failed · 38002 · 500
建立通話:資源建立失敗或無法確認建立結果。
處理與重試: 再次建立前先列出或查詢既有資源,確認上次建立是否已生效。修正根本原因並保留 request_id,不要自動建立重複資源。
範例 · 500 · 38002
{ "request_id": "req_example", "error": { "code": "create_call_failed", "numeric_code": "38002", "message": "Failed to create call" } }- unsupported_by_provider · 30003 · 501
管道不支援此操作,請選擇能力表中支援的操作。
處理與重試: 選擇文件列為支援的渠道與動作。重複請求不會增加能力或開通內測權限。
範例 · 501 · 30003
{ "request_id": "req_xxx", "error": { "code": "unsupported_by_provider", "numeric_code": "30003", "message": "Operation not supported by this provider" } }- provider_adapter_not_found · 30004 · 502
管道服務暫時無法使用,請檢查狀態或稍後再試;重試寫入操作前先確認上次結果。
處理與重試: 建立或結束通話前,查詢目前受管理通話及 call_id/state。preparing 不表示撥號或接通;ended 與 failed 都是終態,不要僅因 failed 重複掛斷。
示意 JSON;message 隨實際原因變化 · 502 · 30004
{ "request_id": "req_example", "error": { "code": "provider_adapter_not_found", "numeric_code": "30004", "message": "Provider adapter unavailable" } }- provider_unavailable · 30002 · 502
管道服務暫時無法使用,請檢查狀態或稍後再試;重試寫入操作前先確認上次結果。
處理與重試: 建立或結束通話前,查詢目前受管理通話及 call_id/state。preparing 不表示撥號或接通;ended 與 failed 都是終態,不要僅因 failed 重複掛斷。
範例 · 502 · 30002
{ "request_id": "req_example_provider_unavailable", "error": { "code": "provider_unavailable", "numeric_code": "30002", "message": "Provider service unavailable" } }- provider_unavailable · 30010 · 502
渠道未能完成本次操作。message 可能在「Provider operation failed:」後附帶原始原因;原因文字可變,不是穩定的程式介面。
處理與重試: 建立或結束通話前,查詢目前受管理通話及 call_id/state。preparing 不表示撥號或接通;ended 與 failed 都是終態,不要僅因 failed 重複掛斷。
適用渠道: WhatsApp
範例 · 502 · 30010
{ "request_id": "req_example_operation_failed", "error": { "code": "provider_unavailable", "numeric_code": "30010", "message": "Provider operation failed: Example operation could not be completed" } }- call_service_unavailable · 38001 · 503
通話服務無法使用,請檢查 Provider/Gateway 連線與設定。
處理與重試: 建立或結束通話前,查詢目前受管理通話及 call_id/state。preparing 不表示撥號或接通;ended 與 failed 都是終態,不要僅因 failed 重複掛斷。
範例 · 503 · 38001
{ "request_id": "req_example", "error": { "code": "call_service_unavailable", "numeric_code": "38001", "message": "Call service unavailable" } }