chat support
This commit is contained in:
41
lib/services/chat_service.dart
Normal file
41
lib/services/chat_service.dart
Normal file
@@ -0,0 +1,41 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import '../config/api_config.dart';
|
||||
|
||||
class ChatService {
|
||||
final Dio dio;
|
||||
|
||||
ChatService(this.dio);
|
||||
|
||||
/// Start chat / get ticket
|
||||
Future<Map<String, dynamic>> startChat() async {
|
||||
final res = await dio.get('/user/chat/start');
|
||||
return Map<String, dynamic>.from(res.data);
|
||||
}
|
||||
|
||||
/// Get all messages
|
||||
Future<List<dynamic>> getMessages(int ticketId) async {
|
||||
final res = await dio.get('/user/chat/messages/$ticketId');
|
||||
return res.data['messages'];
|
||||
}
|
||||
|
||||
/// Send message (text or file)
|
||||
Future<void> sendMessage(
|
||||
int ticketId, {
|
||||
String? message,
|
||||
String? filePath,
|
||||
}) async {
|
||||
final form = FormData();
|
||||
|
||||
if (message != null) form.fields.add(MapEntry('message', message));
|
||||
if (filePath != null) {
|
||||
form.files.add(
|
||||
MapEntry(
|
||||
'file',
|
||||
await MultipartFile.fromFile(filePath),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
await dio.post('/user/chat/send/$ticketId', data: form);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user