feat: payload для /start в ботах.

This commit is contained in:
Jganenokk
2026-07-30 18:39:31 +07:00
parent 8f42692708
commit f6de41f11d
13 changed files with 483 additions and 38 deletions
+4
View File
@@ -429,6 +429,8 @@ class LocationAttachment extends MessageAttachment {
}
class ControlAttachment extends MessageAttachment {
static const String botStartedEvent = 'botStarted';
final String? event;
final String? title;
final List<int>? userIds;
@@ -444,6 +446,8 @@ class ControlAttachment extends MessageAttachment {
this.userId,
}) : super(type: AttachmentType.control);
bool get isBotStart => event == botStartedEvent;
factory ControlAttachment.fromMap(Map<String, dynamic> map) {
String? title = map['title']?.toString();
if ((title == null || title.isEmpty) && map['shortMessage'] != null) {
+48
View File
@@ -0,0 +1,48 @@
import 'contact_info.dart';
class BotCommand {
final String name;
final String? description;
const BotCommand({required this.name, this.description});
factory BotCommand.fromMap(Map map) => BotCommand(
name: map['name']?.toString() ?? '',
description: (map['description'] as String?)?.trim().isNotEmpty == true
? (map['description'] as String).trim()
: null,
);
String get slash => '/$name';
}
class BotInfo {
final int botId;
final List<BotCommand> commands;
final ContactInfo? contact;
const BotInfo({required this.botId, required this.commands, this.contact});
factory BotInfo.fromPayload(int botId, Map<String, dynamic> payload) {
final rawCommands = payload['commands'];
final commands = <BotCommand>[];
if (rawCommands is List) {
for (final c in rawCommands.whereType<Map>()) {
final command = BotCommand.fromMap(c);
if (command.name.isNotEmpty) commands.add(command);
}
}
final rawContact = payload['contact'];
return BotInfo(
botId: botId,
commands: commands,
contact: rawContact is Map
? ContactInfo.fromMap(Map<String, dynamic>.from(rawContact))
: null,
);
}
String? get description => contact?.raw['description'] as String?;
String? get link => contact?.raw['link'] as String?;
}