8.3.0 • Published 8 years ago

telegraf-flow v8.3.0

Weekly downloads
5
License
MIT
Repository
github
Last release
8 years ago

Build Status NPM Version js-standard-style

Telegraf flow

🚥 Control flow middleware for Telegraf.

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 
});
8.3.0

8 years ago

8.2.2

8 years ago

8.2.1

8 years ago

8.2.0

8 years ago

8.1.2

9 years ago

8.1.1

9 years ago

8.1.0

9 years ago

8.0.1

9 years ago

8.0.0

9 years ago

7.1.0

9 years ago

7.0.0

9 years ago

6.1.0

9 years ago

6.0.0

9 years ago

5.1.0

9 years ago

5.0.0

9 years ago

4.2.0

9 years ago

4.1.0

9 years ago

4.0.0

9 years ago

3.4.0

9 years ago

3.3.0

9 years ago

3.2.0

9 years ago

3.1.0

9 years ago

3.0.0

9 years ago

2.0.0

9 years ago

1.4.2

9 years ago

1.4.1

10 years ago

1.4.0

10 years ago

1.3.0

10 years ago

1.2.0

10 years ago

1.1.0

10 years ago

1.0.0

10 years ago

0.9.1

10 years ago

0.9.0

10 years ago

0.8.1

10 years ago

0.8.0

10 years ago

0.7.0

10 years ago

0.6.1

10 years ago

0.6.0

10 years ago

0.5.0

10 years ago

0.4.0

10 years ago

0.3.0

10 years ago

0.2.0

10 years ago

0.1.0

10 years ago