create method
Future<ApiResponseModel<CampaignModel?> >
create({
- required String text,
- required String senderId,
- String? name,
- List<
ContactModel> ? contacts = const [], - List<
String> ? groupsIds = const [], - SMSType? type = SMSType.sms,
- DateTime? scheduledDate,
- CampaignRecurringDayModel? recurring,
Creates a new campaign.
name is the name of the campaign.
contacts is the optional list of contacts for the campaign.
groupsIds is the optional list of group IDs for the campaign.
text is the optional text content of the campaign.
senderId is the optional sender ID for the campaign.
type is the optional SMS type (default: sms).
forceSenderId is whether to force the sender ID (default: false).
Returns the created CampaignModel instance.
Implementation
Future<ApiResponseModel<CampaignModel?>> create({
required String text,
required String senderId,
String? name,
List<ContactModel>? contacts = const [],
List<String>? groupsIds = const [],
SMSType? type = SMSType.sms,
DateTime? scheduledDate,
CampaignRecurringDayModel? recurring,
}) async {
final url = "$_baseUrl/campaign/create";
final payload = {
'name': name,
'contacts': contacts?.map((e) => e.toJson()).toList() ?? [],
'groupsIds': groupsIds ?? [],
'text': text,
'senderId': senderId,
if (type != null) 'type': type.value,
if (scheduledDate != null)
'scheduledDate': scheduledDate.toIso8601String(),
if (recurring != null) 'recurring': recurring.toJson(),
};
debugPrint("flutter_mon_sms_pro/campaign/create/payload: $payload");
final r = await _dio.post(url, data: {
...payload,
"apiKey": _apiKey,
});
debugPrint("flutter_mon_sms_pro/campaign/create/data: ${r.data}");
final response = ApiResponseModel.fromJson(
r.data, (data) => CampaignModel.fromJson(data as Map<String, dynamic>));
return response;
}