npm.io
4.14.1 β€’ Published 3 months ago

telegramsjs

Licence
MIT
Version
4.14.1
Deps
6
Size
1.1 MB
Vulns
0
Weekly
0
Stars
52

Telegramsjs



Bot API NPM Version NPM Downloads

About

telegramsjs is a powerful Node.js module that allows you to easily interact with the Telegram API.

  • Object-oriented
  • Predictable abstractions
  • Performant
  • 100% coverage of the Telegram API

Installation

npm install telegramsjs
yarn add telegramsjs

Support the Project

Support the developer with a cup of teaβ€”after all, solo covers the package.
Buy me a coffee

Optional packages

Example usage

Install telegramsjs:

npm install telegramsjs
yarn add telegramsjs

Afterwards we can create a quite simple example bot:

// ECMAscript/TypeScript
import {
  TelegramClient,
  InlineKeyboardBuilder,
  MarkupStyles,
} from "telegramsjs";
// CommonJS
const {
  TelegramClient,
  InlineKeyboardBuilder,
  MarkupStyles,
} = require("telegramsjs");

const client = new TelegramClient("TELEGRAM_BOT_TOKEN");

client.on("ready", async ({ user }) => {
  await user.setCommands([
    {
      command: "/start",
      description: "Starting command",
    },
  ]);

  if (user.capabilities.allow("joinGroups")) {
    console.log("The bot has permission to be added to other groups. πŸ”“");
  }
  
  console.log(`Bot @${user.username} is the ready status!`);

});

client.on("message", async (msg) => {
  if (!msg.content) return;

  if (msg.content === "/menu" || msg.content === "/start") {
    const menu = new InlineKeyboardBuilder()
      .text("Pay", "menu_pay", {
        style: MarkupStyles.Green,
        icon: "5463122435425448565",
      })
      .text("Rules", "menu_rules", {
        style: MarkupStyles.Danger,
        icon: "5465154440287757794",
      })
      .row()
      .text("Home", "menu_home", {
        style: MarkupStyles.Primary,
        icon: "5253997076169115797",
      });

    await msg.chat.send("Panel for payment", {
      replyMarkup: menu,
    });
  }

  if (msg.content.startsWith("/tag")) {
    if (!msg.chat.isSupergroup()) {
      return msg.reply(`Changing your nickname is only available in groups.`);
    }

    const [, newTag] = msg.content.split(" ");

    try {
      await msg.member.setTag(newTag);
      return msg.chat.send(
        `${msg.author.firstName} Your custom tag has been changed to: ${newTag}`,
      );
    } catch (err) {
      console.log(err);

      return msg.chat.send("Error when changing custom tag.");
    }
  }
});

client.login();

Documentation

For more information and detailed documentation, please visit the documentation.

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 Group.

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.

Keywords