# Router ## [](#command) router.command() Registers some middleware that will only be executed when the bot received a message that starts with the specifid command. - **Type** ```ts 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 ```js bot.command('hello', () => {}) ``` - **References** [`Handler`](#Handler) ## [](#hears) router.hears() Registers some middleware(s) that will only be executed when the message contains some text specified by `pattern` - **Type** ```ts interface Router { hears(pattern: Pattern, ...handlers: Handler[]): void; } ``` - **Example** This route will match butterfly and dragonfly, but not butterflyman, dragonflyman, and so on. ```js bot.hears(/.*fly$/, () => {}) ``` - **References** [`Pattern`](#Pattern), [`Handler`](#Handler) ## [](#use) router.use() Registers some middleware - **Type** ```ts interface Router { use(...handlers: Handler[]): void; } ``` - **References** [`Handler`](#Handler) ## [](#Handler) Handler - **Type** ```ts type Handler = (usr: User, tx: Transaction, next: NextFunction) => void; interface Transaction {} type NextFunction = (error: Error) => void; ``` - **References** [`User`](User.md#User) ## [](#Pattern) Pattern - **Type** ```ts type Pattern = Pattern[] | RegExp | string; ``` - **References** [`Pattern`](#Pattern)