feat: Implement messaging functionality with conversation and chat screens, and enhance agent detail views.

This commit is contained in:
pradeepkumar
2026-03-08 00:41:44 +05:30
parent bdb7b04fbf
commit bba9cd3936
23 changed files with 4402 additions and 3 deletions

View File

@@ -108,6 +108,93 @@ class AgentsRepository {
}
}
/// Get agent by ID: GET /agents/{id}
/// Response: { success, data: AgentProfile }
Future<AgentProfile> getAgentById(String id) async {
try {
final response = await _dio.get('${ApiConstants.agents}/$id');
final data = response.data['data'] as Map<String, dynamic>;
return AgentProfile.fromJson(data);
} on DioException catch (e) {
if (e.error is ApiException) throw e.error as ApiException;
throw ApiException(
message: e.message ?? 'Failed to fetch agent',
statusCode: e.response?.statusCode,
);
}
}
/// Get field values for agent: GET /agents/{id}/field-values
/// Response: { success, data: { agentProfileId, fieldValues: [...] } }
Future<List<AgentFieldValue>> getFieldValues(String agentId) async {
try {
final response =
await _dio.get('${ApiConstants.agents}/$agentId/field-values');
final data = response.data['data'] as Map<String, dynamic>;
final fieldValues = data['fieldValues'] as List<dynamic>? ?? [];
return fieldValues
.map((e) => AgentFieldValue.fromFieldValueResponse(
e as Map<String, dynamic>))
.toList();
} on DioException catch (e) {
if (e.error is ApiException) throw e.error as ApiException;
throw ApiException(
message: e.message ?? 'Failed to fetch field values',
statusCode: e.response?.statusCode,
);
}
}
/// Get testimonials for agent: GET /testimonials/agent/{agentProfileId}
Future<List<Map<String, dynamic>>> getTestimonials(String agentId,
{int limit = 10}) async {
try {
final response = await _dio.get(
'${ApiConstants.testimonials}/agent/$agentId',
queryParameters: {'limit': limit},
);
final data = response.data['data'] as List<dynamic>? ?? [];
return data.cast<Map<String, dynamic>>();
} on DioException catch (_) {
return [];
}
}
/// Get connection status: GET /connection-requests/status/{agentProfileId}
Future<Map<String, dynamic>?> getConnectionStatus(String agentId) async {
try {
final response = await _dio
.get('${ApiConstants.connectionRequests}/status/$agentId');
return response.data['data'] as Map<String, dynamic>?;
} on DioException catch (_) {
return null;
}
}
/// Create connection request: POST /connection-requests
Future<bool> createConnectionRequest(String agentId,
{String? message}) async {
try {
await _dio.post(ApiConstants.connectionRequests, data: {
'agentProfileId': agentId,
if (message != null && message.isNotEmpty) 'message': message,
});
return true;
} on DioException catch (_) {
return false;
}
}
/// Cancel connection request: DELETE /connection-requests/{requestId}
Future<bool> cancelConnectionRequest(String requestId) async {
try {
await _dio.delete('${ApiConstants.connectionRequests}/$requestId');
return true;
} on DioException catch (_) {
return false;
}
}
/// Get agent types: GET /agent-types
/// Response: { success, data: [...] }
Future<List<AgentType>> getAgentTypes() async {