From dc0b2e9f58ddbec6f22d1cbbf599b627270918b2 Mon Sep 17 00:00:00 2001 From: "i.navrotskyj" Date: Mon, 1 Apr 2024 16:30:59 +0300 Subject: [PATCH] WTEL-4393 --- go.mod | 2 +- model/task.go | 18 +++++++++ queue/queue_manager.go | 67 +++++++++++++++++++++++++--------- store/sqlstore/member_store.go | 10 +++-- store/store.go | 4 +- 5 files changed, 76 insertions(+), 25 deletions(-) diff --git a/go.mod b/go.mod index c717fa03..ed420a79 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/streadway/amqp v1.1.0 github.com/webitel/engine v0.0.0-20240327135406-7469d4bcb04b github.com/webitel/flow_manager v0.0.0-20240318151852-e35870a75700 - github.com/webitel/protos/cc v0.0.0-20240328133631-6fe516ff9b1c + github.com/webitel/protos/cc v0.0.0-20240401125538-65d07de06373 github.com/webitel/protos/fs v0.0.0-20240327130525-7501c51c7a8e github.com/webitel/protos/workflow v0.0.0-20240327132302-ffcc68b6314f github.com/webitel/wlog v0.0.0-20220608103744-93b33e61bd28 diff --git a/model/task.go b/model/task.go index b05cf23f..bdb304ec 100644 --- a/model/task.go +++ b/model/task.go @@ -1,5 +1,7 @@ package model +import "encoding/json" + type TaskToAgent struct { AttemptId int64 `json:"attempt_id" db:"attempt_id"` Destination []byte `json:"destination" db:"destination"` @@ -9,3 +11,19 @@ type TaskToAgent struct { TeamUpdatedAt int64 `json:"team_updated_at" db:"team_updated_at"` AgentUpdatedAt int64 `json:"agent_updated_at" db:"agent_updated_at"` } + +type QueueDumpParams struct { + HasReporting *bool `json:"has_reporting,omitempty"` + HasForm *bool `json:"has_form,omitempty"` + ProcessingSec uint32 `json:"processing_sec,omitempty"` + ProcessingRenewalSec uint32 `json:"processing_renewal_sec,omitempty"` + QueueName string `json:"queue_name,omitempty"` +} + +func (q *QueueDumpParams) ToJson() []byte { + d, _ := json.Marshal(&q) + if d == nil { + return []byte("{}") + } + return d +} diff --git a/queue/queue_manager.go b/queue/queue_manager.go index df21c083..8eb5f07b 100644 --- a/queue/queue_manager.go +++ b/queue/queue_manager.go @@ -2,6 +2,7 @@ package queue import ( "context" + "encoding/json" "fmt" "github.com/webitel/call_center/agent_manager" "github.com/webitel/call_center/call_manager" @@ -407,12 +408,27 @@ func (queueManager *QueueManager) DistributeCallToAgent(ctx context.Context, in // FIXME add domain var agent agent_manager.AgentObject + qParams := &model.QueueDumpParams{ + QueueName: in.QueueName, + } + + if qParams.QueueName == "" { + qParams.QueueName = "agent" + } + + if in.Processing != nil && in.Processing.Enabled { + qParams.HasReporting = model.NewBool(true) + qParams.ProcessingSec = in.Processing.Sec + qParams.ProcessingRenewalSec = in.Processing.RenewalSec + } + res, err := queueManager.store.Member().DistributeCallToAgent( queueManager.app.GetInstanceId(), in.GetMemberCallId(), in.GetVariables(), in.GetAgentId(), in.CancelDistribute, + qParams, ) if err != nil { @@ -479,16 +495,12 @@ func (queueManager *QueueManager) DistributeCallToAgent(ctx context.Context, in MemberCallId: &res.CallId, }) - if in.QueueName == "" { - in.QueueName = "Agent" - } - settings := &model.Queue{ Id: 0, DomainId: in.DomainId, DomainName: "TODO", Type: 10, - Name: in.QueueName, + Name: qParams.QueueName, Strategy: "", Payload: nil, TeamId: &res.TeamId, @@ -497,10 +509,10 @@ func (queueManager *QueueManager) DistributeCallToAgent(ctx context.Context, in ProcessingRenewalSec: 15, Hooks: nil, } - if in.Processing != nil && in.Processing.Enabled { + if qParams.HasReporting != nil && *qParams.HasReporting { settings.Processing = true - settings.ProcessingSec = in.Processing.Sec - settings.ProcessingRenewalSec = in.Processing.RenewalSec + settings.ProcessingSec = qParams.ProcessingSec + settings.ProcessingRenewalSec = qParams.ProcessingRenewalSec } var queue = JoinAgentCallQueue{ @@ -530,13 +542,33 @@ func (queueManager *QueueManager) DistributeCallToAgent(ctx context.Context, in func (queueManager *QueueManager) DistributeTaskToAgent(ctx context.Context, in *cc.TaskJoinToAgentRequest) (*Attempt, *model.AppError) { var agent agent_manager.AgentObject + + qParams := &model.QueueDumpParams{ + QueueName: in.QueueName, + } + if qParams.QueueName == "" { + qParams.QueueName = "agent" + } + + if in.Processing != nil && in.Processing.Enabled { + qParams.HasReporting = model.NewBool(true) + qParams.ProcessingSec = in.Processing.Sec + qParams.ProcessingRenewalSec = in.Processing.RenewalSec + if in.Processing.FormSchemaId > 0 { + qParams.HasForm = model.NewBool(true) + } + } + + dest, _ := json.Marshal(in.Destination) + res, err := queueManager.store.Member().DistributeTaskToAgent( queueManager.app.GetInstanceId(), in.DomainId, in.GetAgentId(), - []byte(`{"destination":"1232131231"}`), + dest, in.GetVariables(), in.CancelDistribute, + qParams, ) if err != nil { @@ -569,16 +601,12 @@ func (queueManager *QueueManager) DistributeTaskToAgent(ctx context.Context, in Name: res.Name, }) - if in.QueueName == "" { - in.QueueName = "Agent" - } - settings := &model.Queue{ Id: 0, DomainId: in.DomainId, DomainName: "TODO", Type: model.QueueTypeAgentTask, - Name: in.QueueName, + Name: qParams.QueueName, Strategy: "", Payload: nil, TeamId: &res.TeamId, @@ -586,15 +614,18 @@ func (queueManager *QueueManager) DistributeTaskToAgent(ctx context.Context, in ProcessingSec: 30, ProcessingRenewalSec: 15, Hooks: nil, - FormSchemaId: model.NewInt(604), Variables: map[string]string{ "wbt_auto_answer": "true", }, } - if in.Processing != nil && in.Processing.Enabled { + + if qParams.HasReporting != nil && *qParams.HasReporting { settings.Processing = true - settings.ProcessingSec = in.Processing.Sec - settings.ProcessingRenewalSec = in.Processing.RenewalSec + settings.ProcessingSec = qParams.ProcessingSec + settings.ProcessingRenewalSec = qParams.ProcessingRenewalSec + if in.Processing.FormSchemaId > 0 { + settings.FormSchemaId = model.NewInt(int(in.Processing.FormSchemaId)) + } } var queue = TaskAgent{ diff --git a/store/sqlstore/member_store.go b/store/sqlstore/member_store.go index 6a573956..25ded87b 100644 --- a/store/sqlstore/member_store.go +++ b/store/sqlstore/member_store.go @@ -172,11 +172,11 @@ as x ( return att, nil } -func (s SqlMemberStore) DistributeCallToAgent(node string, callId string, vars map[string]string, agentId int32, force bool) (*model.InboundCallAgent, *model.AppError) { +func (s SqlMemberStore) DistributeCallToAgent(node string, callId string, vars map[string]string, agentId int32, force bool, params *model.QueueDumpParams) (*model.InboundCallAgent, *model.AppError) { var att *model.InboundCallAgent err := s.GetMaster().SelectOne(&att, `select * -from call_center.cc_distribute_inbound_call_to_agent(:Node, :MemberCallId, :Variables, :AgentId) +from call_center.cc_distribute_inbound_call_to_agent(:Node, :MemberCallId, :Variables, :AgentId, :Prams::jsonb) as x ( attempt_id int8, destination jsonb, @@ -204,6 +204,7 @@ where :Force::bool or not exists(select 1 from call_center.cc_member_attempt a w "Variables": model.MapToJson(vars), "AgentId": agentId, "Force": force, + "Prams": params.ToJson(), }) if err != nil { @@ -214,11 +215,11 @@ where :Force::bool or not exists(select 1 from call_center.cc_member_attempt a w return att, nil } -func (s SqlMemberStore) DistributeTaskToAgent(node string, domainId int64, agentId int32, dest []byte, vars map[string]string, force bool) (*model.TaskToAgent, *model.AppError) { +func (s SqlMemberStore) DistributeTaskToAgent(node string, domainId int64, agentId int32, dest []byte, vars map[string]string, force bool, params *model.QueueDumpParams) (*model.TaskToAgent, *model.AppError) { var att *model.TaskToAgent err := s.GetMaster().SelectOne(&att, `select * -from call_center.cc_distribute_task_to_agent(:Node, :DomainId, :AgentId, :Dest::jsonb, :Variables) +from call_center.cc_distribute_task_to_agent(:Node, :DomainId, :AgentId, :Dest::jsonb, :Variables, :Params::jsonb) as x ( attempt_id int8, destination jsonb, @@ -234,6 +235,7 @@ where :Force::bool or not exists(select 1 from call_center.cc_member_attempt a w "Variables": model.MapToJson(vars), "AgentId": agentId, "Force": force, + "Params": params.ToJson(), }) if err != nil { diff --git a/store/store.go b/store/store.go index 8314180a..8012d88a 100644 --- a/store/store.go +++ b/store/store.go @@ -50,8 +50,8 @@ type MemberStore interface { DistributeDirect(node string, memberId int64, communicationId, agentId int) (*model.MemberAttempt, *model.AppError) DistributeCallToQueue(node string, queueId int64, callId string, vars map[string]string, bucketId *int32, priority int, stickyAgentId *int) (*model.InboundCallQueue, *model.AppError) DistributeCallToQueueCancel(id int64) *model.AppError - DistributeCallToAgent(node string, callId string, vars map[string]string, agentId int32, force bool) (*model.InboundCallAgent, *model.AppError) - DistributeTaskToAgent(node string, domainId int64, agentId int32, dest []byte, vars map[string]string, force bool) (*model.TaskToAgent, *model.AppError) + DistributeCallToAgent(node string, callId string, vars map[string]string, agentId int32, force bool, params *model.QueueDumpParams) (*model.InboundCallAgent, *model.AppError) + DistributeTaskToAgent(node string, domainId int64, agentId int32, dest []byte, vars map[string]string, force bool, params *model.QueueDumpParams) (*model.TaskToAgent, *model.AppError) /* Flow control