Location & Biometric
Mini Apps provide location access and biometric authentication capabilities.
LocationManager
The location manager is used to obtain the user's geographic location. Accessed via Telegram.WebApp.LocationManager. Bot API 8.0+
Properties
| Property | Type | Description |
|---|---|---|
isInited | Boolean | Whether the location manager is initialized |
isLocationAvailable | Boolean | Whether the device supports location services |
isAccessRequested | Boolean | Whether location permission has been requested |
isAccessGranted | Boolean | Whether location permission has been granted |
Methods
init
javascript
Telegram.WebApp.LocationManager.init(callback)Initializes the location manager.
| Parameter | Type | Required | Description |
|---|---|---|---|
| callback | Function | No | Initialization complete callback |
getLocation
javascript
Telegram.WebApp.LocationManager.getLocation(callback)Gets the current location.
| Parameter | Type | Required | Description |
|---|---|---|---|
| callback | Function | Yes | Callback with LocationData object, null on failure |
openSettings
javascript
Telegram.WebApp.LocationManager.openSettings()Opens the location permission settings page to guide the user to grant access.
Example
javascript
const locationMgr = Telegram.WebApp.LocationManager;
locationMgr.init(() => {
if (locationMgr.isLocationAvailable) {
locationMgr.getLocation((location) => {
if (location) {
console.log(`Latitude: ${location.latitude}`);
console.log(`Longitude: ${location.longitude}`);
console.log(`Accuracy: ${location.accuracy}m`);
} else {
console.log('Unable to get location');
}
});
} else {
console.log('Device does not support location services');
}
});LocationData
Location data object returned by LocationManager.getLocation().
| Field | Type | Description |
|---|---|---|
latitude | Float | Latitude |
longitude | Float | Longitude |
altitude | Float | null | Altitude in meters, null if unavailable |
course | Float | null | Direction of movement (0-360°), null if unavailable |
speed | Float | null | Speed of movement (m/s), null if unavailable |
horizontal_accuracy | Float | null | Horizontal accuracy in meters |
vertical_accuracy | Float | null | Vertical accuracy in meters |
course_accuracy | Float | null | Course accuracy in degrees |
speed_accuracy | Float | null | Speed accuracy (m/s) |
BiometricManager
The biometric manager provides fingerprint and face recognition authentication. Accessed via Telegram.WebApp.BiometricManager. Bot API 7.2+
Properties
| Property | Type | Description |
|---|---|---|
isInited | Boolean | Whether the manager is initialized |
isBiometricAvailable | Boolean | Whether the device supports biometrics |
biometricType | String | Biometric type: "finger" (fingerprint), "face" (face), or empty string |
isAccessRequested | Boolean | Whether biometric permission has been requested |
isAccessGranted | Boolean | Whether biometric permission has been granted |
isBiometricTokenSaved | Boolean | Whether a biometric token is saved |
deviceId | String | Unique device identifier |
Methods
init
javascript
Telegram.WebApp.BiometricManager.init(callback)Initializes the biometric manager.
| Parameter | Type | Required | Description |
|---|---|---|---|
| callback | Function | No | Initialization complete callback |
requestAccess
javascript
Telegram.WebApp.BiometricManager.requestAccess(params, callback)Requests biometric permission.
| Parameter | Type | Required | Description |
|---|---|---|---|
| params | Object | No | Parameters |
| params.reason | String | No | Reason for requesting permission |
| callback | Function | No | Callback with (granted) parameter |
authenticate
javascript
Telegram.WebApp.BiometricManager.authenticate(params, callback)Initiates biometric authentication.
| Parameter | Type | Required | Description |
|---|---|---|---|
| params | Object | No | Parameters |
| params.reason | String | No | Authentication reason description |
| callback | Function | No | Callback with (authenticated, token) parameters |
updateBiometricToken
javascript
Telegram.WebApp.BiometricManager.updateBiometricToken(token, callback)Updates the biometric token stored on the device.
| Parameter | Type | Required | Description |
|---|---|---|---|
| token | String | Yes | New token value, pass empty string to delete |
| callback | Function | No | Callback with (updated) parameter |
openSettings
javascript
Telegram.WebApp.BiometricManager.openSettings()Opens the biometric permission settings page.
Example
javascript
const bioMgr = Telegram.WebApp.BiometricManager;
bioMgr.init(() => {
if (!bioMgr.isBiometricAvailable) {
console.log('Device does not support biometrics');
return;
}
console.log('Biometric type:', bioMgr.biometricType);
// Request permission
bioMgr.requestAccess({ reason: 'For identity verification' }, (granted) => {
if (granted) {
// Initiate authentication
bioMgr.authenticate({ reason: 'Please verify your identity' }, (authenticated, token) => {
if (authenticated) {
console.log('Authentication successful');
if (token) {
console.log('Token:', token);
}
} else {
console.log('Authentication failed');
}
});
}
});
});
// Save token for future use
bioMgr.updateBiometricToken('my-secure-token', (updated) => {
if (updated) {
console.log('Token saved');
}
});