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

rescript-telegram-webapp

v0.0.2

Published

> ReScript bindings for Telegram's client-side WebApp API.

Readme

rescript-telegram-webapp

ReScript bindings for Telegram's client-side WebApp API.

Based on Telegram Bot API 9.1.

Official docs (worth keeping open in another tab): https://core.telegram.org/bots/webapps#initializing-mini-apps

API Reference: API_REFERENCE.md

Design goals

  • No runtime overhead
  • As close to 1:1 with original API
  • Only encode what is documented

Usage

Install the package via npm:

npm install rescript-telegram-webapp

In your rescript.json, add the dependency:

{
  "dependencies": [
+   "rescript-telegram-webapp"
  ]
}

As per Telegram's documentation, include the Telegram Web App script in your HTML:

<script src="https://telegram.org/js/telegram-web-app.js?59"></script>

Get a reference to the telegramWebApp record in your ReScript code:

open TelegramWebApp.Global
  • Fields of telegramWebApp can be accessed directly, e.g. telegramWebApp.initData
  • Methods are available in modules named after the objects in the original API, e.g. TelegramWebApp.WebAppAPI, TelegramWebApp.MainButtonAPI, etc.
telegramWebApp->TelegramWebApp.WebAppAPI.ready
telegramWebApp.hapticFeedback->TelegramWebApp.HapticFeedbackAPI.impactOccurred(Medium)

telegramWebApp.mainButton.text = "Press me"
telegramWebApp.mainButton.isVisible = true

Difference in APIs

Applying methods

Object oriented APIs are modeled as record types, and functions that act on those records. For example:

window.Telegram.WebApp.ready();

Becomes

open TelegramWebApp.Global

TelegramWebApp.WebAppAPI.ready(telegramWebApp)

Or, using pipe operator:

telegramWebApp->TelegramWebApp.WebAppAPI.ready

All enumerable strings are Variants

It is now possible to switch on errors or statuses and expect exhaustiveness checking.

open TelegramWebApp.Global
open TelegramWebApp.WebAppAPI

telegramWebApp
->openInvoice("invoice_12345", ~callback=status => {
  switch status {
  | Paid => Console.log("Paid")
  | Cancelled => Console.log("Cancelled")
  | Failed => Console.log("Failed")
  | Pending => Console.log("Pending")
  | UndocumentedStatus(value) => Console.log(value)
  }
})

Note the UndocumentedStatus(value) case, for compatibility with future additions to Bot API.

A subscription method per event type

Every event has its dedicated on<EventName> and off<EventName> functions, to provide better type safety. For example, subscribing to the fullscreenChanged event looks like this:

open TelegramWebApp.Global
open TelegramWebApp.WebAppAPI

let handleFullscreenChanged: Events.fullscreenChanged = event => {
  if event.isFullscreen {
    Console.log("Entered fullscreen")
  } else {
    Console.log("Exited fullscreen")
  }
}
telegramWebApp->onFullscreenChanged(handleFullscreenChanged)
telegramWebApp->offFullscreenChanged(handleFullscreenChanged)

WebAppAPI.Events contains type definitions for all event handler signatures.

Submodules

In the original API, some methods are grouped into nested objects. For example, Telegram.WebApp.MainButton. In ReScript, the data structure is preserved, and the methods are grouped into modules. For example, accessing the main button's text is straightforward:

open TelegramWebApp.Global

let mainButtonText = telegramWebApp.mainButton.text

And setting the main button's text looks like this:

open TelegramWebApp.Global
open TelegramWebApp.MainButtonAPI

telegramWebApp.mainButton
->setText("New Button Text")
->ignore

Most of the submodule methods return the object they operate on, to allow method chaining. In ReScript, you can use ->ignore to discard the return value when it's not needed.