Help Center bat/messagelist를 통한 WhatsApp

bat/messagelist를 통한 WhatsApp

WhatsApp Business 메시지는 SMS 및 Viber와 동일한 요청인 POST /bat/messagelist에 "type": "whatsapp"을 지정하여 보냅니다. 메시지 내용은 whatsAppMessage 객체에 넣습니다.

이 페이지의 모든 예제에 대한 바로 사용할 수 있는 요청은 Postman 컬렉션에 있습니다. 아래 “Postman 컬렉션” 섹션을 참조하십시오.

메시지 종류 두 가지

종류whatsAppMessage.type보낼 수 있는 시점
세션 메시지: 텍스트, 미디어, 위치, 연락처, 인터랙티브text, media, location, contact, interactive고객의 마지막 수신 메시지 이후 24시간 세션 창 내에서만 가능합니다.
템플릿template언제든지 가능합니다. 템플릿은 WhatsApp Business Account(WABA)에서 승인되어야 합니다.

세션 창이 없으면 승인된 템플릿을 보내십시오. 이 규칙은 WhatsApp이 폴백 체인의 한 단계인 경우에도 적용됩니다.

공통 필드

{
  "callbackUrl": "https://example.com/smsbat/status",
  "messages": [
    {
      "from": "WABA_PHONE",
      "to": "RECIPIENT_PHONE",
      "type": "whatsapp",
      "ttl": 60,
      "whatsAppMessage": { "type": "text", "text": "Your order is ready." }
    }
  ]
}
필드설명
callbackUrl전달 콜백을 받을 주소입니다. 선택 사항입니다.
from메시지를 보내는 WhatsApp Business 번호입니다.
to수신자 번호입니다.
typewhatsapp.
ttl메시지 유효 시간(초)입니다. 예제에서는 60을 사용하며, 사용자의 시나리오에 맞게 설정하십시오.
whatsAppMessage메시지 내용입니다. 아래 섹션을 참조하십시오.

인증: 모든 SMSBAT API 요청과 마찬가지로 조직 키가 담긴 X-Authorization-Key 헤더를 사용합니다.

세션 메시지

이 섹션의 모든 예제에는 24시간 세션 창이 필요합니다.

텍스트

"whatsAppMessage": {
  "type": "text",
  "text": "Your order is ready."
}

캡션이 있는 이미지

"whatsAppMessage": {
  "type": "media",
  "media": {
    "type": "image",
    "url": "https://example.com/image.png",
    "caption": "Your order is ready."
  }
}

media.url은 이미지의 공개 HTTPS 주소입니다. caption은 선택 사항입니다.

캡션이 있는 동영상

"whatsAppMessage": {
  "type": "media",
  "media": {
    "type": "video",
    "url": "https://example.com/video.mp4",
    "caption": "Your order is ready."
  }
}

오디오

"whatsAppMessage": {
  "type": "media",
  "media": {
    "type": "audio",
    "url": "https://example.com/audio.mp3"
  }
}

문서

"whatsAppMessage": {
  "type": "media",
  "media": {
    "type": "document",
    "url": "https://example.com/invoice.pdf",
    "filename": "invoice.pdf",
    "caption": "Your invoice"
  }
}

filename은 수신자에게 표시되는 파일 이름을 설정합니다. caption은 선택 사항입니다.

media 필드:

필드설명
typeimage, video, audio 또는 document.
url파일의 공개 HTTPS 주소입니다.
caption캡션입니다. 선택 사항이며, 예제에서는 이미지, 동영상, 문서에 사용합니다.
filename문서의 파일 이름입니다.

위치

"whatsAppMessage": {
  "type": "location",
  "location": {
    "latitude": 48.1486,
    "longitude": 17.1077,
    "name": "Pickup point",
    "address": "Bratislava"
  }
}

필요한 경우 장소 이름과 주소를 추가하십시오.

연락처

"whatsAppMessage": {
  "type": "contact",
  "contact": {
    "name": {
      "formatted_name": "Support Team",
      "first_name": "Support"
    },
    "phones": [
      { "phone": "+421900000000", "type": "WORK" }
    ]
  }
}

전체 표시 이름(formatted_name) 외에 이름 필드를 하나 이상 더 입력하십시오(예: first_name).

답장 버튼

"whatsAppMessage": {
  "type": "interactive",
  "interactive": {
    "type": "button",
    "body": { "text": "Confirm your order" },
    "action": {
      "buttons": [
        { "type": "reply", "reply": { "id": "confirm", "title": "Confirm" } },
        { "type": "reply", "reply": { "id": "cancel", "title": "Cancel" } }
      ]
    }
  }
}

reply.id로 수신자가 어떤 버튼을 눌렀는지 구분합니다. reply.title은 버튼 라벨입니다.

목록

"whatsAppMessage": {
  "type": "interactive",
  "interactive": {
    "type": "list",
    "body": { "text": "Choose a pickup point" },
    "action": {
      "button": "View options",
      "sections": [
        {
          "title": "Pickup points",
          "rows": [
            { "id": "center", "title": "City centre" },
            { "id": "station", "title": "Main station" }
          ]
        }
      ]
    }
  }
}

action.button은 목록을 여는 버튼의 라벨입니다. sections[].rows[]는 선택 항목이며, 각 항목에는 id와 title이 있습니다.

템플릿

템플릿은 세션 창 없이 언제든지 보낼 수 있습니다. 템플릿은 발신에 사용하는 WABA에서 승인되어야 합니다.

템플릿 작성 방법

필드설명
template.id승인된 템플릿의 정확한 이름입니다.
template.language해당 템플릿의 언어 코드입니다(예: uk 또는 en_US).
template.body.parameters텍스트 변수의 값이며, 템플릿 순서대로 [{ "text": "..." }] 형식입니다. 변수가 없으면 body를 생략하십시오.
template.header변수가 있는 헤더의 템플릿에만 사용합니다. 고정 헤더에는 필요하지 않습니다.
template.buttons동적 URL 버튼과 빠른 답장 버튼에만 사용합니다.

고정 버튼 URL과 전화 걸기 버튼의 전화번호는 템플릿 자체에 설정되며 전송 시에는 전달하지 않습니다. 매개변수와 버튼의 수는 승인된 템플릿과 일치해야 합니다.

텍스트

"whatsAppMessage": {
  "type": "template",
  "template": {
    "id": "YOUR_TEMPLATE_NAME",
    "language": "uk",
    "body": {
      "parameters": [ { "text": "Alex" } ]
    }
  }
}

동적 URL 버튼

"whatsAppMessage": {
  "type": "template",
  "template": {
    "id": "YOUR_TEMPLATE_NAME",
    "language": "uk",
    "body": {
      "parameters": [
        { "text": "Oleh" },
        { "text": "1 January 2024" },
        { "text": "+1 555-745-2867" }
      ]
    },
    "buttons": [
      { "type": "url", "index": 0, "url_parameter": "ORDER-123" }
    ]
  }
}

index는 템플릿에서 버튼의 위치이며 0부터 시작합니다. url_parameter에는 주소의 변수 부분만 전달하십시오. 예를 들어 버튼 URL이 https://example.com/orders/{{1}}인 경우 값 ORDER-123은 https://example.com/orders/ORDER-123을 만듭니다. 버튼 URL이 고정이면 buttons를 전달하지 마십시오.

빠른 답장 버튼

"buttons": [
  { "type": "quick_reply", "index": 0, "quick_reply_payload": "CONFIRM" },
  { "type": "quick_reply", "index": 1, "quick_reply_payload": "CANCEL" }
]

quick_reply_payload는 수신자가 어떤 버튼을 눌렀는지 구분하는 데 도움이 됩니다. 버튼 인덱스는 템플릿과 일치해야 합니다.

헤더: 텍스트

"header": { "type": "text", "text": "Order 123" }

header.text에 헤더 변수의 값을 전달하십시오.

헤더: 이미지, 동영상, 문서

"header": { "type": "image", "image": { "url": "https://example.com/image.png" } }
"header": { "type": "video", "video": { "url": "https://example.com/video.mp4" } }
"header": {
  "type": "document",
  "document": { "url": "https://example.com/file.pdf", "filename": "sample.pdf" }
}

URL은 공개 HTTPS 주소여야 합니다. 문서의 경우 filename이 첨부 파일 이름을 설정합니다.

전달 상태

WhatsApp 메시지 상태는 전달 콜백 형식으로 callbackUrl에 도착합니다: delivered, undeliverable 또는 permanenterror.

Postman 컬렉션

“OmniSMSBat · BAT /messagelist” 컬렉션 다운로드: WhatsApp(세션 메시지 및 7가지 템플릿), Viber Business, SMS, 폴백에 대한 바로 사용할 수 있는 요청입니다.

  1. 파일을 Postman으로 가져옵니다.
  2. 컬렉션 변수를 입력합니다: orgKey(조직 키), toPhone(수신자 번호), wabaPhone(WhatsApp 발신자 번호), alphaName(Viber Business 및 SMS용 알파 네임), 필요한 경우 callbackUrl.
  3. 템플릿 요청에서 template.id의 PLACEHOLDER_...를 승인된 템플릿의 이름으로 바꾸고 template.language를 확인하십시오.

요청은 프로덕션 서버 https://restapi.smsbat.com으로 전송되며 요금이 부과될 수 있습니다. 별도의 테스트 환경은 없습니다.

관련 문서