All checks were successful
Create Release / build (push) Successful in 6s
Server-side: - Add push credential auto-creation for FCM incoming call notifications - Add queue alert FCM notifications (data-only for background delivery) - Add queue alert cancellation on call accept/disconnect - Fix caller ID to show caller's number instead of Twilio number - Fix FCM token storage when refresh_token is null - Add pre_call_status tracking to revert agent status 30s after call ends - Add SSE fallback polling for mobile app connectivity Mobile app: - Add Android telecom permissions and phone account registration - Add VoiceFirebaseMessagingService for incoming call push handling - Add insistent queue alert notifications with custom sound - Fix caller number display on active call screen - Add caller ID selection dropdown on dashboard - Add phone numbers endpoint and provider support - Add unit tests for CallInfo, QueueState, and CallProvider - Remove local.properties from tracking, add .gitignore Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
133 lines
3.6 KiB
Dart
133 lines
3.6 KiB
Dart
import 'dart:async';
|
|
import 'package:dio/dio.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
import '../models/agent_status.dart';
|
|
import '../models/queue_state.dart';
|
|
import '../services/api_client.dart';
|
|
import '../services/sse_service.dart';
|
|
|
|
class PhoneNumber {
|
|
final String phoneNumber;
|
|
final String friendlyName;
|
|
PhoneNumber({required this.phoneNumber, required this.friendlyName});
|
|
factory PhoneNumber.fromJson(Map<String, dynamic> json) => PhoneNumber(
|
|
phoneNumber: json['phone_number'] as String,
|
|
friendlyName: json['friendly_name'] as String,
|
|
);
|
|
}
|
|
|
|
class AgentProvider extends ChangeNotifier {
|
|
final ApiClient _api;
|
|
final SseService _sse;
|
|
|
|
AgentStatus? _status;
|
|
List<QueueInfo> _queues = [];
|
|
bool _sseConnected = false;
|
|
List<PhoneNumber> _phoneNumbers = [];
|
|
StreamSubscription? _sseSub;
|
|
StreamSubscription? _connSub;
|
|
Timer? _refreshTimer;
|
|
|
|
AgentStatus? get status => _status;
|
|
List<QueueInfo> get queues => _queues;
|
|
bool get sseConnected => _sseConnected;
|
|
List<PhoneNumber> get phoneNumbers => _phoneNumbers;
|
|
|
|
AgentProvider(this._api, this._sse) {
|
|
_connSub = _sse.connectionState.listen((connected) {
|
|
_sseConnected = connected;
|
|
notifyListeners();
|
|
});
|
|
|
|
_sseSub = _sse.events.listen(_handleSseEvent);
|
|
|
|
_refreshTimer = Timer.periodic(
|
|
const Duration(seconds: 15),
|
|
(_) => fetchQueues(),
|
|
);
|
|
}
|
|
|
|
Future<void> fetchStatus() async {
|
|
try {
|
|
final response = await _api.dio.get('/agent/status');
|
|
_status = AgentStatus.fromJson(response.data);
|
|
notifyListeners();
|
|
} catch (e) {
|
|
debugPrint('AgentProvider.fetchStatus error: $e');
|
|
if (e is DioException) debugPrint(' response: ${e.response?.data}');
|
|
}
|
|
}
|
|
|
|
Future<void> updateStatus(AgentStatusValue newStatus) async {
|
|
final statusStr = newStatus.name;
|
|
try {
|
|
await _api.dio.post('/agent/status', data: {
|
|
'status': statusStr,
|
|
'is_logged_in': true,
|
|
});
|
|
_status = AgentStatus(
|
|
status: newStatus,
|
|
isLoggedIn: true,
|
|
currentCallSid: _status?.currentCallSid,
|
|
);
|
|
notifyListeners();
|
|
} catch (e) {
|
|
debugPrint('AgentProvider.updateStatus error: $e');
|
|
if (e is DioException) {
|
|
debugPrint('AgentProvider.updateStatus response: ${e.response?.data}');
|
|
}
|
|
}
|
|
}
|
|
|
|
Future<void> fetchQueues() async {
|
|
try {
|
|
final response = await _api.dio.get('/queues/state');
|
|
final data = response.data;
|
|
_queues = (data['queues'] as List)
|
|
.map((q) => QueueInfo.fromJson(q as Map<String, dynamic>))
|
|
.toList();
|
|
notifyListeners();
|
|
} catch (e) {
|
|
debugPrint('AgentProvider.fetchQueues error: $e');
|
|
if (e is DioException) debugPrint(' response: ${e.response?.data}');
|
|
}
|
|
}
|
|
|
|
Future<void> fetchPhoneNumbers() async {
|
|
try {
|
|
final response = await _api.dio.get('/phone-numbers');
|
|
final data = response.data;
|
|
_phoneNumbers = (data['phone_numbers'] as List)
|
|
.map((p) => PhoneNumber.fromJson(p as Map<String, dynamic>))
|
|
.toList();
|
|
notifyListeners();
|
|
} catch (e) {
|
|
debugPrint('AgentProvider.fetchPhoneNumbers error: $e');
|
|
}
|
|
}
|
|
|
|
Future<void> refresh() async {
|
|
await Future.wait([fetchStatus(), fetchQueues(), fetchPhoneNumbers()]);
|
|
}
|
|
|
|
void _handleSseEvent(SseEvent event) {
|
|
switch (event.event) {
|
|
case 'call_enqueued':
|
|
case 'call_dequeued':
|
|
fetchQueues();
|
|
break;
|
|
case 'agent_status_changed':
|
|
fetchStatus();
|
|
break;
|
|
}
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_refreshTimer?.cancel();
|
|
_sseSub?.cancel();
|
|
_connSub?.cancel();
|
|
super.dispose();
|
|
}
|
|
}
|