question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Global commands in scenes

See original GitHub issue

I have a problem with using scenes and commands. I need to have a command that leaves the scene. When I type /cancel at the scene it’s ignoring me and continue to do other actions.

Example:

// app.js

import Telegraf, { session } from 'telegraf'
import Stage from 'telegraf/stage'

import testScene from './scenes/test'

const telegraf = new Telegraf(process.env.TOKEN)
const stage = new Stage([
  testScene
])

telegraf.use(session())
telegraf.use(stage.middleware())

telegraf.command('cancel', async ({ reply, scene }) => {
  await reply('Hey, you canceled previous scene!')
  await scene.leave()
})

telegraf.startPolling()
// scenes/test/index.js

import Scene from 'telegraf/scenes/base'

const scene = new Scene('echo')

scene.enter(async ({ reply }) => reply('Hello.'))
scene.leave(async ({ reply }) => reply('Goodbye.'))

scene.on('text', async ({ reply }) => reply('Ping Pong.'))

export default scene

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
dotcypresscommented, Dec 18, 2017

Hey @mvrlin

To add global command to all scenes, you can use stage.command:

// app.js

import Telegraf, { session } from 'telegraf'
import Stage from 'telegraf/stage'

import testScene from './scenes/test'

const telegraf = new Telegraf(process.env.TOKEN)
const stage = new Stage([
  testScene
])
stage.command('cancel', async ({ reply, scene }) => {
  await reply('Hey, you canceled previous scene!')
  await scene.leave()
})

telegraf.use(session())
telegraf.use(stage.middleware())

telegraf.startPolling()

0reactions
mvrlincommented, Dec 18, 2017

@dotcypress thank you! Working great!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Key commands for Global Commands in Logic Pro
Key commands for Global Commands in Logic Pro ; Discard Recording and Return to Last Play Position. Command-Period (.) ; Capture as Recording....
Read more >
Choose global or local—ArcGIS Online Help | Documentation
You can choose between a global or local scene to best display your data, such as airline flight patterns, campus facilities, or underground...
Read more >
How can I get more documentation on Scenes, Stages and stuff?
When inside one, all the outer noise, such as global commands or message handlers, stop reacting on user actions. Scenes can be entered, ......
Read more >
scenedetect Application - PySceneDetect - Read the Docs
The options in this section represent the “global” arguments for the main scenedetect command. The most commonly used options are the input video(s)...
Read more >
To Work with Local and Global Scene Explorers | 3ds Max 2019
In any local Scene Explorer, click the arrow to the right of the text field at the bottom-left of the dialog and choose...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found