listActiveAgentSessions method

Future<List<RoomSession>> listActiveAgentSessions(
  1. String projectId
)

Implementation

Future<List<RoomSession>> listActiveAgentSessions(String projectId) async {
  final encodedProjectId = Uri.encodeComponent(projectId);
  final uri = Uri.parse('$baseUrl/accounts/projects/$encodedProjectId/agents/sessions/active');
  final response = await httpClient.get(uri);

  if (response.statusCode >= 400) {
    throw MeshagentException(
      'Failed to list active agent sessions. '
      'Status code: ${response.statusCode}, body: ${response.body}',
    );
  }

  final data = jsonDecode(response.body) as Map<String, dynamic>;
  final list = data['sessions'] as List<dynamic>? ?? [];

  return list.whereType<Map<String, dynamic>>().map(RoomSession.fromJson).toList();
}