Giter VIP home page Giter VIP logo

telegraf-calendar-telegram's People

Contributors

dependabot[bot] avatar fzn0x avatar gianlucaparadise avatar hollag avatar mkhoussid avatar rezox1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

telegraf-calendar-telegram's Issues

Fantastic, but a bit slow sometimes

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! ๐Ÿ’ฏ

error_code: 409

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: {} }

Two suggestions

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,

Calendar markup with min and max dates

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

setMinDate and setMaxDate pass by reference

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);

Calendar is not defined

So i just installed your package and when i went to initiate the calendar following your read me i was met witht his error.

image

How to fix it?

Is the package deprecated?

I followed the download instruction but it says: Error: Cannot find module 'Calendar'. Is the packahe deprecated?

Remove long time spinners

Hi guys!

Thanks for the great add on! I use it in my current project, and here are some enhancement suggestions.

  • Add an example how to call it from inline keyboard, with no infinite spinner
calendar.setDateListener(async (ctx, date) => {
    return await ctx.answerCbQuery()
        .then(async () => {
            return ctx.reply(date)
        })
});
  • Add callback handler to calendar-telegram-ignore action, it allows to avoid long time spinners:
this.bot.action("calendar-telegram-ignore", async context => { 
    return await context.answerCbQuery() 
});
  • Add callback handler to calendar-telegram-next action:
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));
			})
		});
  • Add callback handler to calendar-telegram-prev action:
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));
			})
		});

Adding `shortcutButtonsPlacement` option

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:

Screenshot 2023-01-25 at 15 51 22

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.