Skip to content
martiliones edited this page Jun 12, 2023 · 1 revision

Router

router.command()

Registers some middleware that will only be executed when the bot received a message that starts with the specifid command.

  • Type

    interface Router {
      command(name: string, ...handlers: Handler[]): void;
    }
  • Details

    The commands must meet the following criteria:

    • The command must start with a forward slash character (/).
    • The command must be composed of one or more uppercase or lowercase letters.
    • The letters in the command may be separated by one underscore (_).
    • The command must end with a single letter.
  • Example

    The following route will match /hello command

    bot.command('hello', () => {})
  • References

    Handler

router.hears()

Registers some middleware(s) that will only be executed when the message contains some text specified by pattern

  • Type

    interface Router {
      hears(pattern: Pattern, ...handlers: Handler[]): void;
    }
  • Example

    This route will match butterfly and dragonfly, but not butterflyman, dragonflyman, and so on.

    bot.hears(/.*fly$/, () => {})
  • References

    Pattern, Handler

router.use()

Registers some middleware

  • Type

    interface Router {
      use(...handlers: Handler[]): void;
    }
  • References

    Handler

Handler

  • Type

    type Handler = (usr: User, tx: Transaction, next: NextFunction) => void;
    
    interface Transaction {}
    
    type NextFunction = (error: Error) => void;
  • References

    User

Pattern

  • Type

    type Pattern = Pattern[] | RegExp | string;
  • References

    Pattern

Clone this wiki locally