Skip to content

Ready-to-use components for getting user input.

Notifications You must be signed in to change notification settings

grammyjs/components

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🪄 Components for grammY

🚧 Under development. Please do not use in production yet

Set of useful components for grammY.

Documentation »

Install

Node

// TODO

Deno

// TODO

Usage

// TODO: add imports after publishing

// Extend bot context type
export type MyContext = Context & WebAppDataFlavor;

// Create a bot, specify the extended context
const bot = new Bot<MyContext>(""); // <-- put your authentication token between the ""

bot.command("start", async (ctx) => {
  const keyboard = new Keyboard();

  // Sending the component to the user
  keyboard.webApp("Click to pick", new TimePicker().build());

  await ctx.reply("Hey, pick a time!", {
    reply_markup: keyboard,
  });
});

// Handle time selected by a user
bot.filter(TimePicker.match(), (ctx) => {
  const { time } = ctx.webAppData;

  return ctx.reply(`You chose ${time.getUTCHours()}:${time.getUTCMinutes()}`);
});

bot.start();

Component List

Repository contents

  • Packages
    • components - Package that provides all the components
      • web - Module that creates buttons of web components
      • keyboard - Module that implements keyboard components
  • Apps