npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

teletron-ts

v1.1.2

Published

Fast and Flexible Telegram Bot API Framework for Node.js written in TypeScript.

Downloads

11

Readme

teletron-ts

Fast and Flexible Telegram Bot API Framework for Node.js written in TypeScript.

Features

  • Full Telegram Bot API 5.7 support
  • Object-oriented
  • Full types support
  • Asynchronous
  • Speedy and efficient
  • Beginner friendly

Installation

npm i teletron-ts

Importing

TypeScript

import * as telegram from "teletron-ts";

import { TelegramAPI } from "teletron-ts"; // Individual classes

JavaScript

const telegram = require("teletron-ts");

const { TelegramAPI } = require("teletron-ts"); // Individual classes

Getting started

import { TelegramAPI } from "teletron-ts";

const telegram = new TelegramAPI("token"); // bot token api

// listen for the message event

telegram.onMessage(async (message) => {
  if (message.text === "Hi bot!")
    await telegram.sendMessage(message.chat.id, "Hi there, human!"); // sendMessage will return an instance of IMessage
});

// OR

telegram.on("message", async (message) => {
  if (message.text === "Hi bot!")
    await telegram.sendMessage(message.chat.id, "Hi there, human!"); // sendMessage will return an instance of IMessage
});

// fetch new updates from the api
telegram.startPolling();

Telegram Events

Events you can listen to usign teletron-ts:

  • message
  • edited_message
  • edited_channel_post
  • channel_post
  • inline_query
  • chosen_inline_result
  • callback_query
  • shipping_query
  • poll
  • poll_answer
  • chat_join_request

Please note that both inline_query and chosen_inline_result only work if you enabled this option by sending /setinline to @BotFather

For more information regarding inline queries visit the telegram docs here

Examples

Sending Files

There are 3 ways to send files. You can use the file id of a file that already exist on telegram servers, provide an HTTP URL to the file which then will be downloaded by telegram servers or upload a local file. Lets assume we want to send a photo via the bot:

import { TelegramAPI } from "teletron-ts";

const telegram = new TelegramAPI("token"); // bot token

telegram.on("message", async (message) => {
  // First Method: Using an already existing file_id of a file that has been previously uploaded on telegram
  await telegram.sendPhoto(
    message.chat.id,
    "AgADBQADqacxG2gbbxCWBkgvcmeAgxVPyjIABBlug37DKyhDEU0AAgI"
  );

  // Second Method: Using an HTTP photo url
  await telegram.sendPhoto(
    message.chat.id,
    "https://reshape.sport1.de/c/t/85599615-c80d-47f0-9179-4375d6e4fa93/976x549"
  );

  // Thrid Method: Using a local file
  await telegram.sendPhoto(message.chat.id, { file: "./anime.jpg" });
});

// fetch updates from the api
telegram.startPolling();

Inline Keyboards

Inline keyboards are buttons that will be sent along with the message. These become especially useful if you want to wait for user input to perform certain action!

import { TelegramAPI } from "teletron-ts";
import { IInlineKeyboardMarkup } from "teletron-ts";

const telegram = new TelegramAPI("token");

telegram.on("message", async (m) => {
  const inlineKeyboards: IInlineKeyboardMarkup = {
    inline_keyboard: [
      [
        { text: "Very Good!", callback_data: "vgood" },
        { text: "Fine", callback_data: "fine" },
      ],
      [{ text: "Amazing", callback_data: "amazing" }],
    ],
  };

  await telegram.sendMessage(
    m.chat.id,
    "Hey there, how are you feeling today?",
    {
      reply_markup: JSON.stringify(inlineKeyboards),
    }
  );
});

telegram.on("callback_query", async (query) => {
  if (query.data && query.data === "vgood")
    return await telegram.sendMessage(
      query.message.chat.id,
      "I am feeling very good today too!"
    );
});

Contributions

Software contributions are welcome. If you are not a dev, testing and reproting bugs can also be very helpful!

Questions?

Please open an issue if you have questions, wish to request a feature, etc.