API 參考
訊息POST

傳送名片(vCard)訊息

傳送名片訊息。message.type 為 contact,message.contacts 係結構化名片陣列(可一張或多張),由 UnifyPort 產生 vCard。每張名片必須有 name;phones[].number、emails[].address、organization、title 皆為選填。目前僅 WhatsApp 支援——其他 provider 回傳 400 / 501。contacts 為空或某張缺 name 回傳 400 invalid_request,非 WhatsApp provider 回傳 400 unsupported_message_type。 WhatsApp 發送成功同渠道提供可引用訊息識別碼時可能回傳嘅不透明回覆句柄。要原樣回傳,佢唔係父訊息 id。

https://api.unifyport.ai/v1/messages

請求標頭

X-Api-Key
string必填

工作區 API Key,工作區會由呢個標頭解析得出嚟。

Content-Type
string必填

發送 JSON 請求內容嘅時候請用 application/json。

路徑參數

呢個介面冇路徑參數。

請求內容

account_id
string必填

發送呢條訊息嘅渠道帳號。

to
object必填

收件方目標,包括 id 同 type。

id
string必填

收件方喺渠道側嘅識別碼。

type
string必填

收件方類型:user、group 或 channel。

enum: user, group, channel

message
object必填

標準化嘅訊息內容:文字用 message.text,媒體用 message.url。

type
string必填

訊息類型:text、image、video、audio、document、file 或 contact。

enum: text, image, video, audio, document, file, contact

text
string

message.type 係 text 時發送嘅文字內容。

url
string

媒體訊息使用嘅公開媒體 URL。

file_url
string

檔案類渠道 adapter 支援嘅備用媒體 URL 欄位。

file_key
string

渠道支援時使用嘅渠道側或儲存側檔案參考。

caption
string

image、video、document 或 file 訊息嘅可選說明文字。

contacts[]
object[]

message.type 係 contact 時發送嘅一張或多張結構化名片。

name
string

聯絡人顯示名稱;每張名片都必須提供。

phones[]
object[]

名片包含嘅電話號碼清單。

number
string

電話號碼;每個 phone 項目都必須提供。

type
string

可選嘅電話類型,例如 CELL 或 WORK。

emails[]
object[]

名片包含嘅電郵地址清單。

address
string

電郵地址;每個 email 項目都必須提供。

type
string

可選嘅電郵類型,例如 WORK 或 HOME。

organization
string

聯絡人嘅可選組織名稱。

title
string

聯絡人嘅可選職位名稱。

provider_data
object

渠道專屬嘅選項,例如 Telegram 嘅 parse_mode,或者 WhatsApp 音訊嘅 seconds / waveform;引用回覆請用頂層 reply_to。

seconds
integer

WhatsApp audio 訊息嘅可選音訊時長,單位係秒,必須大於或等於 0。

waveform
string

WhatsApp audio 訊息嘅可選音訊波形資料字串。

reply_to
object

引用回覆目標;將入站 Webhook 嘅 data.message.reply_token 原樣放入發送請求嘅 reply_to.reply_token。

reply_token
string

由入站 Webhook 嘅 data.message.reply_token 原樣複製嘅不透明引用代符。

mentions[]
object[]

喺 text 或 caption 入面由 {{@<id>}} 佔位符引用嘅成員。

id
string

同對應 {{@<id>}} 佔位符匹配嘅渠道側成員識別碼。

回應內容

message_id
string

已受理訊息嘅 UnifyPort 訊息識別碼(msg_...)。

account_id
string

呢個回應所指嘅渠道帳號。

status
string

受理狀態;accepted 即係訊息已經排隊等住派去渠道。

provider_ref
string

渠道側嘅訊息參考,等渠道編咗號之後先會有。

reply_token
string

WhatsApp 發送成功同渠道提供可引用訊息識別碼時可能回傳嘅不透明回覆句柄。要原樣回傳,佢唔係父訊息 id。

回應

200
200 OK

請求成功,回應內容嘅例子如上。

400
請求錯誤

請求內容、路徑或者參數無效。

401
未授權

X-Api-Key 請求標頭缺少或者無效。

409
衝突

目前操作同現有嘅渠道帳號或者資源衝突。

500
伺服器錯誤

服務遇到咗未預期嘅錯誤。

501
渠道未實作

所選渠道未實作呢個操作。

502
上游閘道錯誤

渠道轉接器或者上游渠道未能完成呢個操作。

請求

curl -X POST https://api.unifyport.ai/v1/messages \
  -H "X-Api-Key: <YOUR_API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{
  "account_id": "acc_example",
  "to": {
    "id": "user_example",
    "type": "user"
  },
  "message": {
    "type": "contact",
    "contacts": [
      {
        "name": "Jane Doe",
        "phones": [{ "number": "+8613800000000", "type": "CELL" }],
        "emails": [{ "address": "jane@example.com" }],
        "organization": "ACME",
        "title": "PM"
      }
    ]
  }
}'

回應

{
  "data": {
    "message_id": "msg_example",
    "account_id": "acc_example",
    "status": "accepted",
    "provider_ref": "provider_msg_example",
    "reply_token": "<opaque WhatsApp reply handle>"
  }
}