Skip to content

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

PropertyTypeDescription
isInitedBooleanWhether the location manager is initialized
isLocationAvailableBooleanWhether the device supports location services
isAccessRequestedBooleanWhether location permission has been requested
isAccessGrantedBooleanWhether location permission has been granted

Methods

init

javascript
Telegram.WebApp.LocationManager.init(callback)

Initializes the location manager.

ParameterTypeRequiredDescription
callbackFunctionNoInitialization complete callback

getLocation

javascript
Telegram.WebApp.LocationManager.getLocation(callback)

Gets the current location.

ParameterTypeRequiredDescription
callbackFunctionYesCallback 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().

FieldTypeDescription
latitudeFloatLatitude
longitudeFloatLongitude
altitudeFloat | nullAltitude in meters, null if unavailable
courseFloat | nullDirection of movement (0-360°), null if unavailable
speedFloat | nullSpeed of movement (m/s), null if unavailable
horizontal_accuracyFloat | nullHorizontal accuracy in meters
vertical_accuracyFloat | nullVertical accuracy in meters
course_accuracyFloat | nullCourse accuracy in degrees
speed_accuracyFloat | nullSpeed accuracy (m/s)

BiometricManager

The biometric manager provides fingerprint and face recognition authentication. Accessed via Telegram.WebApp.BiometricManager. Bot API 7.2+

Properties

PropertyTypeDescription
isInitedBooleanWhether the manager is initialized
isBiometricAvailableBooleanWhether the device supports biometrics
biometricTypeStringBiometric type: "finger" (fingerprint), "face" (face), or empty string
isAccessRequestedBooleanWhether biometric permission has been requested
isAccessGrantedBooleanWhether biometric permission has been granted
isBiometricTokenSavedBooleanWhether a biometric token is saved
deviceIdStringUnique device identifier

Methods

init

javascript
Telegram.WebApp.BiometricManager.init(callback)

Initializes the biometric manager.

ParameterTypeRequiredDescription
callbackFunctionNoInitialization complete callback

requestAccess

javascript
Telegram.WebApp.BiometricManager.requestAccess(params, callback)

Requests biometric permission.

ParameterTypeRequiredDescription
paramsObjectNoParameters
params.reasonStringNoReason for requesting permission
callbackFunctionNoCallback with (granted) parameter

authenticate

javascript
Telegram.WebApp.BiometricManager.authenticate(params, callback)

Initiates biometric authentication.

ParameterTypeRequiredDescription
paramsObjectNoParameters
params.reasonStringNoAuthentication reason description
callbackFunctionNoCallback with (authenticated, token) parameters

updateBiometricToken

javascript
Telegram.WebApp.BiometricManager.updateBiometricToken(token, callback)

Updates the biometric token stored on the device.

ParameterTypeRequiredDescription
tokenStringYesNew token value, pass empty string to delete
callbackFunctionNoCallback 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');
  }
});