, (*1)
, (*2)
Telegram Notification Channel plugin for Craft Notifications
A Telegram notification channel for the Craft Notifications plugin, (*3)
Support Open Source. Buy beer.
This plugin is licensed under a MIT license, which means that it's completely free open source software, and you can use it for whatever and however you wish. If you're using it and want to support the development, buy me a beer over at Beerpay!, (*4)
, (*5)
Requirements
Installation
To install the plugin, follow these instructions., (*6)
-
Open your terminal and go to your Craft project:, (*7)
cd /path/to/project
-
Then tell Composer to load the plugin:, (*8)
composer require rias/craft-telegram-notification-channel
-
In the Control Panel, go to Settings → Plugins and click the “Install” button for Telegram Notification Channel., (*9)
Setting up your Telegram Bot
Talk to @BotFather and generate a Bot API Token., (*10)
Then, configure your Telegram Bot API Token either through the plugin settings or by copying the config.php
file to config/telegram-notification-channel.php
and setting the token
there., (*11)
Using the Telegram Notification Channel
You can now add telegram
to your via()
function. You will also have to provide a toTelegram
function to create your message., (*12)
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
}
Here's a screenshot preview of the above notification on Telegram Messenger:, (*13)
, (*14)
Available message methods
-
to($chatId)
: (integer) Recipient's chat id or user id.
-
content('')
: (string) Notification message, supports markdown. For more information on supported markdown styles, check out these docs.
-
button($text, $url)
: (string) Adds an inline "Call to Action" button. You can add as many as you want and they'll be placed 2 in a row.
-
options([])
: (array) Allows you to add additional or override sendMessage payload (A Telegram Bot API method used to send message internally). For more information on supported parameters, check out these docs.
Credits
Brought to you by Rias, (*15)