Added flow to sessions and removed ExtractWithAttributes
This commit is contained in:
parent
804b9b2792
commit
d66df080fe
@ -1,67 +0,0 @@
|
|||||||
package models
|
|
||||||
|
|
||||||
import "time"
|
|
||||||
|
|
||||||
type Conversation struct {
|
|
||||||
Address *string
|
|
||||||
DivisionIds *string `gorm:"type:json"`
|
|
||||||
End *time.Time `gorm:"index"`
|
|
||||||
ExternalTag *string
|
|
||||||
Id string `gorm:"primaryKey;index"`
|
|
||||||
MinMos *float32
|
|
||||||
MinRFactor *float32
|
|
||||||
OriginatingDirection *string
|
|
||||||
RecentTransfers *string `gorm:"type:json"`
|
|
||||||
RecordingState *string
|
|
||||||
SecurePause *bool
|
|
||||||
Start *time.Time `gorm:"index"`
|
|
||||||
UtilizationLabelId *string
|
|
||||||
LiveUpdate *time.Time
|
|
||||||
DetailsUpdate *time.Time
|
|
||||||
SemiLiveUpdate *time.Time
|
|
||||||
JobUpdate *time.Time
|
|
||||||
Participants []struct {
|
|
||||||
Address *string
|
|
||||||
Attributes *string `gorm:"type:json"`
|
|
||||||
ConnectedTime *time.Time `gorm:"index"`
|
|
||||||
ConversationId string `gorm:"foreignKey;index"`
|
|
||||||
EndTime *time.Time `gorm:"index"`
|
|
||||||
ExternalContactId *string
|
|
||||||
ExternalContactInitialDivisionId *string
|
|
||||||
Id string `gorm:"primaryKey;index"`
|
|
||||||
MediaRoles *string `gorm:"type:json"`
|
|
||||||
Name *string `gorm:"index"`
|
|
||||||
Purpose *string `gorm:"index"`
|
|
||||||
QueueId *string
|
|
||||||
Wrapup *string `gorm:"type:json"`
|
|
||||||
WrapupExpected *bool
|
|
||||||
WrapupRequired *bool
|
|
||||||
Sessions []struct {
|
|
||||||
Ani string
|
|
||||||
Direction string
|
|
||||||
Dnis string
|
|
||||||
EdgeId string
|
|
||||||
Id string `gorm:"primaryKey;index"`
|
|
||||||
MediaEndpointStats string `gorm:"type:json"`
|
|
||||||
MediaType string
|
|
||||||
Metrics string `gorm:"type:json"`
|
|
||||||
ParticipantId string `gorm:"foreignKey;index"`
|
|
||||||
ProtocolCallId string
|
|
||||||
Provider string
|
|
||||||
Recording bool
|
|
||||||
RemoteNameDisplayable string
|
|
||||||
SessionDnis string
|
|
||||||
Segments []struct {
|
|
||||||
Id string `gorm:"primaryKey;index"`
|
|
||||||
Conference bool
|
|
||||||
DisconnectType string
|
|
||||||
Q850ResponseCodes string `gorm:"type:json"`
|
|
||||||
SegmentEnd time.Time `gorm:"index"`
|
|
||||||
SegmentStart time.Time `gorm:"index"`
|
|
||||||
SegmentType string `gorm:"index"`
|
|
||||||
SessionId string `gorm:"foreignKey"`
|
|
||||||
WrapUpCode string
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -93,6 +93,20 @@ type AnalyticsConversationWithoutAttributes struct {
|
|||||||
Q850ResponseCodes []int `json:"q850ResponseCodes"`
|
Q850ResponseCodes []int `json:"q850ResponseCodes"`
|
||||||
Conference bool `json:"conference"`
|
Conference bool `json:"conference"`
|
||||||
} `json:"segments"`
|
} `json:"segments"`
|
||||||
|
Flow struct {
|
||||||
|
EndingLanguage string `json:"endingLanguage"`
|
||||||
|
EntryReason string `json:"entryReason"`
|
||||||
|
EntryType string `json:"entryType"`
|
||||||
|
ExitReason string `json:"exitReason"`
|
||||||
|
FlowId string `json:"flowId"`
|
||||||
|
FlowName string `json:"flowName"`
|
||||||
|
FlowType string `json:"flowType"`
|
||||||
|
FlowVersion string `json:"flowVersion"`
|
||||||
|
StartingLanguage string `json:"startingLanguage"`
|
||||||
|
TransferTargetAddress string `json:"transferTargetAddress"`
|
||||||
|
TransferTargetName string `json:"transferTargetName"`
|
||||||
|
TransferType string `json:"transferType"`
|
||||||
|
} `json:"flow"`
|
||||||
Metrics []struct {
|
Metrics []struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Value int `json:"value"`
|
Value int `json:"value"`
|
||||||
|
|||||||
@ -15,6 +15,7 @@ type DBSession struct {
|
|||||||
Recording bool
|
Recording bool
|
||||||
RemoteNameDisplayable string
|
RemoteNameDisplayable string
|
||||||
SessionDnis string
|
SessionDnis string
|
||||||
|
Flow string `gorm:"type:json"`
|
||||||
|
|
||||||
Segments []DBSegment `gorm:"foreignKey:SessionId;references:Id"`
|
Segments []DBSegment `gorm:"foreignKey:SessionId;references:Id"`
|
||||||
}
|
}
|
||||||
|
|||||||
250
util/extract.go
250
util/extract.go
@ -70,6 +70,11 @@ func ExtractWithoutAttributes(base models.AnalyticsConversationWithoutAttributes
|
|||||||
metricsBytes = nil
|
metricsBytes = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
flowBytes, err := json.Marshal(sess.Flow)
|
||||||
|
if err != nil {
|
||||||
|
flowBytes = nil
|
||||||
|
}
|
||||||
|
|
||||||
session := models.DBSession{
|
session := models.DBSession{
|
||||||
Ani: sess.ANI,
|
Ani: sess.ANI,
|
||||||
Direction: sess.Direction,
|
Direction: sess.Direction,
|
||||||
@ -85,6 +90,7 @@ func ExtractWithoutAttributes(base models.AnalyticsConversationWithoutAttributes
|
|||||||
Recording: sess.Recording,
|
Recording: sess.Recording,
|
||||||
RemoteNameDisplayable: sess.RemoteNameDisplayable,
|
RemoteNameDisplayable: sess.RemoteNameDisplayable,
|
||||||
SessionDnis: sess.SessionDNIS,
|
SessionDnis: sess.SessionDNIS,
|
||||||
|
Flow: string(flowBytes),
|
||||||
}
|
}
|
||||||
sessions = append(sessions, session)
|
sessions = append(sessions, session)
|
||||||
|
|
||||||
@ -255,125 +261,125 @@ func ExtractLive(base models.NotificationConversationWithAttributes) (models.DBC
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExtractWithAttributes(base models.AnalyticsConversationWithAttributes) (models.DBConversation, []models.DBParticipant, []models.DBSession, []models.DBSegment) {
|
//func ExtractWithAttributes(base models.AnalyticsConversationWithAttributes) (models.DBConversation, []models.DBParticipant, []models.DBSession, []models.DBSegment) {
|
||||||
|
//
|
||||||
var startTime *time.Time
|
// var startTime *time.Time
|
||||||
parsedStartTime, err := time.Parse(time.RFC3339, base.ConversationStart)
|
// parsedStartTime, err := time.Parse(time.RFC3339, base.ConversationStart)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
startTime = nil
|
// startTime = nil
|
||||||
} else {
|
// } else {
|
||||||
startTime = &parsedStartTime
|
// startTime = &parsedStartTime
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
var endTime *time.Time
|
// var endTime *time.Time
|
||||||
parsedEndTime, err := time.Parse(time.RFC3339, base.ConversationEnd)
|
// parsedEndTime, err := time.Parse(time.RFC3339, base.ConversationEnd)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
endTime = nil
|
// endTime = nil
|
||||||
} else {
|
// } else {
|
||||||
endTime = &parsedEndTime
|
// endTime = &parsedEndTime
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
divisionIdsBytes, err := json.Marshal(base.DivisionIds)
|
// divisionIdsBytes, err := json.Marshal(base.DivisionIds)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
divisionIdsBytes = nil
|
// divisionIdsBytes = nil
|
||||||
}
|
// }
|
||||||
divisionIdsBytesStr := string(divisionIdsBytes)
|
// divisionIdsBytesStr := string(divisionIdsBytes)
|
||||||
|
//
|
||||||
conversation := models.DBConversation{
|
// conversation := models.DBConversation{
|
||||||
DivisionIds: &divisionIdsBytesStr,
|
// DivisionIds: &divisionIdsBytesStr,
|
||||||
End: endTime,
|
// End: endTime,
|
||||||
Id: base.ConversationId,
|
// Id: base.ConversationId,
|
||||||
MinMos: &base.MediaStatsMinConversationMos,
|
// MinMos: &base.MediaStatsMinConversationMos,
|
||||||
MinRFactor: &base.MediaStatsMinConversationRFactor,
|
// MinRFactor: &base.MediaStatsMinConversationRFactor,
|
||||||
OriginatingDirection: &base.OriginatingDirection,
|
// OriginatingDirection: &base.OriginatingDirection,
|
||||||
Start: startTime,
|
// Start: startTime,
|
||||||
}
|
// }
|
||||||
var participants []models.DBParticipant
|
// var participants []models.DBParticipant
|
||||||
var sessions []models.DBSession
|
// var sessions []models.DBSession
|
||||||
var segments []models.DBSegment
|
// var segments []models.DBSegment
|
||||||
|
//
|
||||||
for _, p := range base.Participants {
|
// for _, p := range base.Participants {
|
||||||
|
//
|
||||||
attributesBytes, err := json.Marshal(p.Attributes)
|
// attributesBytes, err := json.Marshal(p.Attributes)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
attributesBytes = nil
|
// attributesBytes = nil
|
||||||
}
|
// }
|
||||||
attributesBytesStr := string(attributesBytes)
|
// attributesBytesStr := string(attributesBytes)
|
||||||
|
//
|
||||||
participant := models.DBParticipant{
|
// participant := models.DBParticipant{
|
||||||
ConnectedTime: nil,
|
// ConnectedTime: nil,
|
||||||
ConversationId: base.ConversationId,
|
// ConversationId: base.ConversationId,
|
||||||
EndTime: nil,
|
// EndTime: nil,
|
||||||
ExternalContactId: &p.ExternalContactId,
|
// ExternalContactId: &p.ExternalContactId,
|
||||||
Id: p.ParticipantId,
|
// Id: p.ParticipantId,
|
||||||
Name: &p.ParticipantName,
|
// Name: &p.ParticipantName,
|
||||||
Purpose: &p.Purpose,
|
// Purpose: &p.Purpose,
|
||||||
Attributes: &attributesBytesStr,
|
// Attributes: &attributesBytesStr,
|
||||||
}
|
// }
|
||||||
participants = append(participants, participant)
|
// participants = append(participants, participant)
|
||||||
|
//
|
||||||
for _, sess := range p.Sessions {
|
// for _, sess := range p.Sessions {
|
||||||
mediaEndpointStatsBytes, err := json.Marshal(sess.MediaEndpointStats)
|
// mediaEndpointStatsBytes, err := json.Marshal(sess.MediaEndpointStats)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
mediaEndpointStatsBytes = nil
|
// mediaEndpointStatsBytes = nil
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
metricsBytes, err := json.Marshal(sess.Metrics)
|
// metricsBytes, err := json.Marshal(sess.Metrics)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
metricsBytes = nil
|
// metricsBytes = nil
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
session := models.DBSession{
|
// session := models.DBSession{
|
||||||
Ani: sess.ANI,
|
// Ani: sess.ANI,
|
||||||
Direction: sess.Direction,
|
// Direction: sess.Direction,
|
||||||
Dnis: sess.DNIS,
|
// Dnis: sess.DNIS,
|
||||||
EdgeId: sess.EdgeId,
|
// EdgeId: sess.EdgeId,
|
||||||
Id: fmt.Sprintf("%s_%s", p.ParticipantId, sess.SessionId),
|
// Id: fmt.Sprintf("%s_%s", p.ParticipantId, sess.SessionId),
|
||||||
MediaEndpointStats: string(mediaEndpointStatsBytes),
|
// MediaEndpointStats: string(mediaEndpointStatsBytes),
|
||||||
MediaType: sess.MediaType,
|
// MediaType: sess.MediaType,
|
||||||
Metrics: string(metricsBytes),
|
// Metrics: string(metricsBytes),
|
||||||
ParticipantId: p.ParticipantId,
|
// ParticipantId: p.ParticipantId,
|
||||||
ProtocolCallId: sess.ProtocolCallId,
|
// ProtocolCallId: sess.ProtocolCallId,
|
||||||
Provider: sess.Provider,
|
// Provider: sess.Provider,
|
||||||
Recording: sess.Recording,
|
// Recording: sess.Recording,
|
||||||
RemoteNameDisplayable: sess.RemoteNameDisplayable,
|
// RemoteNameDisplayable: sess.RemoteNameDisplayable,
|
||||||
SessionDnis: sess.SessionDnis,
|
// SessionDnis: sess.SessionDnis,
|
||||||
}
|
// }
|
||||||
sessions = append(sessions, session)
|
// sessions = append(sessions, session)
|
||||||
|
//
|
||||||
for _, seg := range sess.Segments {
|
// for _, seg := range sess.Segments {
|
||||||
|
//
|
||||||
segmentStart, err := time.Parse(time.RFC3339, seg.SegmentStart)
|
// segmentStart, err := time.Parse(time.RFC3339, seg.SegmentStart)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
segmentStart = time.Now()
|
// segmentStart = time.Now()
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
segmentEnd, err := time.Parse(time.RFC3339, seg.SegmentEnd)
|
// segmentEnd, err := time.Parse(time.RFC3339, seg.SegmentEnd)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
segmentEnd = time.Now()
|
// segmentEnd = time.Now()
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
q850ResponseCodesBytes, err := json.Marshal(seg.Q850ResponseCodes)
|
// q850ResponseCodesBytes, err := json.Marshal(seg.Q850ResponseCodes)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
q850ResponseCodesBytes = nil
|
// q850ResponseCodesBytes = nil
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
segment := models.DBSegment{
|
// segment := models.DBSegment{
|
||||||
Id: fmt.Sprintf("%s_%s", session.Id, seg.SegmentType),
|
// Id: fmt.Sprintf("%s_%s", session.Id, seg.SegmentType),
|
||||||
Conference: seg.Conference,
|
// Conference: seg.Conference,
|
||||||
DisconnectType: seg.DisconnectType,
|
// DisconnectType: seg.DisconnectType,
|
||||||
Q850ResponseCodes: string(q850ResponseCodesBytes),
|
// Q850ResponseCodes: string(q850ResponseCodesBytes),
|
||||||
SegmentEnd: segmentEnd,
|
// SegmentEnd: segmentEnd,
|
||||||
SegmentStart: segmentStart,
|
// SegmentStart: segmentStart,
|
||||||
SegmentType: seg.SegmentType,
|
// SegmentType: seg.SegmentType,
|
||||||
SessionId: sess.SessionId,
|
// SessionId: sess.SessionId,
|
||||||
WrapUpCode: seg.WrapUpCode,
|
// WrapUpCode: seg.WrapUpCode,
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
segments = append(segments, segment)
|
// segments = append(segments, segment)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
return conversation, participants, sessions, segments
|
// return conversation, participants, sessions, segments
|
||||||
}
|
//}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user