Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
middleware () {
return compose([
(ctx, next) => {
if (!ctx[this.options.sessionName]) {
throw new Error("telegraf-flow: Can't find session.")
}
ctx.flow = new FlowContext(ctx, this.scenes, this.options)
return next()
},
super.middleware(),
lazy((ctx) => ctx.flow.current || passThru())
])
}
leave (...fns) {
this.leaveHandler = compose([this.leaveHandler, ...fns])
return this
}
if (response.type === 'stop') {
break
}
this.state.wit.entities = response.entities
this.state.wit.confidence = response.confidence
this.state.wit.message = response.msg
switch (response.type) {
case 'msg':
yield compose(self.messageHandlers)
break
case 'merge':
yield compose(self.mergeHandlers)
break
case 'action':
if (self.actionHandlers[response.action]) {
yield compose(self.actionHandlers[response.action])
}
break
case 'error':
self.onError(new WitError('Wit error: Please check your "action" and "merge" handlers', response))
break
}
messageText = null
hops--
}
this.session.__wit = this.state.wit.context
if (hops === 0) {
self.onError(new WitError('Hop limit reached: Please check your "action" and "merge" handlers', response))
}
})
}
constructor (id, options) {
const opts = Object.assign({
handlers: [],
enterHandlers: [],
leaveHandlers: []
}, options)
super(...opts.handlers)
this.id = id
this.options = opts
this.enterHandler = compose(opts.enterHandlers)
this.leaveHandler = compose(opts.leaveHandlers)
}
enter (...fns) {
this.enterHandler = compose([this.enterHandler, ...fns])
return this
}
var hops = self.maxHops
while (hops > 0) {
var response = yield self.converse(sessionId, messageText, this.state.wit.context)
debug('response', response.type)
if (response.type === 'stop') {
break
}
this.state.wit.entities = response.entities
this.state.wit.confidence = response.confidence
this.state.wit.message = response.msg
switch (response.type) {
case 'msg':
yield compose(self.messageHandlers)
break
case 'merge':
yield compose(self.mergeHandlers)
break
case 'action':
if (self.actionHandlers[response.action]) {
yield compose(self.actionHandlers[response.action])
}
break
case 'error':
self.onError(new WitError('Wit error: Please check your "action" and "merge" handlers', response))
break
}
messageText = null
hops--
}
this.session.__wit = this.state.wit.context
if (hops === 0) {
self.onError(new WitError('Hop limit reached: Please check your "action" and "merge" handlers', response))
constructor (id, options) {
const opts = Object.assign({
handlers: [],
enterHandlers: [],
leaveHandlers: []
}, options)
super(...opts.handlers)
this.id = id
this.options = opts
this.enterHandler = compose(opts.enterHandlers)
this.leaveHandler = compose(opts.leaveHandlers)
}
context: sessionState
}
var messageText = this.message.text
var hops = self.maxHops
while (hops > 0) {
var response = yield self.converse(sessionId, messageText, this.state.wit.context)
debug('response', response.type)
if (response.type === 'stop') {
break
}
this.state.wit.entities = response.entities
this.state.wit.confidence = response.confidence
this.state.wit.message = response.msg
switch (response.type) {
case 'msg':
yield compose(self.messageHandlers)
break
case 'merge':
yield compose(self.mergeHandlers)
break
case 'action':
if (self.actionHandlers[response.action]) {
yield compose(self.actionHandlers[response.action])
}
break
case 'error':
self.onError(new WitError('Wit error: Please check your "action" and "merge" handlers', response))
break
}
messageText = null
hops--
}