Thank you Jacob,
It´s what I´ve finally done. I tried to emulate exactly the fields of the json file, but I don´t know if I have all the fields covered. This is what I´ve done:
private static void CreateMetadataFile(AnalyticsConversationWithoutAttributes conversation, string path, string ext,RecordingMetadata recMetadata, Recording rec)
{
AnalyticsSession session = conversation.Participants.SelectMany(c => c.Sessions).Where(a => a.SessionId == rec.SessionId).FirstOrDefault();
Metadata mdata = new Metadata()
{
mediaType = recMetadata.Media,
provider = ( session != null ) ? session.Provider : null,
userIds = conversation.Participants.Where(c => c.Sessions.Any(b => b.SessionId == recMetadata.SessionId)).Where(c => c.UserId != null).Select(c => c.UserId).ToList(),
startTime = rec.StartTime,
endTime = rec.EndTime,
durationMs = rec.ActualTranscodeTimeMs.HasValue ? rec.ActualTranscodeTimeMs.Value : 0,
initialDirection = conversation.OriginatingDirection.HasValue ? conversation.OriginatingDirection.Value.ToString() : "",
aniNormalized = (session != null) ? session.Ani : "",
aniDisplayable = (session != null && session.Ani != null ) ? "unavailable": null,
dnisNormalized = (session != null) ? session.Dnis : "",
dnisDisplayable = (session != null && session.Dnis != null) ? "unavailable" : null,
queueIds = (session != null) ? session.Segments.Select(a => a.QueueId).Distinct().ToList() : null,
wrapupCodes = (session != null ) ? session.Segments.Where(a => a.SegmentType == AnalyticsConversationSegment.SegmentTypeEnum.Wrapup).Select(a => a.WrapUpCode).ToList() : null,
organizationId = strOrganizationId,
conversationId = conversation.ConversationId,
conversationStartTime = conversation.ConversationStart.Value.ToString(strFormat, CultureInfo.CurrentCulture),
conversationEndTime = conversation.ConversationEnd.Value.ToString(strFormat, CultureInfo.CurrentCulture),
recordingId = recMetadata.Id,
filePath = string.Format("s3://{0}/{1}/year={2}/month={3}/day={4}/hour={5}/conversation_id={6}/{7}.{8}", bucketName, strOrganizationId, conversation.ConversationStart.Value.Year, conversation.ConversationStart.Value.Month, conversation.ConversationStart.Value.Day, conversation.ConversationStart.Value.Hour, conversation.ConversationId, recMetadata.Id, ext),
fileSize = new FileInfo("." + path + "\" + recMetadata.Id + "." + ext).Length,
screenInformation = null
};
//mdata.queueIds = (session != null) ? session.Segments.Select(a => a.QueueId).Distinct().ToList() : null;
//mdata.wrapupCodes = (session != null) ? session.Segments.Where(a => a.SegmentType == AnalyticsConversationSegment.SegmentTypeEnum.Wrapup).Select(a => a.WrapUpCode).ToList() : null;
var settings = new JsonSerializerSettings()
{
ContractResolver = new NullToEmptyObjectResolver(typeof(ScreenInformation))
};
var str = JsonConvert.SerializeObject(mdata, settings);
using (StreamWriter file = File.CreateText("." + path + "\" + recMetadata.Id + "." + ext + "_metadata.json"))
{
//JsonSerializer serializer = new JsonSerializer();
//serializer.Serialize(file, mdata);
file.Write(str);
file.Close();
}
}
As you have seen the AniDisplayable and DnisDisplayable is set to unavailable if the AniNormalized and DnisNormalized is not present. That´s because I didn´t figure how to obtain this fields in conversation object response.
As this file is generated by the API genesys when exported to S3, it would be great that it could be accesible in the API to be invoked.
Regards,
David Garcia