rias / craft-telegram-notification-channel
A Telegram notification channel for the Craft Notifications plugin
Installs: 281
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 2
Type:craft-plugin
Requires
- craftcms/cms: ^3.0.0-RC1
- rias/craft-notifications: ^1.0
This package is auto-updated.
Last update: 2024-12-07 21:59:15 UTC
README
Telegram Notification Channel plugin for Craft Notifications
A Telegram notification channel for the Craft Notifications plugin
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!
Requirements
- Make sure you have Craft Notifications installed
Installation
To install the plugin, follow these instructions.
-
Open your terminal and go to your Craft project:
cd /path/to/project
-
Then tell Composer to load the plugin:
composer require rias/craft-telegram-notification-channel
-
In the Control Panel, go to Settings → Plugins and click the “Install” button for Telegram Notification Channel.
Setting up your Telegram Bot
Talk to @BotFather and generate a Bot API Token.
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.
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.
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:
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