botgram / shell-bot

:robot: Telegram bot that executes commands and sends the live output
GNU General Public License v3.0
787 stars 493 forks source link

Help to understand callback #68

Open Sozik87 opened 7 months ago

Sozik87 commented 7 months ago

Hello friends! :)

Thank you for this project!

Please help me, I can't think of a solution to run the /run docker ps command by button.

bot.command("test_command", function (msg, reply, next) {
  reply.inlineKeyboard([
    [
      { text: "Run docker ps", callback_data: "1" }
    ]
  ]);

  reply.markdown("Please, choose an action");
});

bot.callback((query, next)=>{
        if (query.data === '1') {
                reply.text('/run docker ps').forceReply();
        } else {
                return next()
        }
});

I can't figure out how exactly to write bot.callback so(or something else) that the /run docker ps command (or all other commands with /run) will be executed when the button is pressed in the terminal.

Unfortunately I am very weak with JS.

P.S I was able to figure out how to use /setcommands through BotFather, but I would like to use the button.