grammy-calendar
TypeScript icon, indicating that this package has built-in type declarations

0.0.4 • Public • Published

Grammy Calendar Menu

npm

WARNING: unstable. This is not completely stable yet. Please try it out and provide feedback, either by opening an issue or in the group chat.

This grammY plugin ports telegraf-calendar-telegram to the grammY framework.

Usage

import { Calendar, type CalendarContext, type CalendarOptions } from "grammy-calendar";
import { Bot } from "grammy";

type MyContext = Context & CalendarContext;
type SessionData = {
  calendarOptions: CalendarOptions;
}

const bot = new Bot<MyContext>("BOT-TOKEN");
bot.use(session({
  initial: () => ({ 
    calendarOptions: {} 
  })
}));
const calendarMenu = new Calendar<MyContext>(
  (ctx) => ctx.session.calendarOptions
);
bot.use(calendarMenu);

bot.on("message:text", async (ctx) => {
  ctx.session.calendarOptions = { defaultDate: new Date() };
  await ctx.reply("This is a calendar", { reply_markup: calendarMenu })
})
bot.filter((ctx) => !!ctx.calendarSelectedDate, async (ctx) => {
  const dateText = ctx.calendarSelectedDate!.toString()
  await ctx.reply(`You have selected this date: ${dateText}`)
})

Package Sidebar

Install

npm i grammy-calendar

Homepage

grammy.dev/

Weekly Downloads

5

Version

0.0.4

License

MIT

Unpacked Size

19.7 kB

Total Files

13

Last publish

Collaborators

  • daniharo