Integration with Telegram

Created on 7 May 2023, over 1 year ago
Updated 8 May 2023, over 1 year ago

Problem/Motivation

As the name suggests, integrating with Telegram would be a great feature to send notifications. Users would get instant and free delivery and a lot of addon options thanks to the Telegram Bot API.

Proposed resolution

Check the existing example integrations:

  1. Telega (drupal module to create Telegram Bots)
  2. Monolog (drupal module integrating monolog library) > Handler > TelegramBotHandler.php
  3. Telegram_bot module (only available on D7) that I could easily leverage with a Rules action (now would be ECA) to send a message (given a chat ID):
<?php

/**
 * Implements hook_rules_action_info() on behalf of the user module.
 */
function telegram_bot_notify_rules_action_info() {
  $defaults = array(
    'parameter' => array(
       'chat_id' => array(
         'type' => 'text',
         'label' => t('Telegram Chat ID'),
       ),
       'message' => array(
         'type' => 'text',
         'label' => t('Message to send'),
       ),
     ),
     'group' => t('Telegram Bot'),
  );
  $actions['telegram_bot_send'] = $defaults + array(
    'label' => t('Send message with Telegram Bot'),
    'base' => 'rules_action_telegram_bot_send',
  );
  return $actions;
}

/**
 * Action: Send a message to a chat with Telegram Bot.
 */
function rules_action_telegram_bot_send($chat_id, $message) {
  telegram_bot_api_request("sendMessage", ['chat_id' => $chat_id, "text" => $message]);
}

Remaining tasks

Given I'm a noob, I don't know yet what would be the best path to make this happen..

Feature request
Status

Active

Version

2.2

Component

Miscellaneous

Created by

🇮🇹Italy kopeboy Milan

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @kopeboy
  • 🇮🇹Italy kopeboy Milan

    I just found out a new D10 module which is similar to the D7 Telegram Bot I mentioned, which is Telegram API . Maybe check that instead :)

  • ivnish Kazakhstan

    Hi! I'm a developer of that module. Yes, It's very simple now. It's a drupal service with one function - send message to telegram bot. We can use it in any custom code. I don't know "Push Framework" module and can't help with integration. We need to ask maintainers of "Push Framework"

  • 🇩🇪Germany jurgenhaas Gottmadingen

    It would be great to get Telegram integration for Push Framework. It can be done easily by providing a channel plugin in the Telegram API module. That plugin needs to implement the \Drupal\push_framework\ChannelPluginInterface which only requires a couple of methods, and especially the send method will be the one that takes the message and actually sends it to Telegram through their API.

    You can find a number of other modules implementing that same interface at https://www.drupal.org/project/push_framework/ecosystem and use their plugins as a blueprint.

Production build 0.71.5 2024