benjick / meteor-telegram-bot

Telegram bot plugin for Meteor
24 stars 15 forks source link

how to getUpdates? #2

Closed dcsan closed 8 years ago

dcsan commented 9 years ago

thanks for wrapping this up...

your example shows how to poll for slash commands, but how do i receive all text, esp via long polling?

ref https://core.telegram.org/bots/api#getupdates

dcsan commented 9 years ago

also the slash commands don't seem to return a chatID, so i cant identify a chat to send a message to, unless its replying to an incoming message.

dcsan commented 9 years ago

ok i see you're calling method("getUpdates" internally

https://github.com/benjick/meteor-telegram-bot/blob/master/telegram-bot.js#L19

and you have something setup for a catchAll

    if(msg = item.message.text) {
            msg = TelegramBot.parseCommandString(msg)
            var obj = _.find(TelegramBot.triggers, function(obj) { return obj.command == msg[0] })
            if(obj) {
                TelegramBot.send(obj.callback(msg, from, item.message), chatId)
            }
        }
        else {
            if(typeof(TelegramBot.catchAll) === 'function') {
                TelegramBot.catchAll(item);
            }
        }

but it looks like the catchAll won't run for just the case where there's no command found - it will only run if if(msg = item.message.text) { evals to false.

so there's no way to just listen for a command with a message.text?

benjick commented 9 years ago

Hey

I guess catchAll should be named as catchOthers, because it's catching everything that's not a text message. It's kinda shitty implemented right now so I wouldn't use it

benjick commented 8 years ago

Removed the use of catchAll in the latest version