benjick / meteor-telegram-bot

Telegram bot plugin for Meteor
24 stars 15 forks source link

Listening to user response #13

Closed alexivanovvv closed 8 years ago

alexivanovvv commented 8 years ago

Hi again, this might be a really stupid question, but how do I listen to user response? E.g., after sending a message with, say a riddle ('What is 3+5?'), the bot awaits for user response ('e.g. 8 - or anything else'), and then compares the response with whatever instructions the bot has. I see how I set up specific listeners, but I'm not quite sure I can grasp how to do this kind of interaction from the code samples provided. Would you help with some examples?

goooseman commented 8 years ago

I believe you should use addEventListener for this too.

TelegramBot.addListener('8', function (command, username, original) {
    return 'You are right!!';
  });
alexivanovvv commented 8 years ago

True that. This works for pre-defined answers just fine. However, what do I do if I listen to user inputing their name, for example?

-A Sent from a typo machine

On Fri, Feb 19, 2016 at 10:43 AM, Alexander Gusev notifications@github.com wrote:

I believe you should use addEventListener for this too.

TelegramBot.addListener('8', function (command, username, original) {
    return 'You are right!!';
  });

Reply to this email directly or view it on GitHub: https://github.com/benjick/meteor-telegram-bot/issues/13#issuecomment-186140793

benjick commented 8 years ago

Interesting, never tried this way. Is this what you want? https://core.telegram.org/bots/api#forcereply

alexivanovvv commented 8 years ago

Hm, I'm really not sure how this work. I didn't find any examples with ForceReply so it's hard to say. I'd like to be able to handle a scenario like this (and be able to capture user input):

User: /start 
Bot: Hey, what's your name? 
User: Max 
Bot: Cool. What's your height? 
User: 5' 9” 
Bot: Great. Could you upload your most recent picture? 
User (uploads picture)

…etc. Is there a way to handle such conversation (and store the inputs) with this wrapper? Thanks!

benjick commented 8 years ago

Rewriting it all now, will see if I can find a good way On Feb 19, 2016 21:20, "epleplepl" notifications@github.com wrote:

Hm, I'm really not sure how this work. I didn't find any examples with ForceReply so it's hard to say. I'd like to be able to handle a scenario like this (and be able to capture user input): User: /start Bot: Hey, what's your name? User: Max Bot: Cool. What's your height? User: 5' 9” Bot: Great. Could you upload your most recent picture? User (uploads picture) …etc. Is there a way to handle such conversation (and store the inputs) with this wrapper? Thanks!

On Fri, Feb 19, 2016 at 6:45 PM, Max Malm < notifications@github.com > wrote: Interesting, never tried this way. Is this what you want? https://core.telegram.org/ bots/api#forcereply

— Reply to this email directly or view it on GitHub .

— Reply to this email directly or view it on GitHub https://github.com/benjick/meteor-telegram-bot/issues/13#issuecomment-186387916 .

shrmnk commented 8 years ago

16

That should resolve what you need

shrmnk commented 8 years ago

https://github.com/benjick/meteor-telegram-bot/tree/conversations

In your case, it would be something like this:

TelegramBot.addListener('/start', function(command, username, messageraw) {
    TelegramBot.startConversation(username, messageraw.chat.id, function(username, message, chat_id) {
        var obj = _.find(TelegramBot.conversations[chat_id], obj => obj.username == username);
        console.log('Conversation Status: ' + obj);
        switch(obj.stage) {
            case 0:
                TelegramBot.send('Cool. What\'s your height?', chat_id);
                obj.personName = message;
                obj.stage++;
                break;

            case 1:
                TelegramBot.send('Great. Could you upload your most recent picture?', chat_id);
                obj.personHeight = message;
                break;
        }
    }, {stage: 0, persnName: "", personHeight: ""} );
    return "Hey, what's your name?";
});
alexivanovvv commented 8 years ago

Thank you!

I will give it a try--

Alex Ivanov

On Sun, 20 Mar 2016 at 15:32 Sherman K

< mailto:Sherman K notifications@github.com

wrote:

Closed https://github.com/benjick/meteor-telegram-bot/issues/13 via https://github.com/benjick/meteor-telegram-bot/pull/18 .

You are receiving this because you authored the thread.

Reply to this email directly or https://github.com/benjick/meteor-telegram-bot/issues/13#event-596275153 https://github.com/benjick/meteor-telegram-bot/issues/13#event-596275153