parse static method
A Calloop call push, or null for anything else (chat messages, …).
Implementation
static CalloopPush? parse(Map<dynamic, dynamic> data) {
final d = {for (final e in data.entries) '${e.key}': e.value};
final type = switch (d['type']?.toString()) {
'call.incoming' => CalloopPushType.incoming,
'call.cancelled' => CalloopPushType.cancelled,
'call.incoming.alert' => CalloopPushType.alert,
_ => null,
};
final callId = d['call_id']?.toString() ?? d['callId']?.toString();
if (type == null || callId == null || callId.isEmpty) return null;
String? s(List<String> keys) {
for (final k in keys) {
final v = d[k];
if (v != null && '$v'.isNotEmpty) return '$v';
}
return null;
}
return CalloopPush(
type: type,
callId: callId,
callUuid: s(['call_uuid', 'id']),
tenantId: s(['tenant_id']),
channel: s(['channel']),
customerName: s(['customer_name', 'nameCaller']),
customerAddress: s(['customer_address', 'handle']),
raw: Map<String, dynamic>.from(d),
);
}