-
-
Notifications
You must be signed in to change notification settings - Fork 0
6. API Reference
RAprogramm edited this page Nov 4, 2025
·
1 revision
Comprehensive API reference organized by feature.
use telegram_webapp_sdk::api::user;
user::request_contact(move |contact_requested| {
if contact_requested {
// User shared contact
}
});user::request_phone_number(move |phone_requested| {
if phone_requested {
// User shared phone
}
});use telegram_webapp_sdk::api::cloud_storage;
// Set item
cloud_storage::set_item("key", "value", |success| {
if success {
// Saved
}
}).await;
// Get item
cloud_storage::get_item("key", |value| {
if let Some(val) = value {
// Retrieved
}
}).await;use telegram_webapp_sdk::api::device_storage;
// Save
device_storage::set("key", "value");
// Load
if let Some(value) = device_storage::get("key") {
// Use value
}use telegram_webapp_sdk::api::secure_storage;
// Save securely
secure_storage::set("api_key", "secret", |success| {
// Saved
}).await;
// Retrieve
secure_storage::get("api_key", |value| {
// Use secret
}).await;use telegram_webapp_sdk::api::biometric;
// Initialize biometric manager
biometric::init(|initialized| {
if initialized {
// Request access
biometric::request_access("Unlock app", |granted| {
if granted {
// Authenticate
biometric::authenticate("Verify identity", |authenticated| {
if authenticated {
// Access granted
}
});
}
});
}
}).await;use telegram_webapp_sdk::api::accelerometer;
// Start
accelerometer::start(100, |started| {
if started {
// Read values
if let Some(accel) = accelerometer::get_acceleration() {
println!("X: {}, Y: {}, Z: {}", accel.x, accel.y, accel.z);
}
}
});
// Stop
accelerometer::stop();use telegram_webapp_sdk::api::gyroscope;
gyroscope::start(100, |started| {
if started {
if let Some(gyro) = gyroscope::get_angular_velocity() {
println!("X: {}, Y: {}, Z: {}", gyro.x, gyro.y, gyro.z);
}
}
});use telegram_webapp_sdk::api::device_orientation;
device_orientation::start(100, |started| {
if started {
if let Some(orient) = device_orientation::get_orientation() {
println!("Alpha: {}, Beta: {}, Gamma: {}", orient.alpha, orient.beta, orient.gamma);
}
}
});use telegram_webapp_sdk::api::location_manager;
// Initialize
location_manager::init(|initialized| {
if initialized {
// Get location
location_manager::get_location(|location| {
if let Some(loc) = location {
println!("Lat: {}, Lon: {}", loc.latitude, loc.longitude);
}
});
}
}).await;use telegram_webapp_sdk::api::haptic;
// Impact
haptic::impact_occurred("medium"); // light, medium, heavy, rigid, soft
// Notification
haptic::notification_occurred("success"); // error, success, warning
// Selection changed
haptic::selection_changed();use telegram_webapp_sdk::api::theme;
// Set colors
theme::set_header_color("#FF0000");
theme::set_background_color("#FFFFFF");
theme::set_bottom_bar_color("#000000");use telegram_webapp_sdk::api::viewport;
// Expand to full height
viewport::expand_viewport();
// Get dimensions
let height = viewport::get_viewport_height();
let stable_height = viewport::get_viewport_stable_height();
let width = viewport::get_viewport_width();