API 參考
訊息POST

發送名片(vCard)訊息

發送名片訊息。message.type 為 contact,message.contacts 是結構化名片陣列(可一張或多張),由 UnifyPort 產生 vCard。每張名片必須有 name;phones[].number、emails[].address、organization、title 皆為選填。目前僅 WhatsApp 支援;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

檔案類渠道轉接器支援的備用媒體 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>"
  }
}