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.

[QUESTION] How to enter a scene without context but with chatId

See original GitHub issue

I’m trying to enter a scene because a server side event happened. I have the chatId but no context, since the user didn’t talk in the chat.

How should I enter the scene ?

Here’s a little bit of code:

const PrivateMessage = new Scene('PRIVATE_MESSAGE')
PrivateMessage.enter((ctx) => ctx.reply('echo scene'))
PrivateMessage.leave((ctx) => ctx.reply('exiting echo scene'))
PrivateMessage.command('back', leave())
PrivateMessage.on('text', (ctx) => ctx.reply(ctx.message.text))

this.bot = new Telegraf(this.options.token, {username: this.options.username});
const stage = new Stage([PrivateMessage]);
this.bot.use(session());
this.bot.use(stage.middleware());

ipcMain.on('TelegramNotificationRequest', (ev, obj) => {
  Stage.enter(obj.type); // 'PRIVATE_MESSAGE'
})

When the TelegramNotificationRequest happens, I would like to enter the scene to ask the user what does he want to do.

Is it possible ?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
slydercommented, Jun 24, 2021

Hello, isn’t still possible to enter into the scene during some server event? I think it is a very useful case and is there any way to realize it? So I need to enter into the scene, then send a message to the user and wait for a response.

0reactions
dotcypresscommented, Oct 29, 2019

Guys, enter can’t be called without context. If you want to achieve external control for user, you need to store this event and use it only when you have any update from user.


this.bot = new Telegraf(this.options.token)
const stage = new Stage([PrivateMessage])
stage.on('message', (ctx) => {
  if (database.eventPending(ctx.chat.id)) {
    return ctx.scene.enter('blabla')
  } else {
    return next()
})
this.bot.use(session())
this.bot.use(stage.middleware())

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to send message only once to every individual user who ...
You want to ignore the incoming message if the chat id exists in the sheets to avoid duplicates; Send message to user using...
Read more >
Top 5 telegraf Code Examples - Snyk
To help you get started, we've selected a few telegraf examples, based on popular ways it is used in public projects. Secure your...
Read more >
Telegraf VS Node-Telegram-Bot-API - DEV Community ‍ ‍
Here we imported our scenes and registered them in array. Also we added a stage middleware without which our scenes won't work. And...
Read more >
SIGNAL Behind the Scenes: Twilio's Andres Jaan Tack
In this interview, Twilio's Andres Jaan Tack sits down with Corey Weathers to talk about Twilio's launch of Conversations.
Read more >
Telethon Documentation - Read the Docs
In short, the same code above but without comments to make it clearer: ... Telethon will add a minus sign (negate) the real...
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