npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

telegram-bot-calendar

v1.0.7

Published

This package is for creating calendar UI in telegram bot messages. Easy to use comes with built-in tools to create calendar UI with ease.

Readme

Telegram Bot Calendar

telegram-bot-calendar

Overview

This package is for creating calendar UI in telegram bot messages. Easy to use comes with built-in tools to create calendar UI with ease.

Demo Calendar

Installation

npm install telegram-bot-calendar

Initialization

For JS

const calendar = require('telegram-bot-calendar');

For TS

import calendar from 'telegram-bot-calendar';

Getting first date of the month

This function will provide the Date object for the first date of the provided date's month.

const todaysDate = Date.now();

const firstDate = calendar.getFirstDate(todaysDate);

Creating UI

This function will provide the JSON object, which needs to be passed with the message body while calling the send message API.

const todaysDate = Date.now();

const calendarUI = calendar.getUI(todaysDate);

Calling the send message API of Telegram bot with calendar UI.

const todaysDate = Date.now();

const calendarUI = calendar.getUI(todaysDate);

const sendMsgURL = `https://api.telegram.org/bot${process.env.telegramToken}/sendMessage`;

await axios.post(sendMsgURL,
    {
        chat_id: chat_id,
        text: "Telegram Bot Calendar",
        reply_markup: calendarUI
    }
)

Handling callbacks

The callback needs to be handled with command type. The type object specifies the type of command provided by the user using the calendar. It can be either a date or command for next month's or the previous month's calendar.

const callbackData = data.callback_query.data;

const commandData = calendar.getCommandData(data.callback_query.data);

commandData is an object consisting of two properties:

  1. type: it specifies the type of command passed by the user. It can be one of the seven listed below command types.

    • providedDate : This will be returned when the user clicks on the button displaying a valid date. In this case, the data object will consist of the date in the format month/date/year.

    • nextMonth : This will be returned when the clicks on the Next Month button. It is an indication to display the next month. data object, in this case, will consist of the first date of the displaying month.

    • prevMonth : This will be returned when the clicks on the Previous Month button. It is an indication to display to the previous month. data object in this case will consist of the first date of the displaying month.

    • currMonth : This will be returned when the user clicks on the button displaying the calendar's current month or demanded month.

    • day : This will be returned when the user clicks on the button displaying one of the seven days of the week.

    • dash : This will be returned when the user clicks on the button displaying one of the empty buttons which are displaying as dash or hyphen '-'.

    • notCalendarCommand : This will be returned when the callback data provided to the getCommandData function is not a calendar command or not a telegram-bot-calendar's generated callback data.

  2. data: it provides the information it can be either null or have some value depending upon the type. This will consist of a valid date in case of :

    • nextMonth

    • prevMonth

    • providedDate

    This will be null in case of :

    • day

    • currMonth

    • dash

    • notCalendarCommand

    The date will provided in the format month/date/year. Eg. 2/19/2022

Creating next month's calendar

To create then next month's calendar, first date of the next month is required which can be easily generated using the getNextMonthFirstDate.

const nextMonth = calendar.getNextMonthFirstDate(currDate);

const calendarUI = calendar.getUI(nextMonth);

In this way you can create next month's calendar UI. The currDate can be the date provided by callback with nextMonth command type.

Creating previous months calendar

To create then previous month's calendar, first date of the previous month is required which can be easily generated using the getPrevMonthFirstDate.

const prevMonth = calendar.getPrevMonthFirstDate(currDate);

const calendarUI = calendar.getUI(prevMonth);

In this way you can create previous month's calendar UI. The currDate can be the date provided by callback with prevMonth command type.

Additional

If you want to delete the previously shown calendar you can use the telegram's delete message API.

const chat_id = data.callback_query.from.id;
const message_id = data.callback_query.message.message_id;

const deleteMsgURL = `https://api.telegram.org/bot${process.env.telegramToken}/deleteMessage`;

await axios.post(deleteMsgURL,
    {
        chat_id: chat_id,
        message_id: message_id
    }
)