'how to save in ctx and use it again in action method in telegraf js?

I am creating telegram bot with telegraf js and node js and I wanna pass data in state

const { Telegraf } = require("telegraf");

const bot = new Telegraf(API_KEY);

bot.command("start", (ctx, next) => {
  ctx.state.id= 10000;
  ctx.reply("you used bot", {
    reply_markup: {
      inline_keyboard: [[{ text: "hello", callback_data: "hello" }]],
    },
  });
  next(ctx);
});

but it doesn't appear in action method

bot.action("hello", (ctx) => {
  console.log(ctx.state);
});

this is the output of the console for ctx.state

{}

I passed data with start method and it succeeded but it doesn't work with action method



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source