Skip to content
This repository has been archived by the owner on Sep 22, 2018. It is now read-only.
/ telegraf-flow Public archive

[Deprecated] Control flow middleware for Telegraf

License

Notifications You must be signed in to change notification settings

telegraf/telegraf-flow

Repository files navigation

Build Status NPM Version js-standard-style

Telegraf flow

🚥 Control flow middleware for Telegraf.

Deprecated: telegraf@3.15.3 now supports scene-based control flow (aka Stage) from the box.

Installation

$ npm install telegraf-flow

Example

const Telegraf = require('telegraf')
const TelegrafFlow = require('telegraf-flow')
const { Scene } = TelegrafFlow

// Greeter scene
const greeterScene = new Scene('greeter')
greeterScene.enter((ctx) => ctx.reply('Hi'))
greeterScene.leave((ctx) => ctx.reply('Buy'))
greeterScene.hears(/hi/gi, leave())
greeterScene.on('message', (ctx) => ctx.reply('Send `hi`'))

// Scene registration
const flow = new TelegrafFlow()
flow.register(greeterScene)

const app = new Telegraf(process.env.BOT_TOKEN)
// Flow requires valid Telegraf session
app.use(Telegraf.memorySession())
app.use(flow.middleware())
app.command('greeter', (ctx) => ctx.flow.enter('greeter'))
app.startPolling()

More examples

Telegraf context

Telegraf user context props and functions:

app.on('...', (ctx) => {
  ctx.flow.state                                    // Current scene state
  
  ctx.flow.enter(sceneId, [defaultState, silent])   // Enter scene
  ctx.flow.reenter()                                // Reenter current scene
  ctx.flow.leave()                                  // Leave scene 
});

About

[Deprecated] Control flow middleware for Telegraf

Resources

License

Stars

Watchers

Forks

Packages

No packages published