> ## Documentation Index
> Fetch the complete documentation index at: https://kawax.biz/llms.txt
> Use this file to discover all available pages before exploring further.

# 알림 채널 - LINE SDK for Laravel

> Laravel Notification System과 LINE Messaging API를 통합해 알림을 전송합니다.

## 개요

`LineChannel`을 사용하면 Laravel Notifications에서 LINE으로 메시지를 전송할 수 있습니다.

<Info>
  LINE Notify의 서비스 종료에 따라 LINE Notify 지원은 종료되었습니다. 현재는 Messaging API에 의한 알림이므로 요금 플랜별로 발송 수 제한이 있습니다. [Messaging API 요금](https://developers.line.biz/ja/docs/messaging-api/pricing/)을 참조하세요.
</Info>

## Notification 클래스

`via()`에서 `LineChannel::class`를 반환하고, `toLine()`에서 메시지를 정의합니다.

```php theme={null}
use Illuminate\Notifications\Notification;
use Revolution\Line\Notifications\LineChannel;
use Revolution\Line\Notifications\LineMessage;

class TestNotification extends Notification
{
    public function via(object $notifiable): array
    {
        return [
            LineChannel::class,
        ];
    }

    public function toLine(object $notifiable): LineMessage
    {
        return LineMessage::create(text: 'test');
    }
}
```

## 전송 패턴

### On-Demand 알림

사용자 모델에 연결하지 않고 알림을 보낼 때는 `Notification::route()`를 사용합니다. 전송 대상은 `userId` 또는 `groupId`입니다.

```php theme={null}
use Illuminate\Support\Facades\Notification;

Notification::route('line', 'to')
            ->notify(new TestNotification());
```

### User 모델에서의 알림

User마다 전송 대상을 관리하려면 `routeNotificationForLine()`을 정의합니다.

```php theme={null}
use Illuminate\Notifications\Notifiable;

class User extends Model
{
    use Notifiable;

    public function routeNotificationForLine($notification): string
    {
        return $this->line_id;
    }
}
```

```php theme={null}
$user->notify(new TestNotification());
```

<Info>
  `userId`나 `groupId`는 `FollowEvent`나 `JoinEvent` 등 Webhook 이벤트에서 얻을 수 있습니다.
</Info>

## 메시지 타입

### 텍스트

최대 5건까지 전송할 수 있습니다.

```php theme={null}
use Revolution\Line\Notifications\LineMessage;

public function toLine(object $notifiable): LineMessage
{
    return LineMessage::create()
                      ->text('text 1')
                      ->text('text 2');
}
```

### 발신자 이름과 아이콘 커스터마이징

`withSender()`는 메시지 추가 메서드보다 먼저 호출해야 합니다.

```php theme={null}
use Revolution\Line\Notifications\LineMessage;

public function toLine(object $notifiable): LineMessage
{
    return LineMessage::create()
                      ->withSender(name: 'alt-name', icon: 'https://...png')
                      ->text('text 1')
                      ->text('text 2');
}
```

`create()`의 매개변수로 이름과 아이콘을 지정할 수도 있습니다.

```php theme={null}
use Revolution\Line\Notifications\LineMessage;

public function toLine(object $notifiable): LineMessage
{
    return LineMessage::create(text: 'test', name: 'alt-name', icon: 'https://...png');
}
```

### 스티커

사용할 수 있는 스티커는 [Sticker list](https://developers.line.biz/ja/docs/messaging-api/sticker-list/)를 참조하세요.

```php theme={null}
use Revolution\Line\Notifications\LineMessage;

public function toLine(object $notifiable): LineMessage
{
    return LineMessage::create()
                      ->text('test')
                      ->sticker(package: 446, sticker: 1988);
}
```

### 이미지

공개 URL을 지정합니다.

```php theme={null}
use Revolution\Line\Notifications\LineMessage;

public function toLine(object $notifiable): LineMessage
{
    return LineMessage::create()
                      ->image(original: 'https://.../test.png', preview: 'https://.../preview.png');
}
```

### 동영상

공개 URL을 지정합니다.

```php theme={null}
use Revolution\Line\Notifications\LineMessage;

public function toLine(object $notifiable): LineMessage
{
    return LineMessage::create()
                      ->video(original: 'https://.../test.mp4', preview: 'https://.../preview.png');
}
```

### 기타 메시지 타입

`message()`를 사용하면 임의의 메시지 타입을 추가할 수 있습니다. `setType()`로 타입을 지정하세요.

```php theme={null}
use LINE\Clients\MessagingApi\Model\LocationMessage;
use LINE\Constants\MessageType;
use Revolution\Line\Notifications\LineMessage;

public function toLine(object $notifiable): LineMessage
{
    $location = (new LocationMessage())
        ->setType(MessageType::LOCATION)
        ->setTitle('title')
        ->setAddress('address')
        ->setLatitude(0.0)
        ->setLongitude(0.0);

    return LineMessage::create()
                      ->message($location);
}
```

<Info>
  최신 정보는 [GitHub 저장소](https://github.com/invokable/laravel-line-sdk)를 참조하세요.
</Info>


## Related topics

- [LINE SDK for Laravel](/ko/packages/laravel-line-sdk/index.md)
- [알림 채널 - Laravel Bluesky](/ko/packages/laravel-bluesky/notification.md)
- [Socialite (LINE Login) - LINE SDK for Laravel](/ko/packages/laravel-line-sdk/socialite.md)
- [Webhook / Bot - LINE SDK for Laravel](/ko/packages/laravel-line-sdk/bot.md)
- [알림(Notifications)](/ko/notifications.md)
