Custom Command
Seongnoh Sean Yi edited this page Feb 27, 2020
·
2 revisions
Since v1.1.0
, a normal user can add his custom command in the configuration without modifying source(to add .getCommands()
) by himself, FINALLY!!
...
customCommands: [
{
command: "test",
callback: (command, handler) => {
handler.reply("TEXT", "This is test command!")
}
},
{
command: "detailnews",
description: "For detail of current news article"
callback: (command, handler, self) => {
self.sendNotification("ARTICLE_MORE_DETAILS")
handler.reply("TEXT", "Yes, sir!")
}
},
],
...
This example will register two commands - /test
and /detailnews
.
Basically, the structure of custom command is the same as the existing command. Read the How to add commands before.
{
command, /** REQUIRED **/
callback, /** REQUIRED **/
description, /** OPTIONAL **/
args_pattern, /** OPTIONAL **/
args_mapping, /** OPTIONAL **/
}
But callback
is slightly different. You need to assign a callback function directly.
callback: ([command[, handler[, thisModule]]]) => {
/** Do what you need **/
}
thisModule
will be instance of MMM-TelegramBot
module. When you need to handle module MMM-TelegramBot
directly, use this.
Or you can get specific modules like this.
{
command: "hideallmodules",
callback: (command, handler) => {
MM.getModules().enumerate((m) => {
m.hide()
})
}
}
Read Guide for design command also.