How to use the telegraf.compose function in telegraf

To help you get started, we’ve selected a few telegraf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github telegraf / telegraf-flow / lib / flow.js View on Github external
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())
    ])
  }
github telegraf / telegraf-flow / lib / generic-scene.js View on Github external
leave (...fns) {
    this.leaveHandler = compose([this.leaveHandler, ...fns])
    return this
  }
github telegraf / telegraf-wit / lib / telegraf-wit.js View on Github external
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))
    }
  })
}
github telegraf / telegraf-flow / lib / generic-scene.js View on Github external
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)
  }
github telegraf / telegraf-flow / lib / generic-scene.js View on Github external
enter (...fns) {
    this.enterHandler = compose([this.enterHandler, ...fns])
    return this
  }
github telegraf / telegraf-wit / lib / telegraf-wit.js View on Github external
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))
github telegraf / telegraf-flow / lib / generic-scene.js View on Github external
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)
  }
github telegraf / telegraf-wit / lib / telegraf-wit.js View on Github external
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--
    }