EXT‐TelegramBot - bugsounet/MMM-Bugsounet GitHub Wiki

TelegramBot plugin for MMM-Bugsounet

You can remote-control plugins within Telegram.
The Bot is implemented in this plugin thus you don't need to manage antoher daemon.
Other module developers can add their commands easily.

Screenshot

Create your Telegram Bot

Ref : https://core.telegram.org/bots#6-botfather

  1. Open your browser in Desktop PC(or your mirror or your phone, anywhere) and Navigate to https://telegram.me/botfather
  2. Click Send Message button, then your telegram will be opened in your phone or your PC which Telegram is already installed on. Meet BotFather.
  3. Command /newbot, give a name to the bot created, give an username. username should end with bot. (e.g. MyMagicMirrorBot or mystupidslave-bot... )
  4. After created, you can get API Token. It looks like 110201543:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw. Remember that.
  5. Read messages from BotFather. You can find your bot and change chat room of your Bot. Type anything, but your bot will not react yet.

Module installation

In your mirror, open terminal and execute below

cd ~/MagicMirror/modules/MMM-Bugsounet
npm run setup:EXT-TelegramBot

Configuration (Pre-use)

  1. Open config.js of MagicMirror, add this:
{
  module: 'MMM-Bugsounet/EXTs/EXT-TelegramBot',
  position: 'top_center',
  config: {
    telegramAPIKey : '<your Telegram API Token>',
    allowedUser : ['<your Telegram username without @>'], // This is NOT the username of bot.
  }
},
  1. restart your MagicMirror.

Back to your Bot and test

  1. Back to the chat room with your Bot in Telegram, try /help or /commands. Your bot will react!
  2. Now,try /mychatid. This command will show the id of this chat room. The chat id looks like 12345678. Remember that. We will use this id for admin.

Register admin Chat id in config

  1. Open config.js again.
{
  module: 'MMM-Bugsounet/EXTs/EXT-TelegramBot',
  position: 'top_center',
  config: {
    telegramAPIKey : '<your Telegram API Token>',
    allowedUser : ['<your Telegram username without @>'],
    adminChatId : <your admin chat id>,
  }
},
  1. Restart your MagicMirror.
  2. You can get welcome message in your admin chat room. Now you can use Bot!

Configuration options

{
  module: 'MMM-Bugsounet/EXTs/EXT-TelegramBot',
  position: "top_left",
  config: {
    debug: false,
    telegramAPIKey : '<your Telegram API Token>',
    allowedUser : ['<your Telegram username without @>'],
    adminChatId : <your admin chat id>,
    useWelcomeMessage: false,
    favourites:["/commands", "/modules", "/hideall", "/showall"],
    detailOption: {},
    telecast: null, // true or chat_id
    telecastLife: 1000 * 60 * 60 * 6,
    telecastLimit: 5,
    telecastHideOverflow: true,
    commandAllowed: {},
    useSoundNotification: true,
    dateFormat: "DD-MM-YYYY HH:mm:ss",
    telecastContainer: 300,
    screenshotTool: "grim"
  }
},
Option Description Type Defaut
debug Display debug logs. Boolean false
useWelcomeMessage Display Wake-up message Boolean true
favourites Put your favourite commands to telegram keyboard. They will be loaded by command /favor Array ["/commands", "/modules", "/hideall", "/showall"]
detailOption For Developer/Expert. Set detail options for node-telegram-bot-api constructor Object {}
telecast null for disallowance.
true for activating by only /telecast command.
"{chatId}" for telecasting whole chats in specific chat room.
String null
telecastLife ms of lifetime of chat. After this time, chat will be disappeared and cache data also be removed. Number 1000 * 60 * 60 * 6
telecastLimit How many chats be displayed. Older chat will be shifted by new one. Number 5
telecastHideOverflow on true, when overflowed old chats will be hidden. (defined by CSS) If you have touch/mouse interface, you can scroll hidden area.
Telecast might have different look by position of module. on .bar, .middle.center, .third region, telecastLimit:1 would be better.
Or modify CSS by yourself.
Boolean true
commandAllowed Command would be executable by only specific users.
Others, even in allowedUser cannot use it.
Object {}
useSoundNotification Use Official notification sound, on incomming messages Boolean true
dateFormat Your prefered date format String "DD-MM-YYYY HH:mm:ss"
telecastContainer Force le with of the telecast container in px. Default: 300, mini: 200, max : 1000 Number 300
screenshotTool Set screenshot tool to use for /screenshot command
grim: This tool is designed for Wayland or LabWc compositor using (default)
scrot: This tool is designed for X11 compositor using
String "grim"

commandAllowed configuration Helping

In this example:

  • me and john can execute /telecast command, but jane cannot.
  • only me can execute /mychatid command. The others can't.
  • jane can execute all other commands except /telecast and /mychatid.
  • "modules":[], will be ignored. It does not mean "Nobody can use this command.
allowedUser: ["me", "john", "jane"],
commandAllowed: {
  "telecast": ["me", "john"],
  "mychatid": ["me"],
  "modules": [],
}

Commands List

Try /commands in your TelegramBot.
Supported commands are dependent on which module you've installed.

Currently default supported commands and modules are below:

Command Description
help Show description of commands.
commands List of available commands.
modules List of current installed modules.
mychatid Show chatId of this chat room.
allowed List of allowed users.
allowuser Allow user temporally.
hideall Hide All modules.
showall Show All modules.
hide Hide a module.
show Show a module.
favor Load favourite commands as keyboard.
recent Load recent used commands as keyboard.
resetkeyboard Reset Kyeboard.
notification Send custom notification.
screenshot Take a screenshot of MagicMirror².

You can use the result of /commands for /setcommands of BotFather.

  • For naming commands, use lower case letters.
  • For description, First sentence or line-break should happen in 32 chars.

Telecast

  • send specific chat by command /telecast (See Use commands)
  • telecasting chats from specific chat room(group) to MagicMirror without command. (See Telecast chats)

telecast chats

  • To enable telecasting chats from room(group) without command, you need 2 things before.
    1. Your telegramBot needs privacy:disabled. You can setup privacy mode of bot with @botfather.
    2. You should know chatId of target chat room and your bot is a member of that group. To get chatId, use /mychatid command in that room after inviting bot.
  • Be careful to use. Bot could obtain private user information (name, profile photo, username and conversations), so you should know what you are doing. Explain to members and get consents before using. All rights and responsibilites are yours.
  • All photos and text messages(except reply to bots) from human members will be telecasted.
  • To use this feature, set telecast: {chatId}.
telecast: "-1111111", // "-1111111" will be chatId of target room.

Use commands

  • Instead, a user can explicitly telecast his message with command /telecast.
    For example; /telecast Kids! Time to go to bed! will telecast the message "Kids! Time to go to bed".
telecast: true,
  • To send a photo, write caption with command /telecast.

I don't want to use telecast

telecast: null, // or `false`

Looks

If you are using this on *_bar, *_third or middle_center position: telecastLimit:1 would be recommended.

You can override CSS in your css/custom.css

⚠️ **GitHub.com Fallback** ⚠️