Scenes conduct participation in dialogue. They use listeners to enter an audience into a new dialogue with the bot.
Once entered into a scene, the audience is engaged and isolated from global listeners. The bot will only respond to branches defined by dialogue in that scene. The scope of audience can be:
Kind: global class
string
Promise
boolean
Dialogue
boolean
Param | Type | Description | ||
---|---|---|---|---|
robot | Robot |
Hubot Robot instance | ||
[options] | Object |
Key/val options for config | ||
[options.scope] | string |
How to address participants: user(default) | room | direct |
[options.sendReplies] | boolean |
Toggle replying/sending (prefix message with “@user”) | ||
[key] | string |
Key name for this instance |
Example
let roomScene = new Scene(robot, { scope: 'room' })
Process incoming messages, re-route to dialogue for engaged participants.
Kind: instance method of Scene
Param | Type | Description |
---|---|---|
context | Object |
Passed through the middleware stack, with res |
next | function |
Called when all middleware is complete |
done | function |
Initial (final) completion callback |
Add listener that enters the audience into the scene with callback to add dialogue branches or process response as required.
Enter callback provides full middleware context, but for consistency with other listener callbacks, response is extracted and given as the first argument, full context is second.
Middleware may prevent callback, e.g. from Director if user denied access.
Kind: instance method of Scene
Param | Type | Description | |
---|---|---|---|
type | String |
The listener type: hear | respond |
regex | RegExp |
Matcher for listener (accepts string) | |
callback | function |
Called with response and middleware context after listener matched and scene entered |
Example
let scene = new Scene(robot, { scope: 'user' })
scene.listen('respond', /hello/, (res) => {
res.reply('you are now in a scene')
// add dialogue branches now...
})
Alias of Scene.listen with hear
as specified type.
Kind: instance method of Scene
Alias of Scene.listen with respond
as specified type.
Kind: instance method of Scene
string
Identify the source of a message relative to the scene scope.
Kind: instance method of Scene
Returns: string
- ID of room, user or composite
Param | Type | Description |
---|---|---|
res | Response |
Hubot Response object |
Add a function to the enter middleware stack, to continue or interrupt the pipeline. Called with:
Kind: instance method of Scene
Param | Type | Description |
---|---|---|
piece | function |
Pipeline function to add to the stack. |
Promise
Engage the participants in dialogue. A new Dialogue instance is created and all further messages from the audience in this scene’s scope will be passed to that dialogue, untill they are exited from the scene.
Would usually be invoked as the final piece of enter middleware, after stack execution is triggered by a scene listener but could be called directly to force audience into a scene unprompted.
Kind: instance method of Scene
Returns: Promise
- Resolves with callback called in next tick queue
Param | Type | Description |
---|---|---|
context | Object |
The final context after middleware completed |
context.response | Object |
The hubot response object |
context.participants | string |
Who is being entered to the scene |
[context.options] | Object |
Options object given to dialogue |
[context.arguments] | Array |
Additional arguments given to dialogue |
[done] | function |
Optional final callback after processed - given context |
boolean
Disengage participants from dialogue e.g. in case of timeout or error.
Kind: instance method of Scene
Returns: boolean
- Exit success (may fail if already disengaged)
Param | Type | Default | Description |
---|---|---|---|
res | Response |
Hubot Response object | |
[status] | string |
"unknown" |
Some context, for logs |
End all engaged dialogues.
Kind: instance method of Scene
Dialogue
Get the dialogue for engaged participants (relative to scene scope).
Kind: instance method of Scene
Returns: Dialogue
- Engaged dialogue instance
Param | Type | Description |
---|---|---|
participants | string |
ID of user, room or composite |
boolean
Get the engaged status for participants.
Kind: instance method of Scene
Returns: boolean
- Is engaged status
Param | Type | Description |
---|---|---|
participants | string |
ID of user, room or composite |