rias/craft-telegram-notification-channel

Craft Notifications 插件的 Telegram 通知频道

1.0.1 2018-05-21 08:40 UTC

README

icon

Latest Version Quality Score StyleCI Total Downloads

Craft Notifications 的 Telegram 通知频道插件

Craft Notifications 插件提供 Telegram 通知频道

支持开源。买杯啤酒。

此插件受 MIT 许可证保护,这意味着它是一个完全免费的开源软件,您可以使用它做任何您想做的事情。如果您正在使用它并希望支持开发,请在 Beerpay 上为我买杯啤酒!

Beerpay

要求

安装

要安装插件,请按照以下说明操作。

  1. 打开您的终端并进入您的 Craft 项目

     cd /path/to/project
    
  2. 然后告诉 Composer 加载插件

     composer require rias/craft-telegram-notification-channel
    
  3. 在控制面板中,转到设置 → 插件,并点击 Telegram 通知频道旁边的“安装”按钮。

设置您的 Telegram Bot

@BotFather 交谈并生成一个 Bot API Token。

然后,通过插件设置或通过将 config.php 文件复制到 config/telegram-notification-channel.php 并在那里设置 token 来配置您的 Telegram Bot API Token。

使用 Telegram 通知频道

您现在可以向 via() 函数中添加 telegram。您还必须提供一个 toTelegram 函数来创建您的消息。

use rias\notifications\models\Notification;
use rias\telegramnotificationchannel\models\TelegramMessage;

/**
 * Get the notification's delivery channels.
 *
 * @return array
 */
public function via()
{
    return ['telegram' => '<YOUR_USER_ID/CHAT_ID>'];
}

public function toTelegram()
{
    $blogpost = $this->event->sender;

    return TelegramMessage::create()
        //->to($this->user->telegram_user_id) // You can provide a different user or chat to send to here.
        ->content("A new blogpost has been added:\n*{$blogpost->title}*") // Markdown supported.
        ->button('View blogpost', $blogpost->url); // Inline Button
}

这是上述通知在 Telegram 消息应用中的截图预览

Message screenshot

可用的消息方法

  • to($chatId): (整数) 收件人的聊天 ID 或用户 ID。
  • content(''): (字符串) 通知消息,支持 markdown。有关支持的 markdown 风格的更多信息,请查看这些文档。
  • button($text, $url): (字符串) 添加内联“调用操作”按钮。您可以添加任意多的按钮,并将它们以两行为一组放置。
  • options([]): (数组) 允许您添加或覆盖 sendMessage 负载(一个内部使用的 Telegram Bot API 方法)。有关支持的参数的更多信息,请查看这些文档。

致谢

Rias 提供