The middleware chain is in charge of pre-processing incoming and outgoing messages. A middleware can for example translate a message on receiving and before sending. Most middleware are registered by the modules. For example, the Analytics module keeps track of the messages with the help of an incoming and an outgoing middleware.
- Source:
Methods
(static) register(middleware)
Registers a new middleware into the chain
- Source:
Parameters:
Name | Type | Description |
---|---|---|
middleware |
Middleware.Middleware
|
The middleware to register |
(static) sendIncoming(event)
Sends an incoming event (from the user to the bot)
- Source:
Parameters:
Name | Type | Description |
---|---|---|
event |
Middleware.Event
|
An event object |
(static) sendOutgoing(event)
Sends an outgoing event (from the bot to the user)
- Source:
Parameters:
Name | Type | Description |
---|---|---|
event |
Middleware.Event
|
An event object |
Type Definitions
Event
Properties:
Name | Type | Description |
---|---|---|
platform |
String
|
|
text |
String
|
|
raw |
object
|
|
type |
String
|
- Source:
Type:
-
Object
Handler(event, next)
- Source:
Parameters:
Name | Type | Description |
---|---|---|
event |
Object
|
The incoming or outgoing event |
next |
function
|
Call this function to make the event flow to the next middleware (see example) |
Middleware
Properties:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
name |
String
|
Unique name of the middleware |
||
handler |
Middleware.Handler
|
The handler function |
||
type |
String
|
Can be 'incoming' or 'outgoing' |
||
order |
Number
|
A positive number from 0 (before everything else) to 1000 (last middleware) |
||
enabled |
Boolean
|
<optional> |
true | Whether this middleware is enabled or not |
- Source:
Type:
-
Object