CapturePerceptCommRequest function
Future<void>
CapturePerceptCommRequest(
- PerceptCommunicationState commState,
- Map<
String, dynamic> message, - String piToken
Implementation
Future<void> CapturePerceptCommRequest(
PerceptCommunicationState commState,
Map<String, dynamic> message,
String piToken,
) async {
Debug.print("Communication Request Initiate: $commState $message");
if (message.isEmpty) return;
try {
final remoteMessage = RemoteMessage.fromMap(message);
final remoteMessageJson = remoteMessage.toMap();
Debug.print("PN remote message json: ${jsonEncode(remoteMessageJson)}");
if (!checkIsPnSentFromPercept(remoteMessageJson)) return;
Map<String, dynamic> propertiesToSend = {};
if (remoteMessageJson['pi_pn_metaData'] != null) {
final decodedMetaData = jsonDecode(remoteMessageJson['pi_pn_metaData'])
as Map<String, dynamic>;
if (decodedMetaData.isNotEmpty) {
propertiesToSend.addAll(decodedMetaData);
}
}
final commonProperties =
await TrackingDataProvider.instance.getCommonTrackingData();
propertiesToSend.addAll(commonProperties);
final commRequest = CommunicationRequest.makeRequest(
commState.asString,
propertiesToSend,
);
final eventRequest = EventRequest.makeRequest(
commState.asEventString,
{...remoteMessage.getCampaignDetails(), ...propertiesToSend},
);
await Future.wait([
sendCommunicationCaptureRequest([commRequest], piToken),
sendEventRequest([eventRequest], piToken)
]);
} catch (e, s) {
Debug.print("Communication Request Error: $e $s");
}
}