michtio / craft-telegram-notification-channel

A Telegram notification channel for the Craft Notifications plugin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

icon

Latest Version Quality Score StyleCI Total Downloads

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!

Beerpay

Requirements

Installation

To install the plugin, follow these instructions.

  1. Open your terminal and go to your Craft project:

     cd /path/to/project
    
  2. Then tell Composer to load the plugin:

     composer require rias/craft-telegram-notification-channel
    
  3. 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:

Message screenshot

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

About

A Telegram notification channel for the Craft Notifications plugin

License:MIT License


Languages

Language:PHP 95.3%Language:HTML 4.7%