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

@tonsolutions/telemetree-node

v0.1.7

Published

The Telemetree Node SDK provides a convenient way to track and analyze Telegram events using the Telemetree service.

Downloads

550

Readme

Telemetree Node.js SDK

The Telemetree Node.js SDK provides a simple and efficient way to track and analyze Telegram events using the Telemetree service. This SDK enables easy event capture and secure transmission of Telegram events to the Telemetree platform for analysis.

Features

  • Automatically capture and send Telegram events to Telemetree
  • Encrypt event data with RSA public key encryption
  • Configure specific events and commands to track
  • Simple and intuitive API for seamless integration

Installation

Install the Telemetree SDK using npm:

npm install @tonsolutions/telemetree-node

Usage

  1. Set Up Environment Variables: Create a .env file to securely store your API keys and configuration.

    Add the following keys to .env:

    TELEGRAM_BOT_TOKEN="YOUR_TELEGRAM_BOT_TOKEN"
    TELEMETREE_API_KEY="YOUR_API_KEY"
    TELEMETREE_PROJECT_ID="YOUR_PROJECT_ID"
  2. Import and Initialize the Telemetree Client:

    require("dotenv").config();
    const TelemetreeClient = require("@tonsolutions/telemetree-node");
    
    const client = new TelemetreeClient(
        process.env.TELEMETREE_API_KEY,
        process.env.TELEMETREE_PROJECT_ID
    );
    
    // Ensure client is initialized before using it to track events
    await client.initialize();
  3. Configure Webhook with ngrok: Since Telegram requires a public URL to send updates, you can use ngrok to expose your local server to the internet.

    ngrok http 3000

    This will provide a public URL such as https://your-ngrok-url.ngrok.io. Use this URL to set up your bot’s webhook endpoint.

  4. Set the Webhook in Your App:

    app.get("/set-webhook", async (req, res) => {
      const webhookUrl = `https://your-ngrok-url.ngrok.io/webhook`; // Replace with your ngrok URL
      try {
        const response = await axios.get(
          `https://api.telegram.org/bot${process.env.TELEGRAM_BOT_TOKEN}/setWebhook?url=${webhookUrl}`
        );
        res.send(response.data);
      } catch (error) {
        console.error("Error setting webhook:", error);
        res.sendStatus(500);
      }
    });
  5. Track Telegram Events: Once the webhook is set, you can track events by sending the event data to the client’s track method:

    app.post("/webhook", async (req, res) => {
      const update = req.body;
    
      try {
        const status = await client.track(update);
        console.log("Event tracked successfully with status:", status);
      } catch (error) {
        console.error("Error tracking event:", error);
      }
    
      res.sendStatus(200);
    });

Configuration Options

You can pass the following options when initializing the client:

  • autoCaptureTelegram (Boolean): Enables or disables automatic capturing of Telegram events (default: true)
  • autoCaptureTelegramEvents (Array): Specifies the types of Telegram events to capture automatically (default: ["message"])
  • autoCaptureCommands (Array): Specifies the Telegram commands to capture automatically (default: ["/start", "/help"])

Encryption

The SDK uses RSA encryption to secure event data before sending it to the Telemetree service, ensuring data privacy. The publicKey is fetched automatically from the Telemetree configuration service during initialization, so there’s no need to manually set it.

License

This SDK is licensed under the MIT License.