sendSms method
Send SMS messages
Implementation
Future<Map<String, dynamic>> sendSms({
required String message,
required List<String> numbers,
required String sender,
}) async {
final result = {
'success': true,
'total_success': 0,
'total_failed': 0,
'job_ids': <String>[],
'errors': <String, List<String>>{},
};
try {
final response = await _client.post(
Uri.parse('$_apiBaseUrl/account/area/sms/send'),
headers: _headers,
body: jsonEncode({
'app': _appType,
'ver': _appVersion,
'messages': [
{
'text': message,
'numbers': numbers,
'sender': sender,
}
],
}),
);
final data = jsonDecode(response.body);
result['total_success'] = numbers.length;
if (data['job_id'] != null) {
(result['job_ids'] as List<String>).add(data['job_id']);
}
} catch (e) {
result['success'] = false;
result['total_failed'] = numbers.length;
(result['errors'] as Map<String, List<String>>)[e.toString()] = numbers;
}
return result;
}