通話
掛斷通話beta
此功能現正內測,可聯絡技術支援申請開通工作區資格。
目前只支援 WhatsApp 一對一語音和視像通話。 使用 account_id 同 call_id 結束通話;忘記 call_id 可先查詢目前通話。
https://api.unifyport.ai/v1/calls/{call_id}/hangup支援渠道
請求參數
請求標頭
X-Api-Key工作區 API Key,工作區會由呢個標頭解析得出嚟。
Content-Type發送 JSON 請求內容嘅時候請用 application/json。
路徑參數
call_id用嚟識別嗰條 calls 路由嘅 ID。
maxLength: 128 · pattern: ^[A-Za-z0-9][A-Za-z0-9_-]*$
請求內容
account_id目前工作區的帳戶 ID。
pattern: ^acc_[A-Za-z0-9][A-Za-z0-9_-]*$
如何理解結果
讀取回傳的 call_id 和 state。ended 和 failed 都是通話終態,重複掛斷可能回傳既有終態;不能將 HTTP 200 固定理解為 state=ended,也不要因 state=failed 自動重試。
回應 200 · 200
{
"request_id": "req_example",
"data": {
"call_id": "call_example",
"state": "ended",
"direction": "outbound",
"media_type": "voice"
}
}
回應內容
call_id通話識別碼,掛線時使用。
maxLength: 128
state目前通話狀態。
enum: ended, failed
direction通話方向。
enum: inbound, outbound
media_typevoice 為語音,video 為支援視像的通話。
enum: voice, video
回應
200200 · 200
請求成功,回應內容嘅例子如上。
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" } }- beta_feature_not_enabled · 41002 · 403
工作區需要內測資格,才可使用通話介面及明確訂閱通話事件。
處理與重試: 保留 request_id 同結構化錯誤碼,先排查目前操作,再決定下一步。
範例 · 403 · 41002
{ "request_id": "req_example", "error": { "code": "beta_feature_not_enabled", "numeric_code": "41002", "message": "Beta feature not enabled" } }- workspace_override_forbidden · 11002 · 403
請求嘗試使用呢個 API Key 無權使用嘅工作區覆寫。請移除覆寫請求標頭,改用目標工作區所屬嘅 API Key。
觸發條件: 適用於帶有 X-Workspace-Id 工作區覆寫請求標頭嘅請求。
處理與重試: 保留 request_id 同結構化錯誤碼,先排查目前操作,再決定下一步。
示意 JSON;message 會隨實際原因變化 · 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
目前帳戶及工作區沒有該通話。
處理與重試: 核對目標識別碼、資源歸屬同目前工作區。唔好將已確認缺少或無法存取嘅目標當成暫時服務故障自動重試。
範例 · 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。
示意 JSON;message 會隨實際原因變化 · 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
帳號已有受管理嘅活躍通話。核對已知通話同今次動作意圖;呢個錯誤本身唔要求掛斷,亦唔要求反覆調用同一個失敗查詢。
處理與重試: 保留 request_id 同結構化錯誤碼,先排查目前操作,再決定下一步。
示意 JSON;message 會隨實際原因變化 · 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
示意 JSON;message 會隨實際原因變化 · 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
示意 JSON;message 會隨實際原因變化 · 409 · 30015
{ "request_id": "req_example", "error": { "code": "provider_not_ready", "numeric_code": "30015", "message": "Provider runtime is stopped" } }- call_control_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": "call_control_failed", "numeric_code": "30010", "message": "Provider operation failed" } }- 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" } }- 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 重複掛斷。
示意 JSON;message 會隨實際原因變化 · 503 · 38001
{ "request_id": "req_example", "error": { "code": "call_service_unavailable", "numeric_code": "38001", "message": "Call service unavailable" } }