I am creating game bot, where user should answer some questions, and admin should approve or reject them. I need to find a way, when admin is accepted the answer, to force change scene of the user.
So for example the user is in scene "answering". When user send message, it sends to admin
const gameButtons = [
[
{ text: `✅ approve`, callback_data: `gTo:appG/uId=${ctx.state.userId}` },
{ text: `❌ reject`, callback_data: `gTo:rejG/uId=${ctx.state.userId}` },
],
];
await ctx.telegram.sendMessage(ctx.state.chatTo, `User answer is: ${ctx.message.text}`, {
reply_markup: JSON.stringify({ inline_keyboard: gameButtons }),
});
So the admin receive message and or will accept or reject
const approveQuestion = async ({ ctx, text }) => {
const [, user] = text.split("/");
const [, userId] = user.split("=");
//somehow change users scene to answered
await changeUserScene("winner", userId);
await ctx.telegram.sendMessage(userId, "It is right answer");
};
Is there way to do that?
2
Answers
Edit: After reading/trying a lot, based on a few github issues. You can only change a user’s scene when you have the context (
ctx
) of that user.The easiest way is to get the
ctx
is to save it for later once you get an interaction with a user.Please see my test code, explanation below:
The 2 important parts are:
Here we save the
ctx
of every user when they enterscene_1
.Then, when we receive a message from a user that’s in
scene_2
, we check (this is pure for testing) if the message if fromuser_2
, if so, we use thectx
ofuser_1
and callscene.enter
to force him into the new scene.This works as expected, if needed I can place some screenshots of 2 Telegram accounts talking to that bot.
It seems like you can create the
ctx
on the fly, but I’d recommend just saving it if you have the ability to.Yes run the following. Have inserted comments to aid