Template API Interface

สร้างเทมเพลต

Endpoint

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

การยืนยันตัวตน

ใช้ HTTP Basic Authentication สำหรับการยืนยันตัวตน และเพิ่ม Authorization ลงใน HTTP header:

Authorization: Basic ${base64_auth_string}
              
              Authorization: Basic ${base64_auth_string}

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

อัลกอริทึมสำหรับสร้าง base64_auth_string ข้างต้นคือ base64(dev_key:dev_secret)

ตัวอย่างคำขอ

Request Header

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

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

Request Body

{ "template_id": "test-template-1", "description": "测试模版1", "send_channel_strategy": "whatsapp|sms", "brand_name": "品牌名称", "verify_code_config": { "verify_code_type": 1, "verify_code_len": 6, "verify_code_ttl": 1 }, "whatsapp_config": { "template_type": 1, "template_default_config": { "contain_security": false, "contain_expire": false } }, "sms_config": { "template_type": 2, "template_default_config": { "contain_security": false, "contain_expire": false }, "template_custom_config": { "custom_sub_type": "authentication", "custom_content": "xxx", "custom_country_codes": "HK,PH" } }, "voice_config": { "template_type": 1, "template_default_config": { "contain_security": false, "contain_expire": false } }, "email_config": { "template_name": "email模板名称", "template_custom_configs": [{ "language": "default", "pre_from_name": "test", "pre_from_mail": "test@test.com", "pre_subject": "test", "template_content": "预设邮件模版内容,必填,自定义变量如{{self}},验证码是{{code}}", "pre_param_map": { "self": "这里是self变量预设值" } }] }, "pwa_config": { "pwa_platform": "xx", "pwa_code": "xx" } }
              
              {
    "template_id": "test-template-1",       
    "description": "测试模版1",                 
    "send_channel_strategy": "whatsapp|sms",    
    "brand_name": "品牌名称",                   
    "verify_code_config": {                     
        "verify_code_type": 1,                  
        "verify_code_len": 6,                   
        "verify_code_ttl": 1                    
    },
    "whatsapp_config": {                        
        "template_type": 1,                      
        "template_default_config": {            
            "contain_security": false,              
            "contain_expire": false                 
        }
    },
    "sms_config": {                             
        "template_type": 2,                     
        "template_default_config": {            
            "contain_security": false,              
            "contain_expire": false                 
        },
        "template_custom_config": {             
            "custom_sub_type": "authentication",    
            "custom_content": "xxx",                
            "custom_country_codes": "HK,PH"         
        }
    },
    "voice_config": {                           
        "template_type": 1,                      
        "template_default_config": {            
            "contain_security": false,              
            "contain_expire": false                 
        }
    },
    "email_config": {                           
        "template_name": "email模板名称",                     
        "template_custom_configs": [{
            "language": "default",              
            "pre_from_name": "test",            
            "pre_from_mail": "test@test.com",   
            "pre_subject": "test",              
            "template_content": "预设邮件模版内容,必填,自定义变量如{{self}},验证码是{{code}}",    
            "pre_param_map": {                  
                "self": "这里是self变量预设值"
            }
        }]
    },
    "pwa_config": {                             
        "pwa_platform": "xx",                   
        "pwa_code": "xx"                        
    }
}

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

พารามิเตอร์คำขอ

ออบเจ็กต์คำขอจะแสดงในรูปแบบ JSON ดังนั้น request header ต้องมี Content-Type: application/json

Parameter Type Option Description
template_id String Required ID เทมเพลตแบบกำหนดเองที่ต้องไม่ซ้ำกัน โดยจำกัดความยาวไว้ที่ 128 อักขระ
description String Optional คำอธิบายเทมเพลต โดยจำกัดความยาวไว้ที่ 255 อักขระ
send_channel_strategy String Required กลยุทธ์ของเทมเพลต ช่องทางเดียวสามารถเป็น whatsapp, sms, email หรือ voice ได้ หลายช่องทางให้คั่นด้วย `
brand_name String Optional ตัวระบุแบรนด์ สำหรับเทมเพลตบางประเภทที่มีลายเซ็นแบรนด์ ค่านี้จะใช้แทนตัวแปรลายเซ็นแบรนด์ โดยความยาวต้องอยู่ระหว่าง 2-10 อักขระ
verify_code_config Object Conditionally required การกำหนดค่ารหัสยืนยัน จำเป็นเมื่อเทมเพลตเป็นประเภทรหัสยืนยัน
verify_code_config.verify_code_type Integer Required ประเภทรหัสยืนยัน ช่วงค่า [1,7]: 1-ตัวเลข / 2-ตัวอักษรพิมพ์เล็ก / 4-ตัวอักษรพิมพ์ใหญ่ และสามารถรวมค่าได้ (เช่น 3 หมายถึงตัวเลข + ตัวอักษรพิมพ์เล็ก)
verify_code_config.verify_code_len Integer Required ความยาวของรหัสยืนยัน ช่วงค่า [4,10]
verify_code_config.verify_code_ttl Integer Required ระยะเวลาที่รหัสยืนยันมีผล หน่วยเป็นนาที ช่วงค่า [1,10] เมื่อกลยุทธ์รวม whatsapp ไว้ ค่านี้สามารถเป็นได้เฉพาะ 1, 5 หรือ 10
whatsapp_config Object Conditionally required การกำหนดค่าสำหรับกลยุทธ์ WhatsApp จำเป็นเมื่อกลยุทธ์การส่งรวม whatsapp
whatsapp_config.template_type Integer Required ประเภทเทมเพลต WhatsApp ปัจจุบันรองรับเฉพาะเทมเพลตเริ่มต้นเท่านั้น ดังนั้นค่าจึงกำหนดตายตัวเป็น 1
whatsapp_config.template_default_config Object Conditionally required การกำหนดค่าเทมเพลตเริ่มต้นของ WhatsApp จำเป็นเมื่อประเภทเทมเพลต WhatsApp เป็นเทมเพลตเริ่มต้น
sms_config Object Conditionally required การกำหนดค่าสำหรับกลยุทธ์ SMS จำเป็นเมื่อกลยุทธ์การส่งรวม sms
sms_config.template_type Integer Required ประเภทเทมเพลต SMS: 1-เทมเพลตเริ่มต้น / 2-เทมเพลตแบบกำหนดเอง
sms_config.template_default_config Object Conditionally required การกำหนดค่าเทมเพลตเริ่มต้นของ SMS จำเป็นเมื่อประเภทเทมเพลต SMS เป็นเทมเพลตเริ่มต้น
sms_config.template_custom_config Object Conditionally required การกำหนดค่าเทมเพลตแบบกำหนดเองของ SMS จำเป็นเมื่อประเภทเทมเพลต SMS เป็นเทมเพลตแบบกำหนดเอง
sms_config.template_custom_config.custom_sub_type String Required ประเภทเทมเพลตแบบกำหนดเอง: authentication-รหัสยืนยัน / marketing-การตลาด / utility-การแจ้งเตือน
sms_config.template_custom_config.custom_content String Required เนื้อหาเทมเพลตแบบกำหนดเอง สำหรับประเภท authentication ต้องมีตัวแปร {{code}}
sms_config.template_custom_config.custom_country_codes String Optional รหัสประเทศ/ภูมิภาคเป้าหมาย คั่นด้วยเครื่องหมายจุลภาค ใช้เป็นข้อมูลอ้างอิงระหว่างการตรวจสอบเทมเพลต
voice_config Object Conditionally required การกำหนดค่าสำหรับกลยุทธ์เสียง จำเป็นเมื่อกลยุทธ์การส่งรวม voice
voice_config.template_type Integer Required ประเภทเทมเพลตเสียง ปัจจุบันรองรับเฉพาะเทมเพลตเริ่มต้นเท่านั้น ดังนั้นค่าจึงกำหนดตายตัวเป็น 1
voice_config.template_default_config Object Conditionally required การกำหนดค่าเทมเพลตเริ่มต้นของเสียง จำเป็นเมื่อประเภทเทมเพลตเสียงเป็นเทมเพลตเริ่มต้น
email_config Object Conditionally required การกำหนดค่าสำหรับกลยุทธ์อีเมล จำเป็นเมื่อกลยุทธ์การส่งรวม email
email_config.template_name String Required ชื่อเทมเพลตอีเมล
email_config.template_custom_configs Array Conditionally required การกำหนดค่าเทมเพลตอีเมลแบบกำหนดเอง จำเป็นเมื่อประเภทเทมเพลตอีเมลเป็นเทมเพลตแบบกำหนดเอง และรองรับการกำหนดค่าหลายภาษา
email_config.template_custom_configs.language String Required ภาษา โดย default คือภาษาเริ่มต้น ซึ่งสามารถจับคู่เนื้อหาเทมเพลตที่แตกต่างกันได้ตามพารามิเตอร์ภาษาในระหว่างการส่งข้อความ
email_config.template_custom_configs.pre_from_name String Optional ชื่อผู้ส่งที่ตั้งค่าไว้ล่วงหน้า
email_config.template_custom_configs.pre_from_mail String Required อีเมลผู้ส่งที่ตั้งค่าไว้ล่วงหน้า
email_config.template_custom_configs.pre_subject String Required หัวข้ออีเมลที่ตั้งค่าไว้ล่วงหน้า
email_config.template_custom_configs.template_content String Required เนื้อหาอีเมล รองรับ HTML โดยตัวแปรต้องอยู่ภายใน {{}}
email_config.template_custom_configs.pre_param_map Object Optional ค่าเริ่มต้นสำหรับตัวแปรในเนื้อหาอีเมล โดยประกาศเป็นคู่คีย์-ค่า และค่าต้องเป็นสตริง
pwa_config Object Optional การกำหนดค่าที่เกี่ยวข้องกับ PWA ปัจจุบันเป็นตัวเลือก
pwa_config.pwa_platform String Optional แพลตฟอร์ม PWA ที่ใช้งานอยู่ โปรดติดต่อฝ่ายสนับสนุนด้านเทคนิคสำหรับค่าที่เฉพาะเจาะจง
pwa_config.pwa_code String Optional รหัสที่ใช้ภายในแพลตฟอร์ม PWA

พารามิเตอร์การตอบกลับ

Field Type Option Description
code Integer Required รหัสข้อผิดพลาด โดย 0 หมายถึงสำเร็จ และค่าอื่นหมายถึงล้มเหลว
message String Required ข้อความตอบกลับ

การตอบกลับเมื่อสำเร็จ

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

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

การตอบกลับเมื่อล้มเหลว

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

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

รหัสข้อผิดพลาด

Error Code HTTP Code Description
1000 500 ข้อผิดพลาดภายในระบบ
2001 401 การยืนยันตัวตนล้มเหลว; ไม่มีการระบุโทเค็นที่ถูกต้อง
2002 401 การยืนยันตัวตนล้มเหลว; โทเค็นหมดอายุหรือถูกปิดใช้งานแล้ว
2004 403 ไม่มีสิทธิ์เรียกใช้ API นี้
3001 400 รูปแบบพารามิเตอร์คำขอไม่ถูกต้อง โปรดตรวจสอบว่า request body เป็น JSON ที่ถูกต้องและสอดคล้องกับรูปแบบพารามิเตอร์
3002 400 พารามิเตอร์คำขอไม่ถูกต้อง โปรดตรวจสอบว่าพารามิเตอร์คำขอเป็นไปตามข้อกำหนด
3003 400 ข้อผิดพลาดของพารามิเตอร์ในระดับธุรกิจ โปรดตรวจสอบคำอธิบายในฟิลด์ message ที่ส่งกลับมา

ลบเทมเพลต

Endpoint

DELETE /v1/template-configs/{templateId}

การยืนยันตัวตน

ใช้ HTTP Basic Authentication สำหรับการยืนยันตัวตน และเพิ่ม Authorization ลงใน HTTP header:

Authorization: Basic ${base64_auth_string}
              
              Authorization: Basic ${base64_auth_string}

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

อัลกอริทึมสำหรับสร้าง base64_auth_string ข้างต้นคือ base64(dev_key:dev_secret)

ตัวอย่างคำขอ

Request Header

DELETE /v1/template-configs/{templateId} HTTP/1.1 Authorization: Basic amlndWFuZ2RldjpkZXZfc2VjcmV0
              
              DELETE /v1/template-configs/{templateId} HTTP/1.1
Authorization: Basic amlndWFuZ2RldjpkZXZfc2VjcmV0

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

Request Body

ไม่มี

พารามิเตอร์คำขอ

{templateId} ใน URL หมายถึง ID ของเทมเพลตที่จะลบ ซึ่งผู้เรียกกำหนดไว้เมื่อใช้งาน Create Template API

พารามิเตอร์การตอบกลับ

Field Type Option Description
code Integer Required รหัสข้อผิดพลาด โดย 0 หมายถึงสำเร็จ และค่าอื่นหมายถึงล้มเหลว
message String Required ข้อความตอบกลับ

การตอบกลับเมื่อสำเร็จ

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

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

การตอบกลับเมื่อล้มเหลว

{ "code": 4001, "message": "config not exist" }
              
              {
    "code": 4001,
    "message": "config not exist"
}

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

รหัสข้อผิดพลาด

Error Code HTTP Code Description
1000 500 ข้อผิดพลาดภายในระบบ
2001 401 การยืนยันตัวตนล้มเหลว; ไม่มีการระบุโทเค็นที่ถูกต้อง
2002 401 การยืนยันตัวตนล้มเหลว; โทเค็นหมดอายุหรือถูกปิดใช้งานแล้ว
2004 403 ไม่มีสิทธิ์เรียกใช้ API นี้
3001 400 รูปแบบพารามิเตอร์คำขอไม่ถูกต้อง โปรดตรวจสอบว่า request body เป็น JSON ที่ถูกต้องและสอดคล้องกับรูปแบบพารามิเตอร์
3002 400 พารามิเตอร์คำขอไม่ถูกต้อง โปรดตรวจสอบว่าพารามิเตอร์คำขอเป็นไปตามข้อกำหนด
4001 400 ไม่มีเทมเพลตนี้อยู่ในระบบ

ดึงรายการเทมเพลตทั้งหมด

ปัจจุบัน API นี้ยังไม่รองรับการแบ่งหน้า ระบบจะส่งกลับรายการสรุปของเทมเพลตทั้งหมด และโดยหลักจะไม่รวมเนื้อหาแบบละเอียด หากคุณต้องการเนื้อหาโดยละเอียด โปรดใช้ API สำหรับดูรายละเอียด

Endpoint

GET /v1/template-configs

การยืนยันตัวตน

ใช้ HTTP Basic Authentication สำหรับการยืนยันตัวตน และเพิ่ม Authorization ลงใน HTTP header:

Authorization: Basic ${base64_auth_string}
              
              Authorization: Basic ${base64_auth_string}

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

อัลกอริทึมสำหรับสร้าง base64_auth_string ข้างต้นคือ base64(dev_key:dev_secret)

ตัวอย่างคำขอ

Request Header

GET /v1/template-configs HTTP/1.1 Authorization: Basic amlndWFuZ2RldjpkZXZfc2VjcmV0
              
              GET /v1/template-configs HTTP/1.1
Authorization: Basic amlndWFuZ2RldjpkZXZfc2VjcmV0

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

Request Body

ไม่มี

พารามิเตอร์คำขอ

ไม่มี

การตอบกลับเมื่อสำเร็จ

[{ "template_id": "test-template-1", "description": "测试模版1", "send_channel_strategy": "whatsapp|sms", "brand_name": "品牌名称", "verify_code_config": { "verify_code_type": 1, "verify_code_len": 6, "verify_code_ttl": 1 }, "whatsapp_config": { "template_type": 1 }, "sms_config": { "template_type": 2, "template_parts": 1 }, "voice_config": { "template_type": 1 }, "email_config": { "template_name": "email模板名称" }, "pwa_config": { "pwa_platform": "xx", "pwa_code": "xx" }, "created_time": 1234567890, "status": 1, "audit_remark": "xx" }]
              
              [{
    "template_id": "test-template-1",
    "description": "测试模版1",
    "send_channel_strategy": "whatsapp|sms",
    "brand_name": "品牌名称",
    "verify_code_config": {
        "verify_code_type": 1,
        "verify_code_len": 6,
        "verify_code_ttl": 1
    },
    "whatsapp_config": {
        "template_type": 1
    },
    "sms_config": {
        "template_type": 2,
        "template_parts": 1
    },
    "voice_config": {
        "template_type": 1
    },
    "email_config": {
        "template_name": "email模板名称"
    },
    "pwa_config": {
        "pwa_platform": "xx",
        "pwa_code": "xx"
    },
    "created_time": 1234567890,
    "status": 1,
    "audit_remark": "xx"
}]

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

การตอบกลับเมื่อล้มเหลว

{ "code": 4001, "message": "config not exist" }
              
              {
    "code": 4001,
    "message": "config not exist"
}

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

รหัสข้อผิดพลาด

Error Code HTTP Code Description
1000 500 ข้อผิดพลาดภายในระบบ
2001 401 การยืนยันตัวตนล้มเหลว; ไม่มีการระบุโทเค็นที่ถูกต้อง
2002 401 การยืนยันตัวตนล้มเหลว; โทเค็นหมดอายุหรือถูกปิดใช้งานแล้ว
2004 403 ไม่มีสิทธิ์เรียกใช้ API นี้
4001 400 ไม่มีเทมเพลตนี้อยู่ในระบบ

ดูรายละเอียดเทมเพลต

Endpoint

GET /v1/template-configs/{templateId}

การยืนยันตัวตน

ใช้ HTTP Basic Authentication สำหรับการยืนยันตัวตน และเพิ่ม Authorization ลงใน HTTP header:

Authorization: Basic ${base64_auth_string}
              
              Authorization: Basic ${base64_auth_string}

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

อัลกอริทึมสำหรับสร้าง base64_auth_string ข้างต้นคือ base64(dev_key:dev_secret)

ตัวอย่างคำขอ

Request Header

GET /v1/template-configs/custom-template-id HTTP/1.1 Authorization: Basic amlndWFuZ2RldjpkZXZfc2VjcmV0
              
              GET /v1/template-configs/custom-template-id HTTP/1.1
Authorization: Basic amlndWFuZ2RldjpkZXZfc2VjcmV0

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

Request Body

ไม่มี

พารามิเตอร์คำขอ

{templateId} ใน URL หมายถึง ID ของเทมเพลตที่ต้องการดึงข้อมูล ซึ่งผู้เรียกกำหนดไว้เมื่อใช้งาน Create Template API

การตอบกลับเมื่อสำเร็จ

{ "template_id": "test-template-1", "description": "测试模版1", "send_channel_strategy": "whatsapp|sms", "brand_name": "品牌名称", "verify_code_config": { "verify_code_type": 1, "verify_code_len": 6, "verify_code_ttl": 1 }, "whatsapp_config": { "template_type": 1 }, "sms_config": { "template_type": 2, "template_parts": 1, "template_custom_config": { "custom_sub_type": "authentication", "custom_content": "xxx" } }, "voice_config": { "template_type": 1 }, "email_config": { "template_name": "email模板名称", "template_custom_configs": [{ "language": "default", "pre_from_name": "test", "pre_from_mail": "test@test.com", "pre_subject": "test", "template_content": "预设邮件模版内容,必填,自定义变量如{{self}},验证码是{{code}}", "pre_param_map": { "self": "这里是self变量预设值" } }] }, "pwa_config": { "pwa_platform": "xx", "pwa_code": "xx" }, "created_time": 1234567890, "status": 1, "audit_remark": "xx" }
              
              {
    "template_id": "test-template-1",
    "description": "测试模版1",
    "send_channel_strategy": "whatsapp|sms",
    "brand_name": "品牌名称",
    "verify_code_config": {
        "verify_code_type": 1,
        "verify_code_len": 6,
        "verify_code_ttl": 1
    },
    "whatsapp_config": {
        "template_type": 1
    },
    "sms_config": {
        "template_type": 2,
        "template_parts": 1,
        "template_custom_config": {
            "custom_sub_type": "authentication",
            "custom_content": "xxx"
        }
    },
    "voice_config": {
        "template_type": 1
    },
    "email_config": {
        "template_name": "email模板名称",
        "template_custom_configs": [{
            "language": "default",
            "pre_from_name": "test",
            "pre_from_mail": "test@test.com",
            "pre_subject": "test",
            "template_content": "预设邮件模版内容,必填,自定义变量如{{self}},验证码是{{code}}",
            "pre_param_map": {
                "self": "这里是self变量预设值"
            }
        }]
    },
    "pwa_config": {
        "pwa_platform": "xx",
        "pwa_code": "xx"
    },
    "created_time": 1234567890,
    "status": 1,
    "audit_remark": "xx"
}

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

การตอบกลับเมื่อล้มเหลว

{ "code": 4001, "message": "config not exist" }
              
              {
    "code": 4001,
    "message": "config not exist"
}

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

รหัสข้อผิดพลาด

Error Code HTTP Code Description
1000 500 ข้อผิดพลาดภายในระบบ
2001 401 การยืนยันตัวตนล้มเหลว; ไม่มีการระบุโทเค็นที่ถูกต้อง
2002 401 การยืนยันตัวตนล้มเหลว; โทเค็นหมดอายุหรือถูกปิดใช้งานแล้ว
2004 403 ไม่มีสิทธิ์เรียกใช้ API นี้
4001 400 ไม่มีเทมเพลตนี้อยู่ในระบบ
Icon Solid Transparent White Qiyu
ติดต่อฝ่ายขาย