Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WTEL-4393 #58

Merged
merged 1 commit into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions model/task.go
Original file line number Diff line number Diff line change
@@ -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"`
Expand All @@ -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
}
67 changes: 49 additions & 18 deletions queue/queue_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -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{
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -569,32 +601,31 @@ 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,
Processing: false,
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{
Expand Down
10 changes: 6 additions & 4 deletions store/sqlstore/member_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading