deleteChatSession method

Future deleteChatSession({
  1. required String org,
  2. required String userId,
  3. required String? sessionId,
})

Implementation

Future<dynamic> deleteChatSession(
    {required String org,
    required String userId,
    required String? sessionId}) async {
  // Construct the full URL for the DELETE request
  final String url =
      '$dataBaseUrl/api/ai/mentor/orgs/$org/users/$userId/sessions/$sessionId/';

  // Prepare the headers
  Map<String, String> headers = _headers();

  // Execute the DELETE request
  final response = await http.delete(
    Uri.parse(url),
    headers: headers,
  );

  // Check the response status code and handle accordingly
  if (response.statusCode == 204) {
    // Successfully deleted with no content in the response body
    print('Chat session deleted successfully');
  } else {
    // If the server did not return a 204 No Content response,
    // then throw an exception.
    throw Exception(
        'Failed to delete chat session. Status code: ${response.statusCode}');
  }
}