Logo Site EngageLab Mark Colored Transparent文件
搜尋

建立範本

呼叫地址

POST https://otp.api.engagelab.cc/v1/template-configs

呼叫驗證

請參考 呼叫驗證 了解如何進行 API 鑑權。

請求

請求參數

一個請求物件以 JSON 格式表達,因此請求頭需要帶 Content-Type: application/json 。

參數 類型 選項 說明
template_id String 必填 自訂的範本 id,具有唯一性,限制 128 字元
description String 選填 範本的描述,限制 255 字元
send_channel_strategy String 必填 範本策略,單個管道取值為 whatsapp/sms/email/voice,多管道用|隔開,按順序補發,email 不能和其他管道一起組成策略
brand_name String 選填 品牌標誌,在某些範本樣式具有品牌簽名時會替換品牌簽名變數,長度限制在 2-10 個字元
verify_code_config Object 條件必填 驗證碼的配置,範本包含驗證碼類型時必填
verify_code_config.verify_code_type Integer 必填 驗證碼類型,取值範圍[1,7],1 數字/2 小寫英文字母/4 大寫英文字母,可組合(如 3 表示數字+小寫字母)
verify_code_config.verify_code_len Integer 必填 驗證碼長度,取值範圍[4,10]
verify_code_config.verify_code_ttl Integer 必填 驗證碼有效期,單位分鐘,取值[1,10],策略包含 whatsapp 時只能為 1、5、10
whatsapp_config Object 條件必填 whatsapp 策略的配置,下發策略包含 whatsapp 時必填
whatsapp_config.template_type Integer 必填 whatsapp 範本類型,目前僅支援預設範本,固定為 1
whatsapp_config.template_default_config Object 條件必填 whatsapp 預設範本配置,whatsapp 範本類型為預設範本時必填
sms_config Object 條件必填 sms 策略的配置,下發策略包含 sms 時必填
sms_config.template_type Integer 必填 sms 範本類型,1-預設範本/2-自訂範本
sms_config.template_default_config Object 條件必填 sms 預設範本配置,sms 範本類型為預設範本時必填
sms_config.template_custom_config Object 條件必填 sms 自訂範本配置,sms 範本類型為自訂範本時必填
sms_config.template_custom_config.custom_sub_type String 必填 自訂範本類型,authentication-驗證碼/marketing-行銷/utility-通知
sms_config.template_custom_config.custom_content String 必填 自訂範本內容,authentication 類型時必須包含{{code}}變數
sms_config.template_custom_config.custom_country_codes String 選填 目標國家地區代碼,逗號分隔,用於範本審核時參考
voice_config Object 條件必填 voice 策略的配置,下發策略包含 voice 時必填
voice_config.template_type Integer 必填 voice 範本類型,目前僅支援預設範本,固定為 1
voice_config.template_default_config Object 條件必填 voice 預設範本配置,voice 範本類型為預設範本時必填
email_config Object 條件必填 email 策略的配置,下發策略包含 email 時必填
email_config.template_name String 必填 email 範本名稱
email_config.template_custom_configs Array 條件必填 email 自訂範本配置,email 範本類型為自訂範本時必填,支援多語言配置
email_config.template_custom_configs.language String 必填 語言,default 為預設,訊息下發時可根據 language 參數匹配不同範本內容
email_config.template_custom_configs.pre_from_name String 選填 預設的發件人名稱
email_config.template_custom_configs.pre_from_mail String 必填 預設的發件人信箱
email_config.template_custom_configs.pre_subject String 必填 預設的郵件主旨
email_config.template_custom_configs.template_content String 必填 郵件內容,支援 html,變數需用{{}}括起來
email_config.template_custom_configs.pre_param_map Object 選填 郵件內容變數的預設值,key-value 對聲明,value 需要使用字串
pwa_config Object 選填 pwa 相關配置,暫時可不使用
pwa_config.pwa_platform String 選填 使用的 pwa 平台,具體取值請與技術支援聯繫獲取
pwa_config.pwa_code String 選填 使用的 pwa 平台中的 code

請求範例

請求頭

POST /v1/template-configs HTTP/1.1 Content-Type: application/json Authorization: Basic amlndWFuZ2RldjpkZXZfc2VjcmV0
              
              POST /v1/template-configs  HTTP/1.1
Content-Type: application/json
Authorization: Basic amlndWFuZ2RldjpkZXZfc2VjcmV0

            
此代碼塊在浮窗中顯示

請求體

{ "template_id": "test-template-1", // 自訂的範本id,應用內唯一 "description": "測試範本1", // 該範本的描述說明 "send_channel_strategy": "whatsapp|sms", // 範本的下發策略,支援whatsapp/sms/voice/email四類,組合策略則使用|字元表示失敗補發 "brand_name": "品牌名稱", // 品牌名稱,用在一些國家地區範本內容中的簽名(如簡訊管道中一些國家地區要求要註冊簽名) "verify_code_config": { // 驗證碼的配置,用於配置自動生成的驗證碼,範本包含驗證碼類型時必填 "verify_code_type": 1, // 驗證碼類型,取值範圍[1,7] "verify_code_len": 6, // 驗證碼長度,取值範圍[4,10] "verify_code_ttl": 1 // 驗證碼有效期,取值範圍[1,10],注意當策略包含whatsapp時取值只能是1,5,10 }, "whatsapp_config": { // whatsapp策略的配置,當下發策略包含whatsapp時有效 "template_type": 1, // whatsapp範本類型,目前僅支援預設範本,即固定取值為1 "template_default_config": { // whatsapp預設範本配置,針對預設範本類型時有效 "contain_security": false, // 是否添加安全提醒 "contain_expire": false // 是否添加過期時間內容 } }, "sms_config": { // sms策略的配置,當下發策略包含sms時有效 "template_type": 2, // sms範本類型,取值:1-預設範本/2-自訂範本 "template_default_config": { // sms預設範本配置,針對預設範本類型時有效 "contain_security": false, // 是否添加安全提醒 "contain_expire": false // 是否添加過期時間內容 }, "template_custom_config": { // sms自訂範本配置,sms範本類型為自訂範本時有效 "custom_sub_type": "authentication", // 自訂範本類型,取值:authentication-驗證碼/marketing-行銷/utility-通知 "custom_content": "xxx", // 自訂範本內容,注意若子類型為authentication驗證碼類型時必須包含{{code}}變數 "custom_country_codes": "HK,PH" // 自訂範本的目標國家地區,用於範本審核時參考,請按實際填寫,否則可能影響實際下發 } }, "voice_config": { // voice策略的配置,當下發策略包含voice時有效 "template_type": 1, // voice範本類型,目前僅支援預設範本,即固定取值為1 "template_default_config": { // voice預設範本配置,針對預設範本類型時有效 "contain_security": false, // 是否添加安全提醒 "contain_expire": false // 是否添加過期時間內容 } }, "email_config": { // email策略的配置,當下發策略包含email時有效 "template_name": "email範本名稱", // email範本名稱 "template_custom_configs": [{ // email自訂範本配置,注意這裡是物件陣列,主要是透過language進行區分配置多個 "language": "default", // 語言,default為預設,訊息下發時可以根據language參數來匹配不同的範本內容 "pre_from_name": "test", // 預設的發件人名稱 "pre_from_mail": "test@test.com", // 預設的發件人信箱 "pre_subject": "test", // 預設的郵件主旨 "template_content": "預設郵件範本內容,必填,自訂變數如{{self}},驗證碼是{{code}}", // 郵件內容,支援html,變數需要使用兩個大括號{{}}括起來 "pre_param_map": { // 郵件內容中變數的預設值,即下發時若不指定變數值,則採用下述的預設值來替換變數,採用key-value對聲明,value需要使用字串 "self": "這裡是self變數預設值" } }] }, "pwa_config": { // pwa相關的配置,暫時可以不使用 "pwa_platform": "xx", // 使用的pwa平台,具體取值請與技術支援聯繫獲取確定 "pwa_code": "xx" // 使用的pwa平台中的code } }
              
              {
    "template_id": "test-template-1",       // 自訂的範本id,應用內唯一
    "description": "測試範本1",                 // 該範本的描述說明
    "send_channel_strategy": "whatsapp|sms",    // 範本的下發策略,支援whatsapp/sms/voice/email四類,組合策略則使用|字元表示失敗補發
    "brand_name": "品牌名稱",                   // 品牌名稱,用在一些國家地區範本內容中的簽名(如簡訊管道中一些國家地區要求要註冊簽名)
    "verify_code_config": {                     // 驗證碼的配置,用於配置自動生成的驗證碼,範本包含驗證碼類型時必填
        "verify_code_type": 1,                  // 驗證碼類型,取值範圍[1,7]
        "verify_code_len": 6,                   // 驗證碼長度,取值範圍[4,10]
        "verify_code_ttl": 1                    // 驗證碼有效期,取值範圍[1,10],注意當策略包含whatsapp時取值只能是1,5,10
    },
    "whatsapp_config": {                        // whatsapp策略的配置,當下發策略包含whatsapp時有效
        "template_type": 1,                      // whatsapp範本類型,目前僅支援預設範本,即固定取值為1
        "template_default_config": {            // whatsapp預設範本配置,針對預設範本類型時有效
            "contain_security": false,              // 是否添加安全提醒
            "contain_expire": false                 // 是否添加過期時間內容
        }
    },
    "sms_config": {                             // sms策略的配置,當下發策略包含sms時有效
        "template_type": 2,                     // sms範本類型,取值:1-預設範本/2-自訂範本
        "template_default_config": {            // sms預設範本配置,針對預設範本類型時有效
            "contain_security": false,              // 是否添加安全提醒
            "contain_expire": false                 // 是否添加過期時間內容
        },
        "template_custom_config": {             // sms自訂範本配置,sms範本類型為自訂範本時有效
            "custom_sub_type": "authentication",    // 自訂範本類型,取值:authentication-驗證碼/marketing-行銷/utility-通知
            "custom_content": "xxx",                // 自訂範本內容,注意若子類型為authentication驗證碼類型時必須包含{{code}}變數
            "custom_country_codes": "HK,PH"         // 自訂範本的目標國家地區,用於範本審核時參考,請按實際填寫,否則可能影響實際下發
        }
    },
    "voice_config": {                           // voice策略的配置,當下發策略包含voice時有效
        "template_type": 1,                      // voice範本類型,目前僅支援預設範本,即固定取值為1
        "template_default_config": {            // voice預設範本配置,針對預設範本類型時有效
            "contain_security": false,              // 是否添加安全提醒
            "contain_expire": false                 // 是否添加過期時間內容
        }
    },
    "email_config": {                           // email策略的配置,當下發策略包含email時有效
        "template_name": "email範本名稱",                     // email範本名稱
        "template_custom_configs": [{           // email自訂範本配置,注意這裡是物件陣列,主要是透過language進行區分配置多個
            "language": "default",              // 語言,default為預設,訊息下發時可以根據language參數來匹配不同的範本內容
            "pre_from_name": "test",            // 預設的發件人名稱
            "pre_from_mail": "test@test.com",   // 預設的發件人信箱
            "pre_subject": "test",              // 預設的郵件主旨
            "template_content": "預設郵件範本內容,必填,自訂變數如{{self}},驗證碼是{{code}}",    // 郵件內容,支援html,變數需要使用兩個大括號{{}}括起來
            "pre_param_map": {                  // 郵件內容中變數的預設值,即下發時若不指定變數值,則採用下述的預設值來替換變數,採用key-value對聲明,value需要使用字串
                "self": "這裡是self變數預設值"
            }
        }]
    },
    "pwa_config": {                             // pwa相關的配置,暫時可以不使用
        "pwa_platform": "xx",                   // 使用的pwa平台,具體取值請與技術支援聯繫獲取確定
        "pwa_code": "xx"                        // 使用的pwa平台中的code
    }
}

            
此代碼塊在浮窗中顯示

回應

回應參數

欄位 類型 選項 描述
code Integer 必填 錯誤碼,0 表示成功,其他為失敗
message String 必填 回應資訊

回應範例

成功返回

{ "code": 0, "message": "success" }
              
              {
    "code": 0,
    "message": "success"
}

            
此代碼塊在浮窗中顯示

失敗返回

{ "code": 3003, "message": "not contains any channel config" }
              
              {
    "code": 3003,
    "message": "not contains any channel config"
}

            
此代碼塊在浮窗中顯示

Email 範本變數進階用法

當您在發送策略中啟用 Email 管道時,支援高度自訂郵件主旨和正文內容。透過變數佔位符 {{變數名}},可自動填充驗證碼、品牌資訊等內容,實現靈活的個人化郵件體驗。

變數類型及用法

Email 範本正文(template_content)和主旨(pre_subject)均可嵌入變數,格式為 {{變數名}}

發送 API 透過 template.params 欄位動態傳入,或在範本建立階段設置預設值。

支援的變數

下面變數僅 Email 管道適用。

變數名 類型 說明 填充方式
{{logo_url}} 自訂變數 品牌 Logo 圖片地址 發送時透過 template.params 傳入
{{title}} 自訂變數 郵件正文標題文字 發送時透過 template.params 傳入
{{support_email}} 自訂變數 客服/支援信箱地址 發送時透過 template.params 傳入
{{subject}} 自訂變數 動態覆蓋郵件主旨 發送時透過 template.params 傳入
{{from_name}} 自訂變數 動態覆蓋發件人名稱 發送時透過 template.params 傳入
{{from_mail}} 自訂變數 動態覆蓋發件人信箱 發送時透過 template.params 傳入

注意{{subject}}{{from_name}}{{from_mail}} 這幾個特殊變數不會插入到正文 HTML,而是直接覆蓋郵件的元數據欄位。

郵件主旨範例

{{brand_name}} 驗證碼
              
              {{brand_name}} 驗證碼

            
此代碼塊在浮窗中顯示

郵件正文範例

<img src="{{logo_url}}" /> <strong>{{title}}</strong> <p>您的驗證碼是 <strong>{{code}}</strong>,請在 {{ttl}} 分鐘內完成驗證。</p> <p>如有疑問,請聯繫 <a href="mailto:{{support_email}}">{{support_email}}</a></p>
              
              <img src="{{logo_url}}" />
<strong>{{title}}</strong>
<p>您的驗證碼是 <strong>{{code}}</strong>,請在 {{ttl}} 分鐘內完成驗證。</p>
<p>如有疑問,請聯繫 <a href="mailto:{{support_email}}">{{support_email}}</a></p>

            
此代碼塊在浮窗中顯示

範本預設值設置

範本建立時,可在 pre_param_map 欄位設置自訂變數的預設值。發送郵件時未傳入變數時,將自動使用預設值。

"pre_param_map": { "logo_url": "https://example.com/logo.png", "title": "您的驗證碼", "support_email": "support@example.com" }
              
              "pre_param_map": {
  "logo_url": "https://example.com/logo.png",
  "title": "您的驗證碼",
  "support_email": "support@example.com"
}

            
此代碼塊在浮窗中顯示

發送參數說明

欄位 類型 必填 說明
to string 目標信箱地址
template.id string 郵件範本 ID
template.language string 語言代碼,預設 default
template.params object 範本變數賦值(不含 {{}}

範例請求:

{ "to": "user@example.com", "template": { "id": "my_email_template", "language": "default", "params": { "logo_url": "https://example.com/logo.png", "title": "您的驗證碼", "support_email": "support@example.com" } } }
              
              {
  "to": "user@example.com",
  "template": {
    "id": "my_email_template",
    "language": "default",
    "params": {
      "logo_url": "https://example.com/logo.png",
      "title": "您的驗證碼",
      "support_email": "support@example.com"
    }
  }
}

            
此代碼塊在浮窗中顯示

變數填充優先級

  1. 優先使用發送 API 中 template.params 傳入的變數值;
  2. 若未傳入,則使用範本 pre_param_map 中的預設值;
  3. 若兩者均未設置,則佔位符原樣顯示在郵件內容中。

常見問題解答

Q: 為什麼變數未被替換?
A: 請確認變數名書寫及格式正確(需 {{變數名}}),並確保已透過 template.params 提供值,或範本已設置預設值。

Q: 如何動態設置郵件主旨、發件人?
A: 在請求參數 template.params 內傳入 subjectfrom_namefrom_mail,即可動態覆蓋範本預設的主旨和發件人資訊。

錯誤碼

錯誤碼 http code 說明
1000 500 內部錯誤
2001 401 鑑權失敗,未攜帶正確的 token
2002 401 鑑權失敗,token 已過期或已被禁用
2004 403 無呼叫此 API 的權限
3001 400 請求參數格式無效,請檢查是否符合參數格式的 JSON 內容
3002 400 請求參數有誤,請檢查請求參數是否符合要求
3003 400 業務級別的參數錯誤,請檢查返回 message 欄位說明
Icon Solid Transparent White Qiyu
聯繫銷售