feat: js бриджы для вебапов
This commit is contained in:
@@ -21,8 +21,21 @@ bool hasMiniAppOption(Set<String>? options) =>
|
||||
class WebAppLaunch {
|
||||
final String url;
|
||||
final String? queryId;
|
||||
final int botId;
|
||||
|
||||
const WebAppLaunch({required this.url, this.queryId});
|
||||
const WebAppLaunch({required this.url, required this.botId, this.queryId});
|
||||
}
|
||||
|
||||
class WebAppPhone {
|
||||
final String phone;
|
||||
final String hash;
|
||||
final int authDate;
|
||||
|
||||
const WebAppPhone({
|
||||
required this.phone,
|
||||
required this.hash,
|
||||
required this.authDate,
|
||||
});
|
||||
}
|
||||
|
||||
class ExternalCallbackResult {
|
||||
@@ -52,12 +65,12 @@ class ExternalCallbackResult {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static int? _asInt(dynamic value) {
|
||||
if (value is int) return value;
|
||||
if (value is num) return value.toInt();
|
||||
return int.tryParse(value?.toString() ?? '');
|
||||
}
|
||||
int? _asInt(dynamic value) {
|
||||
if (value is int) return value;
|
||||
if (value is num) return value.toInt();
|
||||
return int.tryParse(value?.toString() ?? '');
|
||||
}
|
||||
|
||||
class WebAppModule {
|
||||
@@ -93,7 +106,32 @@ class WebAppModule {
|
||||
throw const WebAppUnavailable('Сервер не вернул адрес приложения');
|
||||
}
|
||||
final queryId = (data is Map) ? data['query_id']?.toString() : null;
|
||||
return WebAppLaunch(url: url, queryId: queryId);
|
||||
return WebAppLaunch(url: url, botId: botId, queryId: queryId);
|
||||
}
|
||||
|
||||
Future<WebAppPhone> requestPhone(int botId) async {
|
||||
if (_api.state != SessionState.online) {
|
||||
throw const WebAppUnavailable('Нет соединения с сервером');
|
||||
}
|
||||
final packet = await _api.sendRequest(Opcode.phoneWebappShare, {
|
||||
'botId': botId,
|
||||
});
|
||||
final data = packet.payload;
|
||||
if (!packet.isOk || data is! Map) {
|
||||
throw const WebAppUnavailable('Не удалось передать номер телефона');
|
||||
}
|
||||
final phone = data['phone']?.toString();
|
||||
final hash = data['hash']?.toString();
|
||||
final authDate = _asInt(data['authDate'] ?? data['auth_date']);
|
||||
if (phone == null ||
|
||||
phone.isEmpty ||
|
||||
hash == null ||
|
||||
hash.isEmpty ||
|
||||
authDate == null ||
|
||||
authDate == 0) {
|
||||
throw const WebAppUnavailable('Сервер не вернул номер телефона');
|
||||
}
|
||||
return WebAppPhone(phone: phone, hash: hash, authDate: authDate);
|
||||
}
|
||||
|
||||
Future<WebAppLaunch> fetchSferum() async {
|
||||
|
||||
Reference in New Issue
Block a user