bot listen from chanel #1770
Unanswered
yeucodonvn
asked this question in
Q&A
Replies: 1 comment
-
You should NEVER nest listeners like this: bot.command('upfile', (ctx) => {
bot.on('document', (ctx) => { All it does is mount a new listener for all documents every time the command Consider using scenes. // @file: main.js
// you can also use require normally
import { Telegraf, Scene } from "telegraf";
import { document } from "./scenes/document.js";
const stage = new Scenes.Stage([ document ]);
const bot = new Telegraf(token);
bot.use(session()); // Important! Scenes require session first
bot.use(stage.middleware()); // enable our scenes
bot.command("upfile", ctx => {
// add any conditions you need here
return ctx.scene.enter("document-collector");
}); When a user sends the // @file: scenes/document.js
// you can also use require normally
import { Scene } from "telegraf";
import { message } from "telegraf/filters";
export const document = new Scenes.BaseScene("document-collector");
// send a prompt message when user enters scene
document.enter(ctx => ctx.reply("Upload your document"));
// listen for document messages once user is in the scene
document.on(message("document"), ctx => {
// ctx.update.message.document;
});
// reply to all other types of messages
document.on("message", ctx => ctx.reply("Invalid message. Upload a document or send /exit"));
// a way to exit the scene
document.command("exit", ctx => ctx.scene.leave()); Until you call See examples of scenes. If you need to handle multiple questions in a sequence, you may want to use a Wizard scene. See examples of wizards. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I don't know how to make the bot wait for and receive a file from a specific channel id.
bot.command and bot.on are two different ids, so it cannot see the file that has been downloaded from the channel.
Beta Was this translation helpful? Give feedback.
All reactions