PHP code example of rias / craft-telegram-notification-channel
1. Go to this page and download the library: Download rias/craft-telegram-notification-channel library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rias / craft-telegram-notification-channel example snippets
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
}