-
-
Notifications
You must be signed in to change notification settings - Fork 0
Router
martiliones edited this page Jun 12, 2023
·
1 revision
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
commandbot.command('hello', () => {})
-
References
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
Registers some middleware
-
Type
interface Router { use(...handlers: Handler[]): void; }
-
References
-
Type
type Handler = (usr: User, tx: Transaction, next: NextFunction) => void; interface Transaction {} type NextFunction = (error: Error) => void;
-
References
-
Type
type Pattern = Pattern[] | RegExp | string;
-
References