Integrate Unity WebGL on Telegram mini-app
Integrate Unity WebGL on Telegram mini-app
Overview#
Use Unity WebGL to create a mini-game and integrate it into a Telegram mini-app.
Building a new app? Check out the Unity sample project, a scene that demonstrates how to integrate Unity WebGL on Telegram mini-app. The scene is called Telegram
and is located in the Scenes
folder.
Prerequisites#
Openfort SDK is set up in your Unity project. If not, follow the quickstart guide. This project uses WebGL, so make sure you also have set up WebGL.
Configuration#
Telegram mini-app setup#
-
Create a Telegram bot and get the bot token. Follow the official guide to create a bot and get the token.
-
Configure your project providers Enable the Telegram provider and add the bot username and bot token.
Enable the Telegram (Mini-app) provider and add the bot token.
-
Import the telegram mini app SDK in your HTML template file. If you are using the Openfort SDK, you can add the script in the
index.html
file in Assets>WebGLTemplates>Openfort._10<script src="https://cdn.jsdelivr.net/npm/@telegram-apps/sdk@1.1.3/dist/index.iife.js"></script>This will expose a function
telegramApps.sdk.retrieveLaunchParams()
that will return the launch parameters from the Telegram mini-app. -
Add a Json library file
Telegram.jslib
. This file will serve as a bridge between the Unity script and the Telegram SDK. -
Import the InitTelegramApp function in your Unity script.
-
Authenticate with Telegram mini app token using the Openfort SDK.
Using Telegram mini-app as a third-party provider, your token is the Telegram mini-app initData. You can use this token to authenticate with the Openfort SDK.
Using the Telegram mini-app as a third-party provider, openfort.GetAccessToken()
is not available. Your access token is the Telegram mini-app initData.