karacweb/kchat-notification-channel

Infomaniak的kChat的Laravel通知通道

1.0.1 2023-08-26 18:50 UTC

This package is auto-updated.

Last update: 2024-09-27 23:17:08 UTC


README

此包使您能够通过Laravel 5.5+、6.x、7.x、8.x、9.x、10.x轻松使用kChat发送通知

Latest Stable Version License PHPUnit tests

此包利用Infomaniak的公共API,通过Laravel 5.5+、6.x、7.x、8.x、9.x和10.x将通知发送到kChat通道

return KChatMessage::create()
    ->to("123456789")
    ->content('The backup of your application succeeded')
    ->commentTo('987654321');

内容

安装

您可以通过composer安装此包

composer require karacweb/kchat-notification-channel

接下来,如果您使用的是不带自动发现的Laravel,请将服务提供程序添加到config/app.php

'providers' => [
    // ...
    NotificationChannels\KChat\KChatServiceProvider::class,
],

设置kChat服务

  • 创建具有范围kchat的令牌
  • 检索您的kChat实例的URL,它应该类似于https://your-team.kchat.infomaniak.com
  • 将令牌和您的kChat基本URL粘贴到您的config/services.php文件中
    // config/services.php
    'infomaniak_kchat' => [
        'token' => 'YOUR_API_TOKEN',
        'base_url' => 'https://your-team.kchat.infomaniak.com' 
    ],
    

使用方法

现在您可以在通知中的via()方法中使用该通道

use Illuminate\Notifications\Notification;
use NotificationChannels\KChat\KChatChannel;
use NotificationChannels\KChat\KChatMessage;

class BackupSucceeded extends Notification
{
    public function via($notifiable)
    {
        return [KChatChannel::class];
    }

    public function toKChat($notifiable)
    {
        return KChatMessage::create()
            ->to("123456789")
            ->content('The backup of your application succeeded')
            ->commentTo('987654321'); // A post ID you wish to respond to
    }
}

除了使用to($channel_id)方法指定通道ID之外,您还可以在您的Notifiable模型中添加routeNotificationForKChat方法。此方法需要返回通道ID。

public function routeNotificationForKChat(Notification $notification)
{
    return '123456789';
}

可用的消息方法

  • to(string $channel_id):发送消息的通道。
  • content(string $content):消息的内容(支持Markdown)。
  • commentTo(string $post_id):您希望回复的帖子ID。

检索kChat通道ID

Retrieve the kChat channel ID

在消息中使用Markdown

// app/Notifications/InterestingNotification.php
public function toKChat($notifiable)
{
    return KChatMessage::create()
        ->to("123456789")
        ->content(view('notificationTemplate', [
            'variable' => 'ABC',
        ]));
}
// resources/views/notificationTemplate.blade.php
** ✅ Bold title **

Lorem ipsum *dolor* sit amet, ~~consectetur~~ adipiscing elit...

Variable content {{ $variable }}

变更日志

有关最近更改的更多信息,请参阅变更日志

测试

$ composer test

安全

如果您发现任何安全相关的问题,请通过info@karac.ch而不是使用问题跟踪器来发送电子邮件。

贡献

有关详细信息,请参阅贡献

致谢

许可

MIT许可(MIT)。有关更多信息,请参阅许可文件