Skip to content

Commit

Permalink
WTEL-4353
Browse files Browse the repository at this point in the history
  • Loading branch information
i.navrotskyj committed Mar 27, 2024
1 parent 8d56fad commit b29cc34
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 28 deletions.
8 changes: 4 additions & 4 deletions app/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
Expand Down
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-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
Expand Down
22 changes: 11 additions & 11 deletions grpc_api/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
Expand Down Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions grpc_api/client/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
})

Expand Down
2 changes: 1 addition & 1 deletion grpc_api/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion model/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
14 changes: 7 additions & 7 deletions store/sqlstore/agent_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand Down
2 changes: 1 addition & 1 deletion store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit b29cc34

Please sign in to comment.