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

3.1.4 • Public • Published

Telegramsjs



Bot API NPM Version NPM Downloads

⚙️ Introduction

Telegramsjs is a lightweight Node.js library for creating Telegram bots. It provides an easy-to-use and flexible framework for building bots without relying on third-party libraries such as Telegraf.js or node-telegram-bot-api. This library allows developers to create Telegram bots with ease and efficiency.

⚒️ Installation

You can install the telegramsjs library using npm:

npm install telegramsjs

📙 Usage

Example

// esm/ts module
import { TelegramBot } from "telegramsjs";
// cjs module
const { TelegramBot } = require("telegramsjs");

const bot = new TelegramBot(process.env.BOT_TOKEN);

bot.start((ctx) => ctx.reply("Welcome"));
bot.help((ctx) => ctx.reply("Send me a sticker"));
bot.reaction("❤️", (ctx) => ctx.reply("Like! ❤️"));
bot.hears("hi", (ctx) => ctx.reply("Hey there"));

bot.login();

// Enable graceful stop
process.once("SIGINT", () => bot.disconnect("SIGINT"));
process.once("SIGTERM", () => bot.disconnect("SIGTERM"));
// esm/ts module
import { TelegramBot, InlineKeyboard } from "telegramsjs";
// cjs module
const { TelegramBot, InlineKeyboard } = require("telegramsjs");

const bot = new TelegramBot(process.env.BOT_TOKEN);

bot.command("user", async (ctx) => {
  const inline_keyboard = new InlineKeyboard()
    .text("Like!", "like_callback_poll")
    .row()
    .text("Dislike!", "dislike_callback_poll");

  await ctx.reply("Developer 🙈", {
    reply_markup: inline_keyboard,
  });
});

bot.action(/callback_poll/, async (ctx) => {
  const text =
    ctx.data.split("_")[0] === "like"
      ? "Thank you for like! ❤️"
      : "Thank you, I will try! ❤️";
  await ctx.editMessageText(text);
});

bot.login();

// Enable graceful stop
process.once("SIGINT", () => bot.disconnect("SIGINT"));
process.once("SIGTERM", () => bot.disconnect("SIGTERM"));

Webhook

// esm/ts module
import { TelegramBot, InlineKeyboard } from "telegramsjs";
// cjs module
const { TelegramBot, InlineKeyboard } = require("telegramsjs");

const bot = new TelegramBot(process.env.BOT_TOKEN);

bot.start((ctx) => ctx.reply("Welcome"));
bot.help((ctx) => ctx.reply("Send me a sticker"));
bot.reaction("❤️", (ctx) => ctx.reply("Like! ❤️"), "newReaction");
bot.hears('hi', (ctx) => ctx.reply("Hey there"))

bot.login({
  webhook: {
    url: string;
    port?: number;
    host?: string;
    path?: string;
    certificate?: Buffer | ReadStream | string;
    ip_address?: string;
    max_connections?: number;
    tlsOptions?: TlsOptions;
    requestCallback?: RequestListener;
    allowed_updates?: MethodParameters["setWebhook"]["allowed_updates"];
    drop_pending_updates?: boolean;
    secret_token?: string;
  }
});

// Enable graceful stop
process.once("SIGINT", () => bot.disconnect("SIGINT"));
process.once("SIGTERM", () => bot.disconnect("SIGTERM"));

📖 Documentation

For more information and detailed documentation, please visit the Telegramsjs Documentation v1 Telegramsjs Documentation v2. Telegramsjs Documentation v3.

🎒 Contributions

We welcome contributions to the development of Telegramsjs! If you have any ideas or suggestions, please visit the Official Support Server or the Official Telegram Channel.

📒 Example

For a comprehensive example of using the library, please refer to the GitHub page.

🧾 License

Telegramsjs is available under the MIT license. For more information, please refer to the LICENSE file.

Dependencies (7)

Dev Dependencies (3)

Package Sidebar

Install

npm i telegramsjs

Weekly Downloads

193

Version

3.1.4

License

MIT

Unpacked Size

305 kB

Total Files

67

Last publish

Collaborators

  • crazy-sempai07