I can't switch months ๐
MrBouchtaoui opened this issue ยท 6 comments
First i want to thank you for your fantastic calendar ๐
I do have a problem, I just think I don't know how to do it correctly.
I can see the callendar on the chat, but I can change month or year just once and than it stops.
I have the following Wizard scene:
const reminderWizard = (userId) => {
return new WizardScene(
"my-wizard",
async (ctx) => {
await ctx.reply(`What's your name?`);
ctx.wizard.cursor = 0;
return ctx.wizard.next();
},
async (ctx) => {
const resp = ctx.message.text;
ctx.scene.session.state.subject = resp;
await ctx.reply(`What's your job?`);
return ctx.wizard.next();
},
async (ctx) => {
const resp = ctx.message.text;
ctx.scene.session.state.description = resp;
console.log("Received response: ", resp);
// show calendar!!!
calendar.startNavCalendar(ctx.message);
return ctx.wizard.next();
},
async (ctx) => {
const resp = ctx.message.text;
console.log("Received response: ", resp);
// Hmmm how does this work???
if (
ctx.callbackQuery.message.message_id ==
calendar.chats.get(ctx.callbackQuery.message.chat.id)
) {
res = calendar.clickButtonCalendar(ctx.callbackQuery);
if (res !== -1) {
await ctx.reply("You selected: " + res);
}
} else {
await ctx.reply(`Thank you for your payment!`);
}
return ctx.wizard.next();
},
async (ctx) => {
const resp = ctx.message;
console.log("Received response: ", resp);
await ctx.reply("I registered your subscription");
return await ctx.scene.leave();
}
);
};
My assumption is that this snippet is not enough:
if (
ctx.callbackQuery.message.message_id ==
calendar.chats.get(ctx.callbackQuery.message.chat.id)
) {
res = calendar.clickButtonCalendar(ctx.callbackQuery);
if (res !== -1) {
await ctx.reply("You selected: " + res);
}
}
Can you please help me with a solution?
Hello, @MrBouchtaoui!
First of all, thank you, Iโm glad that my library was useful to someone)
Did I understand you correctly, you want it to be possible if you select the wrong month, say, to be able to go back to choosing the month?
The problem is that I can press < or > one time and than it stops working.
Example:
Calendar starts with January 2024
I press next > I get February
I press next > it stays at February instead of March
I press previous < it stays at February
So the next > or previous < buttons work once and than stop working.
I use the code in my previous post.
I also declared the calendar like this:
let calendar = new Calendar(bot, {
date_format: 'DD-MM-YYYY',
language: 'en',
bot_api: 'telegraf'
});
I hope you have an idea what might be the problem and how to fix it.
I found the solution after studying your code.
if (
ctx.callbackQuery.message.message_id ==
calendar.chats.get(ctx.callbackQuery.message.chat.id)
) {
res = calendar.clickButtonCalendar(ctx.callbackQuery);
if (res !== -1) {
await ctx.reply("You selected: " + res);
} else { // rewind this step to handle next button action!
ctx.wizard.cursor--;
}
}
Maybe you can update your examples with a wizard demo. Anyway, thank you very much for sharing this nice library ๐๐ผ
I understood you.
Today I will try to test and release an update)
Hello, @MrBouchtaoui!
I apologize for the long response, Iโm currently busy with my main work, Iโll test it and release an update in the near future.
Good afternoon, @MrBouchtaoui!
Sorry for the long response, it was too much work.
Regarding your issue: I tested and carefully studied your comment. The problem occurs due to the use of wizard scene
, which is a special case of using the library. A little later I will add a FAQ where I will describe such cases. Thanks for your support and use of the library.