diff --git a/app/agent.go b/app/agent.go index ce5f862f..88d94aff 100644 --- a/app/agent.go +++ b/app/agent.go @@ -152,8 +152,8 @@ func (app *App) CloseAgentTask(attemptId int64) *model.AppError { return app.dialing.Manager().CloseAgentTask(attemptId) } -func (app *App) RunTeamTrigger(ctx context.Context, domainId int64, agentId int32, triggerId int32, vars map[string]string) (string, *model.AppError) { - data, appErr := app.Store.Agent().AgentTriggerJob(ctx, domainId, agentId, triggerId) +func (app *App) RunTeamTrigger(ctx context.Context, domainId int64, userId int64, triggerId int32, vars map[string]string) (string, *model.AppError) { + data, appErr := app.Store.Agent().AgentTriggerJob(ctx, domainId, userId, triggerId) if appErr != nil { return "", appErr } @@ -166,8 +166,8 @@ func (app *App) RunTeamTrigger(ctx context.Context, domainId int64, agentId int3 vars[k] = v } - vars["agent_id"] = strconv.Itoa(int(agentId)) - vars["user_id"] = strconv.Itoa(int(data.UserId)) + vars["agent_id"] = strconv.Itoa(int(data.AgentId)) + vars["user_id"] = strconv.Itoa(int(userId)) vars["email"] = data.Email vars["extension"] = data.Extension vars["agent_name"] = data.Name diff --git a/go.mod b/go.mod index 000af9dd..e1e1b17a 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-20231219131344-033714018987 github.com/webitel/flow_manager v0.0.0-20230928094914-a9c915fbadcb - github.com/webitel/protos/cc v0.0.0-20240327112629-2581d12d96d4 + github.com/webitel/protos/cc v0.0.0-20240327130525-7501c51c7a8e github.com/webitel/protos/fs v0.0.0-20231219144336-af0e727d5b1e github.com/webitel/protos/workflow v0.0.0-20231219144336-af0e727d5b1e github.com/webitel/wlog v0.0.0-20220608103744-93b33e61bd28 diff --git a/grpc_api/agent.go b/grpc_api/agent.go index 56d06670..c48a7b54 100644 --- a/grpc_api/agent.go +++ b/grpc_api/agent.go @@ -12,17 +12,6 @@ type agent struct { cc.UnsafeAgentServiceServer } -func (api *agent) RunTrigger(ctx context.Context, in *cc.RunTriggerRequest) (*cc.RunTriggerResponse, error) { - jobId, err := api.app.RunTeamTrigger(ctx, in.DomainId, in.AgentId, in.TriggerId, in.Variables) - if err != nil { - return nil, err - } - - return &cc.RunTriggerResponse{ - JobId: jobId, - }, nil -} - func NewAgentApi(a *app.App) *agent { return &agent{app: a} } @@ -106,3 +95,14 @@ func (api *agent) CloseTask(_ context.Context, in *cc.CloseTaskRequest) (*cc.Clo return &cc.CloseTaskResponse{}, nil } + +func (api *agent) RunTrigger(ctx context.Context, in *cc.RunTriggerRequest) (*cc.RunTriggerResponse, error) { + jobId, err := api.app.RunTeamTrigger(ctx, in.DomainId, in.UserId, in.TriggerId, in.Variables) + if err != nil { + return nil, err + } + + return &cc.RunTriggerResponse{ + JobId: jobId, + }, nil +} diff --git a/grpc_api/client/agent.go b/grpc_api/client/agent.go index f2765c83..0559e1ab 100644 --- a/grpc_api/client/agent.go +++ b/grpc_api/client/agent.go @@ -104,7 +104,7 @@ func (api *agentApi) CloseTask(appId string, domainId, attemptId int64) error { return err } -func (api *agentApi) RunTrigger(ctx context.Context, domainId int64, agentId int32, triggerId int32, vars map[string]string) (string, error) { +func (api *agentApi) RunTrigger(ctx context.Context, domainId int64, userId int64, triggerId int32, vars map[string]string) (string, error) { cli, err := api.cli.getRandomClient() if err != nil { return "", err @@ -114,7 +114,7 @@ func (api *agentApi) RunTrigger(ctx context.Context, domainId int64, agentId int res, err = cli.Agent().RunTrigger(ctx, &cc.RunTriggerRequest{ DomainId: domainId, TriggerId: triggerId, - AgentId: agentId, + UserId: userId, Variables: vars, }) diff --git a/grpc_api/client/client.go b/grpc_api/client/client.go index b3f43985..7190f205 100644 --- a/grpc_api/client/client.go +++ b/grpc_api/client/client.go @@ -23,7 +23,7 @@ type AgentApi interface { AcceptTask(appId string, domainId, attemptId int64) error CloseTask(appId string, domainId, attemptId int64) error - RunTrigger(ctx context.Context, domainId int64, agentId int32, triggerId int32, vars map[string]string) (string, error) + RunTrigger(ctx context.Context, domainId int64, userId int64, triggerId int32, vars map[string]string) (string, error) } type MemberApi interface { diff --git a/model/agent.go b/model/agent.go index 67594984..6991797a 100644 --- a/model/agent.go +++ b/model/agent.go @@ -182,7 +182,7 @@ type AgentTriggerJob struct { SchemaId uint32 `json:"schema_id" db:"schema_id"` Extension string `json:"extension" db:"extension"` Email string `json:"email" db:"email"` - UserId int64 `json:"user_id" db:"user_id"` + AgentId int32 `json:"agent_id" db:"agent_id"` Name string `json:"name" db:"name"` Variables StringMap `json:"variables" db:"variables"` } diff --git a/store/sqlstore/agent_store.go b/store/sqlstore/agent_store.go index 0e0fe29f..6d521320 100644 --- a/store/sqlstore/agent_store.go +++ b/store/sqlstore/agent_store.go @@ -398,20 +398,20 @@ where agent_id = :AgentId and state != 'waiting'`, map[string]interface{}{ return nil } -func (s *SqlAgentStore) AgentTriggerJob(ctx context.Context, domainId int64, agentId int32, triggerId int32) (*model.AgentTriggerJob, *model.AppError) { +func (s *SqlAgentStore) AgentTriggerJob(ctx context.Context, domainId int64, userId int64, triggerId int32) (*model.AgentTriggerJob, *model.AppError) { var tr model.AgentTriggerJob err := s.GetReplica().WithContext(ctx).SelectOne(&tr, `select tr.schema_id, - a.user_id, + a.id as agent_id, coalesce(u.extension, '') extension, coalesce(u.email, '') email, coalesce(u.name::varchar, u.username) name, u.profile as variables -from call_center.cc_team_trigger tr - inner join call_center.cc_agent a on a.id = :AgentId and a.team_id = tr.team_id - inner join directory.wbt_user u on u.id = a.user_id -where tr.id = :Id and a.domain_id = :DomainId`, map[string]interface{}{ - "AgentId": agentId, +from directory.wbt_user u + inner join call_center.cc_agent a on a.user_id = u.id + inner join call_center.cc_team_trigger tr on tr.team_id = a.team_id +where tr.id = :Id and u.dc = :DomainId and u.id = :UserId`, map[string]interface{}{ + "UserId": userId, "DomainId": domainId, "Id": triggerId, }) diff --git a/store/store.go b/store/store.go index 70534ee3..3d1b6ab6 100644 --- a/store/store.go +++ b/store/store.go @@ -127,7 +127,7 @@ type AgentStore interface { OnlineWithOutActive(sec int) ([]model.AgentHashKey, *model.AppError) LosePredictAttempt(id int) *model.AppError CheckAllowPause(domainId int64, agentId int) (bool, *model.AppError) - AgentTriggerJob(ctx context.Context, domainId int64, agentId int32, triggerId int32) (*model.AgentTriggerJob, *model.AppError) + AgentTriggerJob(ctx context.Context, domainId int64, userId int64, triggerId int32) (*model.AgentTriggerJob, *model.AppError) } type TeamStore interface {