JSPM

  • Created
  • Published
  • Downloads 1031775
  • Score
    100M100P100Q172824F
  • License MIT

grammY core package ported to Node.js

Package Exports

  • grammy

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (grammy) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

grammY

The grammY package lets you easily write Telegram bots. Here is a quickstart for you to get started, but note that a better explanation is in our repo on GitHub.

You may also want to check out the docs.

Quickstart

Talk to @BotFather to create a new Telegram bot and obtain a bot token.

Paste the following code into a new file bot.js.

import { Bot } from "grammy";
// This works, too (CommonJS modules):
// const { Bot } = require('grammy')

// Create bot object
const bot = new Bot(""); // <-- place your bot token inside this string

// Listen for messages
bot.command("start", (ctx) => ctx.reply("Welcome! Send me a photo!"));
bot.on("message:text", (ctx) => ctx.reply("That is text and not a photo!"));
bot.on("message:photo", (ctx) => ctx.reply("Nice photo! Is that you?"));
bot.on("edited_message", (ctx) =>
  ctx.reply("Ha! Gotcha! You just edited this!", {
    reply_to_message_id: ctx.editedMessage.message_id,
  })
);

// Launch!
bot.start();

Congratulations! You have successfully created your first Telegram bot.

You can run it like so:

node bot.js