Naltox / telegram-node-bot

Node module for creating Telegram bots.
MIT License
721 stars 143 forks source link

Retrieving parameters from user input #130

Closed MikhailMS closed 7 years ago

MikhailMS commented 7 years ago

In previous version it was possible for user to send search parameters along with bot command, like "/search :parameter1 :parameter2" etc. So it would look like this in the code

get routes() {
        return {
            '/search :parameter1 :parameter2': 'searchHandler'
        }
    }
}

tg.router
    .when(['/sum :parameter1 :parameter2'], new SearchController())

However with current version it throws an error and I cannot yet see how to solve this issue. What is the workaround at the moment?

jokame commented 7 years ago

How did you solve? What was the solution?

MikhailMS commented 7 years ago

@jokame The best way would be to implement this functionality yourself, however you can use RegexpCommand to do it - and then you just need to work with string which is, in fact, user's message. So for example, your RegexpCommand would be triggered on 'plot' word, so if user send message in the form 'plot circle', all you need to do is get this message in your controller ($.message.string) and get rid of 'plot' word. It works fine for 1 parameter, but u can use delimiters, like ',' to process more.