SMSBAT รองรับชั้นความเข้ากันได้กับ Messagio API. สิ่งนี้ทำให้คุณสามารถย้ายการผสานรวม Viber ที่ออกแบบมาสำหรับ Messagio ไปยัง SMSBAT ได้โดยไม่ต้องเขียนโครงสร้าง payload ใหม่หรือเปลี่ยนตรรกะการผสานรวม
การตั้งค่าการเชื่อมต่อ
เพื่อส่งคำขอผ่าน SMSBAT ให้ปรับปรุง base URL และข้อมูลประจำตัวการตรวจสอบในการผสานรวมของคุณ:
- Base URL:
https://restapi.smsbat.com
- Endpoint:
POST /api/SendMessage
- Request Format:
application/x-www-form-urlencoded (ข้อมูลฟอร์ม)
การตรวจสอบสิทธิ์และข้อมูลประจำตัว
คำขอจะได้รับการตรวจสอบโดยใช้พารามิเตอร์ที่ส่งโดยตรงในข้อมูลฟอร์มของ body คำขอ:
| พารามิเตอร์ | ประเภท | จำเป็น | คำอธิบาย |
|---|
user | string | Yes | การเข้าสู่ระบบบัญชี SMSBAT ของคุณหรือรหัสผู้ใช้. |
sign | string | Yes | รหัสลับ API หรือลายเซ็นที่ลงทะเบียนสำหรับชื่อผู้ส่ง. |
from | string | Yes | ชื่ออัลฟ่าผู้ส่งที่ลงทะเบียน. |
sending_method | string | Yes | ประเภทช่องทาง ใช้ viber สำหรับข้อความ Viber Business ปกติหรือ viber_otp สำหรับเทมเพลต Viber OTP. |
phone | string | Yes | หมายเลขโทรศัพท์ของผู้รับในรูปแบบสากล (เช่น 380501234567). |
ประเภทข้อความ Viber
เลือกแท็บด้านล่างเพื่อดูพารามิเตอร์เฉพาะและ payload ของคำขอสำหรับโครงสร้างข้อความ Viber ต่างๆ:
ส่งข้อความแบบง่าย.
พารามิเตอร์เพิ่มเติม:
| พารามิเตอร์ | ประเภท | จำเป็น | คำอธิบาย |
|---|
txt | string | Yes | ข้อความ. |
ตัวอย่าง Payload ของคำขอ:
POST /api/SendMessage HTTP/1.1
Host: restapi.smsbat.com
Content-Type: application/x-www-form-urlencoded
sending_method=viber&from=MySender&user=myuser&phone=380501234567&sign=api_secret_signature&txt=Hello+from+SMSBAT%21
ส่งข้อความพร้อมปุ่มเรียกการกระทำแบบโต้ตอบ.
พารามิเตอร์เพิ่มเติม:
| พารามิเตอร์ | ประเภท | จำเป็น | คำอธิบาย |
|---|
txt | string | Yes | ข้อความ. |
button_text | string | Yes | ข้อความที่แสดงบนปุ่ม. |
button_link | string | Yes | URL ปลายทางเมื่อคลิกปุ่ม. |
ตัวอย่าง Payload ของคำขอ:
POST /api/SendMessage HTTP/1.1
Host: restapi.smsbat.com
Content-Type: application/x-www-form-urlencoded
sending_method=viber&from=MySender&user=myuser&phone=380501234567&sign=api_secret_signature&txt=Check+our+latest+offers%21&button_text=Open&button_link=https%3A%2F%2Fwww.example.com
ส่งไฟล์รูปภาพสาธารณะ.
พารามิเตอร์เพิ่มเติม:
| พารามิเตอร์ | ประเภท | จำเป็น | คำอธิบาย |
|---|
image_link | string | Yes | URL HTTPS สาธารณะของรูปภาพ. |
txt | string | No | ข้อความคำบรรยายแบบเลือกเพื่อแสดงใต้รูปภาพ. |
ตัวอย่าง Payload ของคำขอ:
POST /api/SendMessage HTTP/1.1
Host: restapi.smsbat.com
Content-Type: application/x-www-form-urlencoded
sending_method=viber&from=MySender&user=myuser&phone=380501234567&sign=api_secret_signature&image_link=https%3A%2F%2Fwww.example.com%2Fimage.png
ส่งการ์ดแบบรีชที่มีข้อความ รูปภาพ และปุ่ม.
พารามิเตอร์เพิ่มเติม:
| พารามิเตอร์ | ประเภท | จำเป็น | คำอธิบาย |
|---|
txt | string | Yes | ข้อความคำบรรยาย. |
image_link | string | Yes | URL HTTPS สาธารณะของรูปภาพ. |
button_text | string | Yes | ข้อความที่แสดงบนปุ่ม. |
button_link | string | Yes | URL ปลายทางเมื่อคลิกปุ่ม. |
ตัวอย่าง Payload ของคำขอ:
POST /api/SendMessage HTTP/1.1
Host: restapi.smsbat.com
Content-Type: application/x-www-form-urlencoded
sending_method=viber&from=MySender&user=myuser&phone=380501234567&sign=api_secret_signature&txt=Hot+deals+inside%21&image_link=https%3A%2F%2Fwww.example.com%2Fimage.png&button_text=Open&button_link=https%3A%2F%2Fwww.example.com
ส่งไฟล์วิดีโอพร้อมคำบรรยายข้อความแบบเลือกและปุ่มดำเนินการ.
พารามิเตอร์เพิ่มเติม:
| พารามิเตอร์ | ประเภท | จำเป็น | คำอธิบาย |
|---|
video.url | string | Yes | URL HTTPS สาธารณะของไฟล์วิดีโอ. |
video.thumbnail | string | Yes | URL HTTPS สาธารณะของภาพตัวอย่างวิดีโอ. |
video.size_mb | integer | Yes | ขนาดไฟล์วิดีโอโดยประมาณเป็นเมกะไบต์. |
video.duration_sec | integer | Yes | ระยะเวลาวิดีโอเป็นวินาที. |
txt | string | No | ข้อความอธิบายเพิ่มเติม (ไม่บังคับ). |
button_text | string | No | ข้อความปุ่มแบบเลือก (สามารถทำหน้าที่เป็นคำบรรยายหรือลิงก์). |
button_link | string | No | URL ลิงก์ปุ่มแบบเลือก. |
ตัวอย่าง Payload ของคำขอ:
POST /api/SendMessage HTTP/1.1
Host: restapi.smsbat.com
Content-Type: application/x-www-form-urlencoded
sending_method=viber&from=MySender&user=myuser&phone=380501234567&sign=api_secret_signature&txt=Watch+this+tutorial%21&video.url=https%3A%2F%2Fwww.example.com%2Fvideo.mp4&video.thumbnail=https%3A%2F%2Fwww.example.com%2Fvideo-thumbnail.png&video.size_mb=1&video.duration_sec=3&button_text=Open&button_link=https%3A%2F%2Fwww.example.com
ส่งรหัสผ่านครั้งเดียว (OTP) ของ Viber โดยใช้เทมเพลตที่ได้รับการอนุมัติล่วงหน้า.
Note
เมื่อส่งข้อความ OTP คุณต้องตั้งค่า sending_method เป็น viber_otp.
พารามิเตอร์เพิ่มเติม:
| พารามิเตอร์ | ชนิด | จำเป็น | คำอธิบาย |
|---|
template.id | string | Yes | ID ของเทมเพลต OTP Viber ที่ได้รับการอนุมัติล่วงหน้า. |
template.lang | string | Yes | รหัสภาษาของเทมเพลต (เช่น en, uk). |
template.params.pin | string | Yes | ค่า PIN OTP ที่จะใส่ลงในเทมเพลต. |
template.params.business_platform_name | string | Yes | ตัวแปรสำหรับชื่อธุรกิจในเทมเพลต. |
template.params.code_validity_time | string | Yes | ระยะเวลาความถูกต้องของ PIN เป็นนาที. |
ตัวอย่าง Payload ของคำขอ:
POST /api/SendMessage HTTP/1.1
Host: restapi.smsbat.com
Content-Type: application/x-www-form-urlencoded
sending_method=viber_otp&from=MySender&user=myuser&phone=380501234567&sign=api_secret_signature&template.id=otp_template_123&template.lang=en&template.params.pin=123456&template.params.business_platform_name=SMSBAT&template.params.code_validity_time=7
ส่งการ์ดข้อความแบบโต้ตอบที่มีหลายสไลด์ (การ์ด) ที่ผู้ใช้สามารถสไลด์ผ่านได้.
พารามิเตอร์เพิ่มเติม:
| พารามิเตอร์ | ชนิด | จำเป็น | คำอธิบาย |
|---|
txt | string | Yes | ข้อความหัวเรื่องของแคโรเซล. |
carousel[N].title | string | Yes | หัวเรื่องของการ์ด N (เริ่มที่ 0). |
carousel[N].image_url | string | Yes | URL รูปภาพ HTTPS สาธารณะของการ์ด N. |
carousel[N].primary_label | string | Yes | ข้อความปุ่มหลักของการ์ด N. |
carousel[N].primary_url | string | Yes | URL ลิงก์ของปุ่มหลักของการ์ด N. |
carousel[N].secondary_label | string | No | คำบรรยายปุ่มรองของการ์ด N. |
carousel[N].secondary_url | string | No | URL ลิงก์ปุ่มรองของการ์ด N. |
ตัวอย่าง Payload ของคำขอ:
POST /api/SendMessage HTTP/1.1
Host: restapi.smsbat.com
Content-Type: application/x-www-form-urlencoded
sending_method=viber&from=MySender&user=myuser&phone=380501234567&sign=api_secret_signature&txt=Top+picks+for+you&carousel%5B0%5D.title=First+Offer&carousel%5B0%5D.image_url=https%3A%2F%2Fwww.example.com%2Fitem-1.png&carousel%5B0%5D.primary_label=Open&carousel%5B0%5D.primary_url=https%3A%2F%2Fwww.example.com%2Fitem-1&carousel%5B0%5D.secondary_label=Details&carousel%5B0%5D.secondary_url=https%3A%2F%2Fwww.example.com%2Fitem-1%2Fdetails&carousel%5B1%5D.title=Second+Offer&carousel%5B1%5D.image_url=https%3A%2F%2Fwww.example.com%2Fitem-2.png&carousel%5B1%5D.primary_label=Open&carousel%5B1%5D.primary_url=https%3A%2F%2Fwww.example.com%2Fitem-2
ส่งข้อความที่มีแบบสำรวจหรือคำถามเชิงโต้ตอบ
พารามิเตอร์เพิ่มเติม:
| พารามิเตอร์ | ชนิด | จำเป็น | คำอธิบาย |
|---|
txt | string | Yes | ข้อความคำถามสำรวจ. |
survey_options[N] | string | Yes | ข้อความตัวเลือกสำรวจสำหรับรายการ N (ดัชนีเริ่มที่ 0). ต้องมีอย่างน้อย 2 ตัวเลือก. |
option_type | integer | Yes | ประเภทของตัวเลือก: 1 (RadioButtons) หรือ 2 (Buttons ปกติ). |
ตัวอย่าง Payload ของคำขอ:
POST /api/SendMessage HTTP/1.1
Host: restapi.smsbat.com
Content-Type: application/x-www-form-urlencoded
sending_method=viber&from=MySender&user=myuser&phone=380501234567&sign=api_secret_signature&txt=Please+rate+our+service&survey_options%5B0%5D=Excellent&survey_options%5B1%5D=Good&survey_options%5B2%5D=Average&option_type=1
รูปแบบการตอบกลับ
Endpoint ความเข้ากันได้ของ Messagio API จะคืนค่าการตอบกลับใน รูปแบบ XML พร้อมสถานะ HTTP 200 OK.
การตอบกลับที่ยอมรับ (สำเร็จ)
<response>
<code>0</code>
<tech_message>OK</tech_message>
<msg_id phone="380501234567">MESSAGE_GUID</msg_id>
</response>
การตอบกลับข้อผิดพลาด
หากการตรวจสอบพารามิเตอร์ของคำขอหรือการตรวจสอบสิทธิ์ล้มเหลว การตอบกลับจะคืนค่าโค้ดที่ไม่เป็นศูนย์.
<response>
<code>-1</code>
<tech_message>PARAM ERROR (sign)</tech_message>
</response>
<response>
<code>-2</code>
<tech_message>ERROR(unauthorized)</tech_message>
</response>
คอลแบ็ก
URL สำหรับ Callback ต้องถูกนำไปใช้งานและโฮสต์บนแพลตฟอร์มของคุณ SMSBAT ส่ง HTTP callbacks เพื่ออัปเดตระบบของคุณเกี่ยวกับเหตุการณ์การจัดส่ง การตอบแบบสำรวจ และการตอบกลับของผู้ใช้.
1. สถานะการจัดส่ง Callback
ส่งเมื่อข้อความเปลี่ยนสถานะ (delivered, read, failed).
- Content-Type:
application/x-www-form-urlencoded
- Method:
POST
รูปแบบ Payload ของ Request:
- Delivered:
msg_id=MESSAGE_GUID&status=delivered
- Seen/Read:
msg_id=MESSAGE_GUID&status=delivered&type=seen
- Undelivered / Failed:
msg_id=MESSAGE_GUID&status=undelivered&status_extended=REASON
คำอธิบายฟิลด์:
msg_id: รหัสข้อความที่เป็นเอกลักษณ์ของ SMSBAT (GUID) ที่ส่งกลับใน response ของ SendMessage.
status: ผลลัพธ์การจัดส่ง (delivered, undelivered, หรือ status unknown).
type: ตั้งค่าเป็น seen เมื่อข้อความถูกผู้รับดู.
status_extended: เหตุผลทางเทคนิคเฉพาะสำหรับสถานะ undelivered (เช่น VIBER_EXPIRED, VIBER_BLOCKED_BY_USER, VIBER_USER_NOT_FOUND, VIBER_NO_DEVICE).
2. Survey Answer Callback
ทำงานเมื่อผู้ใช้เลือกตัวเลือกการตอบในข้อความ Viber Survey.
- Content-Type:
application/x-www-form-urlencoded
- Method:
POST
รูปแบบ Payload ของ Request:
msg_id=ORIGINAL_SURVEY_MESSAGE_GUID&text=SELECTED_OPTION_TEXT
3. Inbound User Message Callback
จะทำงานเมื่อผู้ใช้ส่งข้อความหรือสื่อตอบกลับไปยังบริการ Viber Business ของคุณ.
- ประเภทเนื้อหา:
application/json
- วิธี:
POST
รูปแบบข้อมูลที่ส่งคำขอ:
{
"msg_id": "INBOUND_MESSAGE_GUID",
"text": "Hello, I have a question",
"media": "https://example.com/user-attachment.png",
"phone": "380501234567",
"sender_bm_id": "12345"
}
คำอธิบายฟิลด์:
msg_id: ID ข้อความที่ไม่ซ้ำกันซึ่งสร้างขึ้นสำหรับการตอบกลับขาเข้า.
text: เนื้อหาข้อความที่ผู้ใช้ส่ง (สามารถเป็น null หากส่งสื่อเท่านั้น).
media: URL โดยตรงสำหรับดาวน์โหลดไฟล์สื่อที่ผู้ใช้ส่ง (สามารถเป็น null หากเป็นข้อความเท่านั้น).
phone: หมายเลขโทรศัพท์ของผู้ส่งในรูปแบบสากล.
sender_bm_id: ID ผู้ส่ง Viber Business.