Skip to content
Seongnoh Sean Yi edited this page Jun 18, 2024 · 11 revisions

MMM-TelegramBot

TelegramBot module for MagicMirror

[Screen Shot]

Feature

  • You can remote-control your MagicMirror and modules within Telegram.
  • The Bot is implemented in this module thus you don't need to manage antoher daemon.
  • Other module developers can add their commands easily. (See the Wiki : https://github.com/eouia/MMM-TelegramBot/wiki )

Installation

1) Create 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.

2) Install Module

  1. In your mirror, open terminal and execute below;
cd ~/MagicMirror/modules
git clone https://github.com/eouia/MMM-TelegramBot.git
cd modules/MMM-TelegramBot
npm install

3) Configuration (Pre-use)

  1. Open .env file in your MMM-TelegramBot module directory. Or copy it from env.example. Then, put your API Key into it.
# .env
TELEGRAM_API_KEY=110201543:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw
  1. Open config.js of MagicMirror, add these;
{
  module: 'MMM-TelegramBot',
  config: {
    allowedUser : ['<your Telegram username without @>'], // This is NOT the username of bot.
  }
},

  1. restart your MagicMirror.

4) 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.

5) Register admin Chat id

  1. Open config.js again.
{
  module: 'MMM-TelegramBot',
  config: {
    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!

Commands list

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

Currently supported commands and modules are below;

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
alert - Show alert message on your `MagicMirror`
reboot - Reboot `MagicMirror`
shutdown - Shutdown `MagicMirror`
dismissalert - Remove Alert from Mirror
favor - Load favourite commands as keyboard
recent - Load recent used commands as keyboard
resetkeyboard - Reset Kyeboard
shell - Execute shell script/command directly
notification - Send custom notification
screenshot - Take a screenshot of MagicMirror

UPDATED 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.

Please add command /XXX for module XXXX...

Okay, maybe I can add those commands with ease. But I think this module as some kind of interface between user and module. Therefore the best is that the module supports Telegram commands by itself. It is not difficult, really. So, you'd better ask the module developer to support this feature.

By example; I COULD add /screen on and /screen off in TelegramBot. But I didn't. Because there are so many modules which turn the screen on and off, So I think those commands SHOULD belong to those modules.

If you get a rejection from module developer, I'll consider implementing that command in TelegramBot.

UPDATED However I made a module for default system controls. Use MMM-Tools.

UPDATED Since 1.1.0 I added the feature of custom command by user's own. Now you don't need to request command to module developer. Read **Custom Command

Why my TelegramBot doesn't react to my command?

First, your Mirror should be running on.

Second, Your Mirror should have no error or exception on running currently.

Third, Some commands might not react. Ask the command provider.

Last, If your TelegramBot was out of works(when your mirror was powered off, or your mirror was halted by error...), the old commands are not executed. Because it could make unintended execution. So TelegramBot will ignore old commands.