> For the complete documentation index, see [llms.txt](https://tech.x2bee.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tech.x2bee.com/dev-guide/developer-guide-en/dev-start/customer-message-sending/sms-sending.md).

# SMS Sending

This document covers the SMS sending source code and method.

First, it explains how to configure and verify the Config settings.

Second, it explains how to write it at each business layer.

{% hint style="info" %}
**\<update>**<br>

2023.08.03

* Content related to MMS image upload has been added.
* We recommend calling Api Common when sending SMS.
  {% endhint %}

***

## Config Settings

**application.yml**

{% code title="application.yml" %}

```yaml
spring:
  bizMessage:
    accessKey: VHIZ4hLLrhf6uyRIrk4F
    secretKey: pHvcggk52DXYOYYUDvXyLi5RkcmwneeMoOx8xoTd
    sms:
      smsNum: T010-9341-7470 # 발신자 번호 T***-****-****
      serviceId: ncp:sms:kr:309485696868:x2bee
```

{% endcode %}

* The `accessKey`, `secretKey`, and `serviceId` properties are issued by NCP (Naver Cloud Platform).
* The `smsNum` property is the sender number registered and approved with NCP (Naver Cloud Platform).

## Sample Source and Description

* [x2bee-api-sample-vanilla](https://gitlab.x2bee.com/x2bee-venus-beta/venus-x2bee-api-sample-vanilla) project

**BizMessageController**

{% code title="BizMessageController (key excerpt)" %}

```java
@Autowired
private MessageSender messageSender;

@PostMapping("/sendSms")
public ResponseEntity<Response> sendSms() throws Exception {
    ...
    List<MessagesRequest> messagesList = new ArrayList<>();
    for(int i=0;i<10;i++) {
        messagesList.add(MessagesRequest.builder()
            .receiverPhoneNumber("01012341234")
            .subject("LMS, MMS에서만 사용 가능한 제목") //BizMessageRequest.subject 보다 우선적용
            .content("X2BEE 테스트 플래티어님 환영합니다.") //BizMessageRequest.content 보다 우선적용
            .build());
    }

    // 이미지 업로드시
    String image1 = ".jpg, .jpeg 이미지를 Base64로 인코딩한 값, 파일 기준 최대 300Kbyte, 해상도 최대 1500 * 1440";
    String image2 = ".jpg, .jpeg 이미지를 Base64로 인코딩한 값, 파일 기준 최대 300Kbyte, 해상도 최대 1500 * 1440";

    // 이미지 파일은 최대 3개까지만 전송 가능
    List<String> images = new ArrayList<>();
    images.add(image1);
    images.add(image2);
    images.add(image2);

    BizMessageRequest request = BizMessageRequest.builder()
        .messages(messagesList)
        .subject("기본 LMS, MMS에서만 사용 가능한 메시지 제목") //MessagesRequest.subject 에 값이 있으면 무시됨
        .content("기본 메시지 내용") //MessagesRequest.content 에 값이 있으면 무시됨
        .images(images)
        .type("SMS")
        .build();

    //======================================================
    // API-COMMON 호출
    BizMessageResponse response = restApiUtil.post(
        this.commonApiUrl + "/api/common/interface/bizmessage/sendsms",
        request,
        new ParameterizedTypeReference<Response<BizMessageResponse>>() {}
    ).getPayload();
    //======================================================
    // API-COMMON 에서 직접 호출시
    // messageSender.sendSms(request);
    ...
}
```

{% endcode %}

Create a **BizMessageRequest** and enter the parameters by referring to the example and the table below.

* **When sending LMS or MMS, refer to the Notes column in the table below.**

| Item                                | Mandatory | Type   | Description                                                                         | Notes                                                                                                                                                                                                                                                                                                 |
| ----------------------------------- | --------- | ------ | ----------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| BizMessageRequest.type              | NOT NULL  | String | SMS Type                                                                            | SMS, LMS, MMS (lowercase allowed)                                                                                                                                                                                                                                                                     |
| BizMessageRequest.subject           | Optional  | String | Default message subject                                                             | <p><strong>Available only for LMS, MMS</strong></p><ul><li>LMS, MMS: max 40 bytes</li></ul>                                                                                                                                                                                                           |
| BizMessageRequest.content           | Optional  | String | Default message content                                                             | <ul><li>SMS: max 80 bytes</li><li>LMS, MMS: max 2000 bytes</li></ul>                                                                                                                                                                                                                                  |
| BizMessageRequest.messages          | NOT NULL  | List   | Message information                                                                 | <ul><li>See items below (<a href="http://messages.xxx/">messages.XXX</a>)</li><li>Max 100</li></ul>                                                                                                                                                                                                   |
| MessagesRequest.receiverPhoneNumber | NOT NULL  | String | Recipient number                                                                    | Only digits can be entered, excluding hyphens ( - )                                                                                                                                                                                                                                                   |
| MessagesRequest.subject             | Optional  | String | Individual message subject; takes precedence over and overrides the parent subject. | <p><strong>Available only for LMS, MMS</strong></p><ul><li>LMS, MMS: max 40 bytes</li><li>Overrides the parent subject.</li></ul>                                                                                                                                                                     |
| MessagesRequest.content             | NOT NULL  | String | Individual message content; takes precedence over and overrides the parent content. | <ul><li>SMS: max 80 bytes</li><li>LMS, MMS: max 2000 bytes</li><li>Overrides the parent content.</li></ul>                                                                                                                                                                                            |
| BizMessageRequest.images            | Optional  | List   | Base64-encoded file binary value                                                    | <ul><li><code>.jpg</code>, <code>.jpeg</code> 및 the <strong>Base64</strong>-encoded value of the image</li><li>Max 300 KB per file</li><li>Max resolution 1500 \* 1440</li><li>Up to 3 images can be sent as long as the total MMS transmission size is <strong>2000 bytes or less</strong></li></ul> |

{% hint style="info" %}
If you're not familiar with Builder, you can also use Setter.
{% endhint %}

Example (Using Setter)

{% code title="Setter Example" %}

```java
for(int i=0;i<10;i++) {
    MessagesRequest messagesRequest = new MessagesRequest();
    messagesRequest.setReceiverPhoneNumber("01012341234");
    messagesRequest.setContent("X2BEE 테스트 플래티어님 환영합니다.");
    messagesList.add(messagesRequest);
}
```

{% endcode %}

{% hint style="info" %}

### When Sending SMS from Another Project (Recommended Method)

(1) If you are sending SMS from a project other than `x2bee-api-common-vanilla`, call the api-common API.

As shown in the example source, put the required parameters into a `BizMessageRequest` object and call the `/api/common/interface/bizmessage/sendsms` endpoint using the POST method.

* The `messages` and `type` variables are required parameters.
* `commonApiUrl` is the URL specified in application.yml.
  {% endhint %}
