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 🙏

© 2026 – Pkg Stats / Ryan Hefner

use-telegram

v1.0.10

Published

A TypeScript package for easy integration with Telegram WebApp API

Readme

use-telegram

A TypeScript package for easy integration with Telegram WebApp API. Provides React hooks and context for managing Telegram WebApp's MainButton with full TypeScript support.

Features

  • 🚀 React Hooks: Easy-to-use hooks for Telegram WebApp integration
  • 📝 TypeScript: Full TypeScript support with proper type definitions
  • 🎯 Flexible: Support for both persistent and one-time action buttons
  • 🔄 Auto-updates: Button text and options update automatically on state changes
  • 🎯 Flexible: Support for both persistent and one-time action buttons

Installation

npm install use-telegram

Quick Start

1. Wrap your app with the provider

import { TelegramWebContextProvider } from 'use-telegram';

function App() {
  return (
    <TelegramWebContextProvider>
      <YourApp />
    </TelegramWebContextProvider>
  );
}

2. Use the hooks in your components

import { useMainButton, useActionButton } from 'use-telegram';

function MyComponent() {
  const [count, setCount] = useState(0);

  // Persistent button that stays visible
  const counterBtn = useMainButton(
    { text: `Counter ${count}`, hasShineEffect: true }, 
    (btn) => {
      setCount(prev => {
        const newCount = prev + 1;
        btn.setText(`Counter ${newCount}`);
        return newCount;
      });
    }
  );

  // One-time button that hides after click
  const oneTimeBtn = useActionButton(
    { text: 'One time button', hasShineEffect: true }, 
    () => {
      alert('One time button clicked');
    }
  );

  return (
    <div>
      <button onClick={counterBtn.showButton}>Show Counter Button</button>
      <button onClick={oneTimeBtn.showButton}>Show One-time Button</button>
      <button onClick={counterBtn.hideButton}>Hide Button</button>
    </div>
  );
}

API Reference

Hooks

useMainButton(options, onClick?)

Creates a persistent main button that stays visible until manually hidden.

Parameters:

  • options (Partial): Button configuration
  • onClick? (btn: MainButton) => void: Click handler with button instance

Returns:

  • showButton(): Function to show the button
  • hideButton(): Function to hide the button

useActionButton(options, onClick?)

Creates a one-time action button that automatically hides after being clicked.

Parameters:

  • options (Partial): Button configuration
  • onClick? (btn: MainButton) => void: Click handler with button instance

Returns:

  • showButton(): Function to show the button
  • hideButton(): Function to hide the button

Button Options

interface MainButton {
  text: string;           // Button text
  color?: string;         // Button color (hex format)
  hasShineEffect?: boolean; // Enable shine effect
}

Context Provider

TelegramWebContextProvider

Wraps your app to provide Telegram WebApp functionality.

Props:

  • children: React components
  • theme?: Optional theme parameters
<TelegramWebContextProvider theme={{ bg_color: '#ffffff' }}>
  {children}
</TelegramWebContextProvider>

Examples

Counter with Auto-updating Text

import { useState } from 'react';
import { useMainButton } from 'use-telegram';

function Counter() {
  const [count, setCount] = useState(0);

  const btn = useMainButton(
    { text: `Count: ${count}`, hasShineEffect: true },
    (btn) => {
      setCount(prev => {
        const newCount = prev + 1;
        btn.setText(`Count: ${newCount}`);
        return newCount;
      });
    }
  );

  return (
    <div>
      <p>Current count: {count}</p>
      <button onClick={btn.showButton}>Show Counter Button</button>
      <button onClick={btn.hideButton}>Hide Button</button>
    </div>
  );
}

Form Submission

import { useActionButton } from 'use-telegram';

function Form() {
  const [formData, setFormData] = useState('');

  const submitBtn = useActionButton(
    { text: 'Submit Form', color: '#007AFF' },
    () => {
      // Form will be submitted and button will auto-hide
      console.log('Form submitted:', formData);
    }
  );

  return (
    <div>
      <input 
        value={formData} 
        onChange={(e) => setFormData(e.target.value)}
        placeholder="Enter data"
      />
      <button onClick={submitBtn.showButton}>Show Submit Button</button>
    </div>
  );
}

Custom Theme

import { TelegramWebContextProvider } from 'use-telegram';

function App() {
  const theme = {
    bg_color: '#ffffff',
    text_color: '#000000',
    hint_color: '#999999',
    link_color: '#007AFF',
    button_color: '#007AFF',
    button_text_color: '#ffffff'
  };

  return (
    <TelegramWebContextProvider theme={theme}>
      <YourApp />
    </TelegramWebContextProvider>
  );
}

Requirements

  • React 18+
  • Node.js 16+
  • Telegram WebApp environment

Browser Support

This package is designed to work within Telegram's WebApp environment. Make sure your app is running inside Telegram's WebApp container.

Development

# Install dependencies
npm install

# Build the package
npm run build

# Watch for changes
npm run dev

# Lint code
npm run lint

# Format code
npm run format

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

If you encounter any issues or have questions, please open an issue on GitHub.

Changelog

1.0.0

  • Initial release
  • Support for MainButton and ActionButton hooks
  • Theme customization
  • Full TypeScript support