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

# Canal de notificaciones - LINE SDK for Laravel

> Integra el sistema de notificaciones de Laravel con la API de LINE Messaging para enviar notificaciones.

## Resumen

Con `LineChannel` puedes enviar mensajes a LINE desde Laravel Notifications.

<Info>
  Con el cierre del servicio de LINE Notify, la compatibilidad con LINE Notify ha finalizado. Actualmente las notificaciones utilizan la API de Messaging, por lo que existen límites de mensajes según el plan de precios. Consulta las [tarifas de la API de Messaging](https://developers.line.biz/ja/docs/messaging-api/pricing/).
</Info>

## Clase Notification

En `via()` devuelve `LineChannel::class` y en `toLine()` define el mensaje.

```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');
    }
}
```

## Patrones de envío

### Notificaciones On-Demand

Para enviar notificaciones sin vincularlas a un modelo de usuario, utiliza `Notification::route()`. El destino es un `userId` o un `groupId`.

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

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

### Notificación desde el modelo User

Para gestionar el destino por usuario, define `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>
  Puedes obtener `userId` y `groupId` de eventos de Webhook como `FollowEvent` o `JoinEvent`.
</Info>

## Tipos de mensaje

### Texto

Se pueden enviar hasta 5 mensajes.

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

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

### Personalizar el nombre y el icono del remitente

`withSender()` debe llamarse antes que los métodos que añaden mensajes.

```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');
}
```

También puedes indicar el nombre y el icono como parámetros de `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');
}
```

### Stickers

Consulta la [lista de stickers](https://developers.line.biz/ja/docs/messaging-api/sticker-list/) para ver los que puedes usar.

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

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

### Imagen

Indica una URL pública.

```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');
}
```

### Vídeo

Indica una URL pública.

```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');
}
```

### Otros tipos de mensaje

Con `message()` puedes añadir cualquier tipo de mensaje. Especifica el tipo con `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>
  Para la información más reciente, consulta el [repositorio de GitHub](https://github.com/invokable/laravel-line-sdk).
</Info>


## Related topics

- [Canal de notificaciones - Laravel Bluesky](/es/packages/laravel-bluesky/notification.md)
- [LINE SDK for Laravel](/es/packages/laravel-line-sdk/index.md)
- [Notificaciones](/es/notifications.md)
- [Comparativa de métodos de autenticación - Laravel Bluesky](/es/packages/laravel-bluesky/authentication.md)
- [Laravel Bluesky](/es/packages/laravel-bluesky/index.md)
