MMRIZE / MMM-TelegramBot

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

How to register a name for a command that has a NOTIFICATION event ? #25

Closed azro352 closed 5 years ago

azro352 commented 5 years ago

I just learned how to use Telegram and MMM-TelegramBot, it works good, so I tried to use it for the newsfeed module (the default one) as it has some notification availables : newsfeed notif

In the file newsfeed/newsfeed.js I add (line 43) the following code :

getCommands: function(commander){
    return [{
        command: "ARTICLE_NEXT"
    }]
}

So when I use /ARTICLE_NEXT it works, but how to change the name of the command ? Like /infonext triggers ARTICLE_NEXT notif ?

Edit : I tried :

getCommands: function(commander){
    return [{
        command: "infonext",
        callback : "ARTICLE_NEXT"
    }]
},

But i got ""that command is not registered for this one above

, and

getCommands: function(commander){
    return [{
        command: "infonext",
        callback : "command_infonext"
    }]
},
command_infonext: function(command, handler){
    this.sendNotification("ARTICLE_NEXT")
}

But nothing happen :/

eouia commented 5 years ago

I think it should be working. "that command is not registered" is still happening?

azro352 commented 5 years ago

Yes :/

eouia commented 5 years ago

Anyway, this.sendNotification(ARTICLE_NEXT) will not delivered to the module itself which emit that notification. You can use receivedNotification instead.

Back to main issue;

getCommands: function(commander){
    return [{
        command: "ARTICLE_NEXT'
    })
}

If this command be registered

getCommands: function(commander){
    return [{
        command: "infonext',
        callback : "command_infonext'
    })
},
command_infonext: function(command, handler){
    this.sendNotification("ARTICLE_NEXT")
}

this should be registered also. (Even the command be failed to executed)

eouia commented 5 years ago

But... I find the syntax error now.

return [{
        command: "ARTICLE_NEXT'
    }) //<--

It should be ], not )

azro352 commented 5 years ago

I’ve edited :

The solution would be to put the code from the “ifs” is notificationreceived in methods, to be accessible from inside this js file

eouia commented 5 years ago

You can use this.receivedNotification("ARTICLE_NEXT", null, null) instead sendNotification inside of same module. It will work like "receiving notification from somewhere".

azro352 commented 5 years ago

Not working, nothing happen, and no reply from the handler :/I've add an issue in the newsfeed repo too

eouia commented 5 years ago

Show your full command_infonext

eouia commented 5 years ago

And See this also; https://github.com/eouia/MMM-News/blob/081fcb219b3bba459d5486b6e1836e8dc429e60e/MMM-News.js#L56-L103 I think receivedNotification was wrong. Sorry, I type with only my memory. notificationReceived will be right.

azro352 commented 5 years ago

It's simply the name of the function defined below notificationReceived : function(... :D


Final Solution :

getCommands: function(commander){
    return [{
        command: "infonext",
        callback : "cmd_next"
    }]
},
cmd_next: function(command, handler){
    this.notificationReceived("ARTICLE_NEXT")
    handler.reply("TEXT", "Next news shown")
}