Skip to content

Commit

Permalink
WTEL-4393; refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
i.navrotskyj committed Apr 1, 2024
1 parent b8191e7 commit 0ad3a55
Show file tree
Hide file tree
Showing 25 changed files with 529 additions and 344 deletions.
11 changes: 11 additions & 0 deletions model/task.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package model

type TaskToAgent struct {
AttemptId int64 `json:"attempt_id" db:"attempt_id"`
Destination []byte `json:"destination" db:"destination"`
Variables map[string]string `json:"variables" db:"variables"`
Name string `json:"name" db:"name"`
TeamId int `json:"team_id" db:"team_id"`
TeamUpdatedAt int64 `json:"team_updated_at" db:"team_updated_at"`
AgentUpdatedAt int64 `json:"agent_updated_at" db:"agent_updated_at"`
}
99 changes: 0 additions & 99 deletions queue/agent_call.go

This file was deleted.

134 changes: 113 additions & 21 deletions queue/queue_call.go → queue/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package queue

import (
"fmt"
"github.com/webitel/call_center/agent_manager"
"github.com/webitel/call_center/call_manager"
"github.com/webitel/call_center/model"
)
Expand Down Expand Up @@ -39,27 +40,6 @@ func (queue *CallingQueue) SetHoldMusic(callRequest *model.CallRequest) {
}
}

func IsHuman(call call_manager.Call, amd *model.QueueAmdSettings) bool {
if amd == nil || !amd.Enabled {
return true
}

if amd.Ai {
aiAmd := call.AiResult()
if aiAmd.Error != "" || aiAmd.Result == "undefined" {
return true // TODO ?
}
for _, v := range amd.PositiveTags {
if v == aiAmd.Result {
return true
}
}
return false
}

return call.IsHuman()
}

func (queue *CallingQueue) SetAmdCall(callRequest *model.CallRequest, amd *model.QueueAmdSettings, onHuman string) bool {
if amd == nil || !amd.Enabled {
return false
Expand Down Expand Up @@ -121,6 +101,86 @@ func (queue *CallingQueue) NewCall(callRequest *model.CallRequest) (call_manager
return queue.queueManager.callManager.NewCall(callRequest)
}

func (queue *CallingQueue) AgentCallRequest(agent agent_manager.AgentObject, at *agentTeam, attempt *Attempt, apps []*model.CallRequestApplication) *model.CallRequest {
cr := &model.CallRequest{
Endpoints: agent.GetCallEndpoints(),
Strategy: model.CALL_STRATEGY_DEFAULT,
Destination: attempt.Destination(),
Variables: model.UnionStringMaps(
queue.Variables(),
attempt.ExportVariables(),
agent.Variables(),
map[string]string{
//"ignore_early_media": "true",
//"absolute_codec_string": "opus,pcmu,pcma",
//"sip_h_X-Webitel-Display-Direction": "inbound",
//"bypass_media_resume_on_hold": "true",
"hangup_after_bridge": "true",
"ignore_display_updates": "true",
"cc_reporting": fmt.Sprintf("%v", queue.Processing()),
model.CallVariableDomainId: fmt.Sprintf("%v", queue.DomainId()),
model.CallVariableUserId: fmt.Sprintf("%v", agent.UserId()),
"bridge_export_vars": "cc_agent_id",
"sip_h_X-Webitel-Direction": "internal",
"wbt_destination": attempt.Destination(),
"wbt_to_id": fmt.Sprintf("%v", agent.Id()),
"wbt_to_number": agent.CallNumber(),
"wbt_to_name": agent.Name(),
"wbt_to_type": "user", //todo agent ?

"wbt_from_name": attempt.Name(),
"wbt_from_type": "member",
"wbt_from_number": attempt.Destination(),

//"effective_caller_id_name": attempt.Name(),
//"effective_caller_id_number": attempt.Destination(),
//
//"origination_callee_id_name": attempt.Name(),
//"origination_callee_id_number": attempt.Destination(),
"origination_caller_id_name": attempt.Name(),
"origination_caller_id_number": attempt.Destination(),

model.QUEUE_AGENT_ID_FIELD: fmt.Sprintf("%d", agent.Id()),
model.QUEUE_TEAM_ID_FIELD: fmt.Sprintf("%d", at.Id()),
model.QUEUE_NAME_FIELD: queue.Name(),
model.QUEUE_TYPE_NAME_FIELD: queue.TypeName(),
model.QUEUE_ATTEMPT_ID_FIELD: fmt.Sprintf("%d", attempt.Id()),
},
),
Timeout: at.CallTimeout(),
//CallerName: agent.Name(),
//CallerNumber: agent.CallNumber(),
}

if agent.HasPush() {
cr.SetPush()
}

queue.SetHoldMusic(cr)

if queue.id > 0 {
cr.Variables[model.QUEUE_ID_FIELD] = fmt.Sprintf("%d", queue.Id())
}

if attempt.MemberId() != nil {
cr.Variables["wbt_from_id"] = fmt.Sprintf("%d", *attempt.MemberId())
cr.Variables[model.QUEUE_MEMBER_ID_FIELD] = cr.Variables["wbt_from_id"]
}

if agent.GreetingMedia() != nil {
cr.Applications = append([]*model.CallRequestApplication{
{
AppName: "playback",
Args: model.RingtoneUri(agent.DomainId(), agent.GreetingMedia().Id, agent.GreetingMedia().Type),
},
}, apps...)
} else {
cr.Applications = apps
}

return cr
}

func (queue *CallingQueue) HangupManyCall(skipId, cause string, ids ...string) {
if len(ids) == 1 {

Expand Down Expand Up @@ -184,3 +244,35 @@ func (queue *CallingQueue) GetTransferredCall(id string) (call_manager.Call, *mo
func (queue *CallingQueue) GranteeId() *int {
return queue.granteeId
}

func (queue *CallingQueue) MissedAgentAttempt(attemptId int64, agentId int, call call_manager.Call) *model.AppError {
missed := &model.MissedAgentAttempt{
AttemptId: attemptId,
AgentId: agentId,
Cause: call.HangupCause(),
MissedAt: call.HangupAt(),
}

return queue.queueManager.store.Agent().CreateMissed(missed)
}

func IsHuman(call call_manager.Call, amd *model.QueueAmdSettings) bool {
if amd == nil || !amd.Enabled {
return true
}

if amd.Ai {
aiAmd := call.AiResult()
if aiAmd.Error != "" || aiAmd.Result == "undefined" {
return true // TODO ?
}
for _, v := range amd.PositiveTags {
if v == aiAmd.Result {
return true
}
}
return false
}

return call.IsHuman()
}
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion queue/queue_call_ivr.go → queue/call_ivr.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type IVRQueue struct {
QueueIVRSettings
}

func QueueIVRSettingsFromBytes(data []byte) QueueIVRSettings {
func IVRSettingsFromBytes(data []byte) QueueIVRSettings {
var settings QueueIVRSettings
json.Unmarshal(data, &settings)
return settings
Expand Down
2 changes: 1 addition & 1 deletion queue/queue_call_offline.go → queue/call_offline.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type OfflineCallQueue struct {
OfflineQueueSettings
}

func QueueOfflineSettingsFromBytes(data []byte) OfflineQueueSettings {
func OfflineSettingsFromBytes(data []byte) OfflineQueueSettings {
var settings OfflineQueueSettings
json.Unmarshal(data, &settings)
return settings
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 9 additions & 9 deletions queue/dialing.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ func NewDialing(app App, m mq.MQ, callManager call_manager.CallManager, agentMan
return &dialing
}

func (dialing *DialingImpl) Manager() *QueueManager {
return dialing.queueManager
func (d *DialingImpl) Manager() *QueueManager {
return d.queueManager
}

func (dialing *DialingImpl) Start() {
func (d *DialingImpl) Start() {
wlog.Debug("starting dialing service")
dialing.watcher = utils.MakeWatcher("Dialing", DEFAULT_WATCHER_POLLING_INTERVAL, dialing.routeData)
d.watcher = utils.MakeWatcher("Dialing", DEFAULT_WATCHER_POLLING_INTERVAL, d.routeData)

dialing.startOnce.Do(func() {
go dialing.watcher.Start()
go dialing.queueManager.Start()
go dialing.statisticsManager.Start()
go dialing.expiredManager.Start()
d.startOnce.Do(func() {
go d.watcher.Start()
go d.queueManager.Start()
go d.statisticsManager.Start()
go d.expiredManager.Start()
})
}

Expand Down
File renamed without changes.
10 changes: 0 additions & 10 deletions queue/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,3 @@ func NewErrorVariableRequired(queue QueueObject, attempt *Attempt, name string)
http.StatusBadRequest,
)
}

func NewErrorCommunicationPatternRequired(queue QueueObject, attempt *Attempt) *model.AppError {
return model.NewAppError(
"Queue",
"queue.distribute.invalid_communication_pattern.error",
map[string]interface{}{"QueueId": queue.Id(), "AttemptId": attempt.Id()},
"",
http.StatusUnauthorized,
)
}
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions queue/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func NewQueue(queueManager *QueueManager, resourceManager *ResourceManager, sett
BaseQueue: base,
HoldMusic: settings.HoldMusic,
granteeId: settings.GranteeId,
}, QueueOfflineSettingsFromBytes(settings.Payload)), nil
}, OfflineSettingsFromBytes(settings.Payload)), nil

case model.QueueTypeInboundCall:
inboundSettings := model.QueueInboundSettingsFromBytes(settings.Payload)
Expand All @@ -138,7 +138,7 @@ func NewQueue(queueManager *QueueManager, resourceManager *ResourceManager, sett
BaseQueue: base,
HoldMusic: settings.HoldMusic,
granteeId: settings.GranteeId,
}, QueueIVRSettingsFromBytes(settings.Payload)), nil
}, IVRSettingsFromBytes(settings.Payload)), nil

case model.QueueTypePreviewCall:
return NewPreviewCallQueue(CallingQueue{
Expand All @@ -165,7 +165,7 @@ func NewQueue(queueManager *QueueManager, resourceManager *ResourceManager, sett
return NewInboundChatQueue(base, InboundChatQueueFromBytes(settings.Payload)), nil

case model.QueueTypeAgentTask:
return NewTaskAgentQueue(base, TaskAgentSettingsFromBytes(settings.Payload)), nil
return NewTaskInboundQueue(base, TaskInboundSettingsFromBytes(settings.Payload)), nil

case model.QueueTypeOutboundTask:
return NewTaskOutboundQueue(base, TaskOutboundQueueSettingsFromBytes(settings.Payload)), nil
Expand Down
Loading

0 comments on commit 0ad3a55

Please sign in to comment.