Skip to content
Open
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
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
# engine

## Email quick replies — EM-30

Quick Replies have a `channel`: empty for non-Email replies or `email`, set on
create only. Search without `channel` returns replies without a channel, with
`email` only Email replies; another value is refused
(`quick_reply.email.invalid_channel`).

- **Body.** `text` is required and is the plain-text fallback, `html` is
optional. HTML is stored sanitized: paragraphs, line breaks, emphasis,
lists, quotes and `http`/`https`/`mailto` links; markup without text is
stored empty. `text` and `html` are limited to 64 KiB each.
- **Variables.** Only `${agent_name}`, `${contact_name}`, `${thread_id}` and
`${thread_subject}`, case sensitive, in `text` and in HTML text; another or
unclosed `${` and a variable in an HTML attribute are refused. Workspace
fills them on insert as text; a missing value becomes empty with a warning.
- **Edit.** PUT replaces the reply. PATCH of an Email reply changes only
`name`, `text`, `html`, `teams` and `queues` listed in `fields` (over HTTP:
the keys of the body); none of them is `quick_reply.email.empty_patch`.
`article` is not used. Teams and queues must belong to the domain
(`quick_reply.email.invalid_restriction`).
- **Access.** Rights of `dictionaries`; with `restrict_to_agent` a reply
without teams and queues, of the agent's team or of the agent's queues.
- **Send.** Workspace sends the final `body_html`; `email-service` derives the
plain text. The profile signature stays a separate fragment.

Other errors: `quick_reply.email.text_required`, `body_too_large`,
`invalid_token`, `token_in_attribute`, all `InvalidArgument`.

## Email events — EM-26

Stage 17 delivers the Workspace events of `email-service` to the operator over
Expand Down
33 changes: 33 additions & 0 deletions app/cc_quick_reply.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ func (a *App) GetQuickReplyPage(ctx context.Context, domainId int64, search *mod
list []*model.QuickReply
err model.AppError
)

if !model.IsValidQuickReplyChannel(search.Channel) {
return nil, false, model.NewQuickReplyChannelError(search.Channel)
}

if strings.Contains(search.Sort, AGENT_PRIORITY_SORT) {
list, err = a.Store.QuickReply().GetAllPageByAgentPriority(ctx, domainId, int64(userId), search)
Expand All @@ -32,6 +36,17 @@ func (a *App) GetQuickReplyPage(ctx context.Context, domainId int64, search *mod
}

func (a *App) CreateQuickReply(ctx context.Context, domainId int64, reply *model.QuickReply) (*model.QuickReply, model.AppError) {
if !model.IsValidQuickReplyChannel(reply.Channel) {
return nil, model.NewQuickReplyChannelError(reply.Channel)
}
if reply.IsEmail() {
if err := reply.PrepareEmail(); err != nil {
return nil, err
}
} else {
reply.Html = ""
}

return a.Store.QuickReply().Create(ctx, domainId, reply)
}

Expand All @@ -53,6 +68,12 @@ func (a *App) UpdateQuickReply(ctx context.Context, domainId int64, reply *model
oldReply.Queues = reply.Queues
oldReply.Teams = reply.Teams
oldReply.Article = reply.Article
if oldReply.IsEmail() {
oldReply.Html = reply.Html
if err = oldReply.PrepareEmail(); err != nil {
return nil, err
}
}

oldReply, err = a.Store.QuickReply().Update(ctx, domainId, oldReply)
if err != nil {
Expand All @@ -68,6 +89,18 @@ func (a *App) PatchQuickReply(ctx context.Context, domainId int64, id uint32, pa
return nil, err
}

if oldReply.IsEmail() {
// The whole reply is validated, only the fields of the mask are written.
fields, err := oldReply.PatchEmail(patch)
if err != nil {
return nil, err
}
if err = oldReply.PrepareEmail(); err != nil {
return nil, err
}
return a.Store.QuickReply().PatchEmail(ctx, domainId, oldReply, fields)
}

oldReply.Patch(patch)

if err = oldReply.IsValid(); err != nil {
Expand Down
308 changes: 190 additions & 118 deletions gen/engine/quick_replies.pb.go

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ require (
github.com/grpc-ecosystem/grpc-gateway/v2 v2.28.0
github.com/jmoiron/sqlx v1.4.0
github.com/lib/pq v1.10.9
github.com/microcosm-cc/bluemonday v1.0.27
github.com/pborman/uuid v1.2.1
github.com/pkg/errors v0.9.1
github.com/rabbitmq/amqp091-go v1.10.0
Expand Down Expand Up @@ -55,6 +56,7 @@ require (
github.com/MicahParks/keyfunc v1.9.0 // indirect
github.com/andres-erbsen/clock v0.0.0-20160526145045-9e14626cd129 // indirect
github.com/armon/go-metrics v0.4.1 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
Expand All @@ -70,6 +72,7 @@ require (
github.com/google/uuid v1.6.0
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.3 // indirect
github.com/gorilla/css v1.0.1 // indirect
github.com/hashicorp/consul/api v1.33.2 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ github.com/armon/go-metrics v0.4.1 h1:hR91U9KYmb6bLBYLQjyM+3j+rcd/UhE+G78SFnF8gJ
github.com/armon/go-metrics v0.4.1/go.mod h1:E6amYzXo6aW1tqzoZGT755KkbgrJsSdpwZ+3JqfkOG4=
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk=
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
Expand Down Expand Up @@ -154,6 +156,8 @@ github.com/googleapis/enterprise-certificate-proxy v0.3.2 h1:Vie5ybvEvT75RniqhfF
github.com/googleapis/enterprise-certificate-proxy v0.3.2/go.mod h1:VLSiSSBs/ksPL8kq3OBOQ6WRI2QnaFynd1DCjZ62+V0=
github.com/googleapis/gax-go/v2 v2.12.3 h1:5/zPPDvw8Q1SuXjrqrZslrqT7dL/uJT2CQii/cLCKqA=
github.com/googleapis/gax-go/v2 v2.12.3/go.mod h1:AKloxT6GtNbaLm8QTNSidHUVsHYcBHwWRvkNFJUQcS4=
github.com/gorilla/css v1.0.1 h1:ntNaBIghp6JmvWnxbZKANoLyuXTPZ4cAMlo6RyhlbO8=
github.com/gorilla/css v1.0.1/go.mod h1:BvnYkspnSzMmwRK+b8/xgNPLiIuNZr6vbZBTPQ2A3b0=
github.com/gorilla/handlers v1.5.2 h1:cLTUSsNkgcwhgRqvCNmdbRWG0A3N4F+M2nWKdScwyEE=
github.com/gorilla/handlers v1.5.2/go.mod h1:dX+xVpaxdSw+q0Qek8SSsl3dfMk3jNddUkMzo0GtH0w=
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
Expand Down Expand Up @@ -258,6 +262,8 @@ github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/microcosm-cc/bluemonday v1.0.27 h1:MpEUotklkwCSLeH+Qdx1VJgNqLlpY2KXwXFM08ygZfk=
github.com/microcosm-cc/bluemonday v1.0.27/go.mod h1:jFi9vgW+H7c3V0lb6nR74Ib/DIB5OBs92Dimizgw2cA=
github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso=
github.com/miekg/dns v1.1.41 h1:WMszZWJG0XmzbK9FEmzH2TVcqYzFesusSIB41b8KHxY=
github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI=
Expand Down
8 changes: 8 additions & 0 deletions grpc_api/cc_quick_reply.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ func (api *quickReply) CreateQuickReply(ctx context.Context, in *engine.CreateQu
Article: GetLookup(in.Article),
Teams: GetLookups(in.Teams),
Queues: GetLookups(in.Queues),
Channel: in.Channel,
Html: in.Html,
}

replyq, err := api.ctrl.CreateQuickReply(ctx, session, reply)
Expand Down Expand Up @@ -65,6 +67,7 @@ func (api *quickReply) SearchQuickReplies(ctx context.Context, in *engine.Search
Ids: in.GetId(),
Queue: in.GetQueue(),
RestrictToAgent: in.GetRestrictToAgent(),
Channel: in.GetChannel(),
}

list, endList, err = api.ctrl.SearchQuickReply(ctx, session, req)
Expand Down Expand Up @@ -112,6 +115,8 @@ func (api *quickReply) PatchQuickReply(ctx context.Context, in *engine.PatchQuic
patch.Article = GetLookup(in.Article)
patch.Teams = GetLookups(in.Teams)
patch.Queues = GetLookups(in.Queues)
patch.Html = model.NewString(in.Html)
patch.Fields = in.Fields

if reply, err = api.ctrl.PatchQuickReply(ctx, session, in.Id, patch); err != nil {
return nil, err
Expand All @@ -134,6 +139,7 @@ func (api *quickReply) UpdateQuickReply(ctx context.Context, in *engine.UpdateQu
Article: GetLookup(in.Article),
Teams: GetLookups(in.Teams),
Queues: GetLookups(in.Queues),
Html: in.Html,
}

reply, err = api.ctrl.UpdateQuickReply(ctx, session, reply)
Expand Down Expand Up @@ -172,5 +178,7 @@ func toEngineQuickReply(src *model.QuickReply) *engine.QuickReply {
Queues: GetProtoLookups(src.Queues),
Teams: GetProtoLookups(src.Teams),
Article: GetProtoLookup(src.Article),
Channel: src.Channel,
Html: src.Html,
}
}
14 changes: 10 additions & 4 deletions model/cc_quick_reply.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ type QuickReply struct {
Queues []*Lookup `json:"queue" db:"queues"`
Teams []*Lookup `json:"team" db:"teams"`
Article *Lookup `json:"article" db:"article"`
Channel string `json:"channel" db:"channel"`
Html string `json:"html" db:"html"`
}

type SearchQuickReply struct {
ListRequest
Queue []uint32
Ids []uint32
Name *string
Queue []uint32
Ids []uint32
Name *string
Channel string

RestrictToAgent bool
}
Expand All @@ -29,10 +32,13 @@ type QuickReplyPatch struct {
Queues []*Lookup `json:"queue" db:"queues"`
Teams []*Lookup `json:"team" db:"teams"`
Article *Lookup `json:"article" db:"article"`
Html *string `json:"html"`
// Fields is the PATCH mask; only Email replies use it.
Fields []string `json:"fields"`
}

func (p QuickReply) AllowFields() []string {
return []string{"id", "created_by", "created_at", "updated_by", "updated_at", "name", "text", "teams", "queues"}
return []string{"id", "created_by", "created_at", "updated_by", "updated_at", "name", "text", "teams", "queues", "channel", "html"}
}

func (QuickReply) DefaultOrder() string {
Expand Down
Loading
Loading