benjick / meteor-telegram-bot

Telegram bot plugin for Meteor
24 stars 15 forks source link

Multiple functions in addListener #8

Closed sspatank closed 8 years ago

sspatank commented 8 years ago

Hi, I am new to javascript and meteor.

I am trying put in two run functions in the addListener callback function. However, the chat only returns the first run function. In the code below, it only returns 1 and not 2 when I type in \test hello.

What am I doing wrong?

if (Meteor.isServer) {
  Meteor.startup(function () {
    // set our token
    TelegramBot.token = '11222334MyPersonalTokennz;slkjfewfrj';
    TelegramBot.start(); // start the bot
    // add a listener for '/test'
    TelegramBot.addListener('/test', function(command) { 
    // command will contain the entire command in an array where command[0] is the command. 
    // In this case '/test'. Each argument will follow.
      if(!command[1]) { // if no arguments
        return false
        // if you return false the bot wont answer
      } else {
        return "1"
        return "2"
      }
      // command[1] will be the first argument, command[2] the second etc
      // below the bot will reply with 'test: hi' if you sent him /test hi
    });
  });
}
benjick commented 8 years ago

A function ends when you do return.

You can try TelegramBot.method('sendMessage', { chat_id: chatId, text: message }) and run that two times

sspatank commented 8 years ago

Yes. I just figured that out and was about to close the issue. Thank you though!

benjick commented 8 years ago

No problem. Let me know if you're missing any features