MMRIZE / MMM-TelegramBot

TelegramBot module for remote-controlling MagicMirror
MIT License
26 stars 8 forks source link

Registering new command not showing up #22

Closed ghost closed 5 years ago

ghost commented 5 years ago

I tried to add a new customs command, but it doest not show up on the list when running /command on Telegram:

Following code:

getCommands : function(register) {
        if (register.constructor.name == 'TelegramBotCommandRegister') {
            register.add({
                command: 'relay',
                description: 'You can trigger a relay with that command',
                callback: 'command_relay',
                args_pattern : [/^on|off/i],
                args_mapping : ['onoff']
            })
        }
        if (register.constructor.name == 'AssistantCommandRegister') {
          register.add({
            command: 'turn relay :onoff(on|off)',
            description: 'Turn relay on or off.',
            callback: 'cmd_relay',
          })
        }
    },

    command_relay : function(command, handler){
        if (!handler.args) {
            handler.reply('TEXT','No arguments given',{parse_mode:'Markdown'})
        } else {
            if(handler.args['onoff']){
                if (handler.args['onoff'].toLowerCase() == "on") {
                  handler.reply('TEXT', "Triggering relay on")
                  this.sendSocketNotification('relay_on')
                }
                if (handler.args['onoff'].toLowerCase() == "off") {
                  handler.reply('TEXT', "Triggering relay off")
                  this.sendSocketNotification('relay_off')
                }
              } else {
                handler.reply('TEXT','No arguments given',{parse_mode:'Markdown'})
              }
        },
    },

Any ideas?

ghost commented 5 years ago

2nd attempt as well not working:

    getCommands : function(commander) {
        commander.add({
            command: 'relay',
            description: 'You can trigger a relay with that command',
            callback: 'command_relay',
            args_pattern : [/^on|off/i],
            args_mapping : ['onoff']
        })
    },
ghost commented 5 years ago

This is based on a fork: https://github.com/FatTony123/MMM-PIR-Sensor

eouia commented 5 years ago

Sorry for really late reply. I probably missed this issue. Have you still got this problem?

ghost commented 5 years ago

no worries, but i did not follow up on this either. would need to reconfigure my mirror accordingly.

On Tue, 10 Sep 2019, 19:13 Seongnoh Sean Yi, notifications@github.com wrote:

Sorry for really late reply. I probably missed this issue. Have you still got this problem?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/eouia/MMM-TelegramBot/issues/22?email_source=notifications&email_token=AAVMNUHXWWD2FRUDHMAC2NDQI7ISRA5CNFSM4GSTV5JKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6L22YA#issuecomment-530034016, or mute the thread https://github.com/notifications/unsubscribe-auth/AAVMNUBS2QDJIT4G325SICDQI7ISRANCNFSM4GSTV5JA .

eouia commented 5 years ago

Feel free to post a new issue when you need.