
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
rescript-telegram-webapp
Advanced tools
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
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
telegramWebApp can be accessed directly, e.g. telegramWebApp.initDataTelegramWebApp.WebAppAPI, TelegramWebApp.MainButtonAPI, etc.telegramWebApp->TelegramWebApp.WebAppAPI.ready
telegramWebApp.hapticFeedback->TelegramWebApp.HapticFeedbackAPI.impactOccurred(Medium)
telegramWebApp.mainButton.text = "Press me"
telegramWebApp.mainButton.isVisible = true
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
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.
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.
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.
FAQs
> ReScript bindings for Telegram's client-side WebApp API.
We found that rescript-telegram-webapp demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.