Naltox / telegram-node-bot

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

regex route example? #108

Closed paOol closed 8 years ago

paOol commented 8 years ago

the file shows this in the comments.

    *
     * @param {string|RegExp|Array<string, RegExp>} commands

however, I'm not sure what the regex should look like in routes.

I've tried

  get routes() {
      return { 
          ['/gif ', '/\/gif (.+)/i']: 'returnGif'
      }
  }

and

  get routes() {
      return { 
          '/\/gif (.+)/i': 'returnGif'
      }
  }

I am trying to do "/gif :searchterm" but that breaks if the query is more than one word.

paOol commented 8 years ago

solved

  get routes() {
      return { 
          [/\/gif (.+)/i]: 'returnGif'
      }
  }

tg.router 
    .when([/\/gif (.+)/i], new MediaController())