gianlucaparadise / telegraf-calendar-telegram Goto Github PK
View Code? Open in Web Editor NEWInline calendar for Telegram bots using Telegraf framework
Home Page: https://t.me/CalendarTelegrafBot
License: Apache License 2.0
Inline calendar for Telegram bots using Telegraf framework
Home Page: https://t.me/CalendarTelegrafBot
License: Apache License 2.0
Hello,
I'm in love with this component, so that I switched from node-bot-telegram-api to Telegraph in order to be able to use it.
It was exactly what I was looking for ๐ก๏ธ .
But, I noticed sometimes it waits switching from a month to another, why do you think this happens?
It is a behaviour only few times is present, so I was wondering why..
I am available if you need more details.
And... congrats! ๐ฏ
When I call this I am getting following error
response:
{ ok: false,
error_code: 409,
description: 'Conflict: terminated by other long poll or webhook' },
description: 'Conflict: terminated by other long poll or webhook',
parameters: {} }
First of all, Thanks for your cool component:+1:
I got two suggestions:
1: Separate year and month in two line and year changer for the first line or put it as an option.
2: get a function in options for date select callback
Sincerely,
any chance to update telegraf to new 4.7.0 ?
So i managed to set up the calendar so it works, but when i click on the advance month button it does nothing.
Hello there!
I believe that this code:
/**
* Return Calendar Markup
*/
getCalendar() {
return this.helper.getCalendarMarkup(new Date());
}
should actually be like this, in order to be able to get correctly (date-limited) markup from the calendar.
/**
* Return Calendar Markup
*/
getCalendar() {
return this.helper.getCalendarMarkup(new Date(this.helper.options.minDate));
}
Explanation: the default date ("today") might not be within the restricted range minDate up to maxDate, so the generated markup is potentially showing an erroneous view.
Also note that in this case we also create a temporary Date object that we pass on, because otherwise this.helper.options.minDate will also get changed while generating the markup, similar to this issue #5
Another potential improvement:
calendarWidget.setMinDate(myMinDate));
calendarWidget.setMaxDate(myMaxDate);
as per documentation can actually lead to myMinDate and myMaxDate to have their value changed as a side effect when generating a new view. So either make the documentation clearer to pass a completely new (throw-away) object to avoid this:
calendarWidget.setMinDate(new Date(myMinDate));
calendarWidget.setMaxDate(new Date(myMaxDate));
or adjust the setter/getter functions like this:
setMinDate(date) {
this.helper.setMinDate(new Date(date));
return this;
}
instead of simply passing the reference to the object as is the case at the moment:
this.helper.setMinDate(date);
I followed the download instruction but it says: Error: Cannot find module 'Calendar'. Is the packahe deprecated?
I have programmed demo bot using node-telegram-bot-API and now I am planning to integrate my bot with the calendar. Can this be tweaked so that it can be run from the bot powered by node-telegram-bot-api instead of telegraf?
Hi guys!
Thanks for the great add on! I use it in my current project, and here are some enhancement suggestions.
calendar.setDateListener(async (ctx, date) => {
return await ctx.answerCbQuery()
.then(async () => {
return ctx.reply(date)
})
});
this.bot.action("calendar-telegram-ignore", async context => {
return await context.answerCbQuery()
});
this.bot.action(/calendar-telegram-next-[\d-]+/g, async context => { // turn function into async
let dateString = context.match[0].replace("calendar-telegram-next-", "");
let date = new Date(dateString);
date.setMonth(date.getMonth() + 1);
let prevText = context.callbackQuery.message.text;
return await context.answerCbQuery() // avoid long time spinner
.then(async () => {
return context.editMessageText(prevText, this.helper.getCalendarMarkup(date));
})
});
this.bot.action(/calendar-telegram-prev-[\d-]+/g, async context => { // turn function into async
let dateString = context.match[0].replace("calendar-telegram-prev-", "");
let date = new Date(dateString);
date.setMonth(date.getMonth() - 1);
let prevText = context.callbackQuery.message.text;
return await context.answerCbQuery() // avoid long time spinner
.then(async () => {
return context.editMessageText(prevText, this.helper.getCalendarMarkup(date));
})
});
I tried to submit a PR, but caught a 403 error.
Anyway, minor - but useful - change:
--- a/telegraf-calendar-telegram/calendar-helper/index.js
+++ b/telegraf-calendar-telegram/calendar-helper/index.js
@@ -24,6 +24,7 @@ class CalendarHelper {
maxDate: null,
ignoreWeekDays: [],
shortcutButtons: [],
+ shortcutButtonsPlacement: 'top',
hideIgnoredWeeks: false,
},
options
@@ -84,7 +85,9 @@ class CalendarHelper {
);
}
- page.push(menuShortcutButtons);
+ page[
+ this.options.shortcutButtonsPlacement === 'bottom' ? 'push' : 'unshift'
+ ](menuShortcutButtons);
}
addHeader(page, date) {
@@ -209,12 +212,13 @@ class CalendarHelper {
let page = [];
+ this.addHeader(page, date);
+ this.addDays(page, date);
+
const shortcutButtons = this.options.shortcutButtons;
if (shortcutButtons && shortcutButtons.length > 0) {
this.addShortcutButtons(page);
}
- this.addHeader(page, date);
- this.addDays(page, date);
return page;
}
This allows to build the calendar like this:
setStartWeekDay(startDay) {
this.helper.setWeekDayNames(startDay);
return this;
}
should be
this.helper.setStartWeekDay(startDay);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.