From f339e70df45bc84a139af1930d37163a609639c7 Mon Sep 17 00:00:00 2001 From: Denys Bahachuk Date: Mon, 23 Nov 2026 18:09:41 +0000 Subject: [PATCH] feat(EM-30): support Email quick replies --- README.md | 28 +++ app/cc_quick_reply.go | 33 +++ gen/engine/quick_replies.pb.go | 308 +++++++++++++++---------- go.mod | 3 + go.sum | 6 + grpc_api/cc_quick_reply.go | 8 + model/cc_quick_reply.go | 14 +- model/cc_quick_reply_email.go | 196 ++++++++++++++++ model/cc_quick_reply_email_test.go | 121 ++++++++++ store/sqlstore/cc_quick_reply_store.go | 154 ++++++++++--- store/store.go | 1 + 11 files changed, 712 insertions(+), 160 deletions(-) create mode 100644 model/cc_quick_reply_email.go create mode 100644 model/cc_quick_reply_email_test.go diff --git a/README.md b/README.md index caba9528..bb6eb6b6 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/app/cc_quick_reply.go b/app/cc_quick_reply.go index b86feebb..f0ee1ee6 100644 --- a/app/cc_quick_reply.go +++ b/app/cc_quick_reply.go @@ -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) @@ -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) } @@ -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 { @@ -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 { diff --git a/gen/engine/quick_replies.pb.go b/gen/engine/quick_replies.pb.go index 23597043..87e17b23 100644 --- a/gen/engine/quick_replies.pb.go +++ b/gen/engine/quick_replies.pb.go @@ -31,6 +31,11 @@ type CreateQuickReplyRequest struct { Queues []*Lookup `protobuf:"bytes,3,rep,name=queues,proto3" json:"queues,omitempty"` Teams []*Lookup `protobuf:"bytes,4,rep,name=teams,proto3" json:"teams,omitempty"` Article *Lookup `protobuf:"bytes,5,opt,name=article,proto3" json:"article,omitempty"` + // Channel: empty for non-Email replies or "email". Set on create only. + Channel string `protobuf:"bytes,6,opt,name=channel,proto3" json:"channel,omitempty"` + // Email only: stored sanitized; text is the plain-text fallback. + // Variables: ${agent_name}, ${contact_name}, ${thread_id}, ${thread_subject}. + Html string `protobuf:"bytes,7,opt,name=html,proto3" json:"html,omitempty"` } func (x *CreateQuickReplyRequest) Reset() { @@ -100,6 +105,20 @@ func (x *CreateQuickReplyRequest) GetArticle() *Lookup { return nil } +func (x *CreateQuickReplyRequest) GetChannel() string { + if x != nil { + return x.Channel + } + return "" +} + +func (x *CreateQuickReplyRequest) GetHtml() string { + if x != nil { + return x.Html + } + return "" +} + type QuickReply struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -115,6 +134,8 @@ type QuickReply struct { Teams []*Lookup `protobuf:"bytes,8,rep,name=teams,proto3" json:"teams,omitempty"` Article *Lookup `protobuf:"bytes,9,opt,name=article,proto3" json:"article,omitempty"` Queues []*Lookup `protobuf:"bytes,10,rep,name=queues,proto3" json:"queues,omitempty"` + Channel string `protobuf:"bytes,11,opt,name=channel,proto3" json:"channel,omitempty"` + Html string `protobuf:"bytes,12,opt,name=html,proto3" json:"html,omitempty"` } func (x *QuickReply) Reset() { @@ -219,6 +240,20 @@ func (x *QuickReply) GetQueues() []*Lookup { return nil } +func (x *QuickReply) GetChannel() string { + if x != nil { + return x.Channel + } + return "" +} + +func (x *QuickReply) GetHtml() string { + if x != nil { + return x.Html + } + return "" +} + type SearchQuickRepliesRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -232,6 +267,8 @@ type SearchQuickRepliesRequest struct { Id []uint32 `protobuf:"varint,6,rep,packed,name=id,proto3" json:"id,omitempty"` Queue []uint32 `protobuf:"varint,7,rep,packed,name=queue,proto3" json:"queue,omitempty"` RestrictToAgent bool `protobuf:"varint,8,opt,name=restrict_to_agent,json=restrictToAgent,proto3" json:"restrict_to_agent,omitempty"` + // Empty returns replies without a channel, "email" returns Email replies. + Channel string `protobuf:"bytes,9,opt,name=channel,proto3" json:"channel,omitempty"` } func (x *SearchQuickRepliesRequest) Reset() { @@ -322,6 +359,13 @@ func (x *SearchQuickRepliesRequest) GetRestrictToAgent() bool { return false } +func (x *SearchQuickRepliesRequest) GetChannel() string { + if x != nil { + return x.Channel + } + return "" +} + type ListQuickReplies struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -436,6 +480,8 @@ type PatchQuickReplyRequest struct { Teams []*Lookup `protobuf:"bytes,5,rep,name=teams,proto3" json:"teams,omitempty"` Article *Lookup `protobuf:"bytes,6,opt,name=article,proto3" json:"article,omitempty"` Queues []*Lookup `protobuf:"bytes,7,rep,name=queues,proto3" json:"queues,omitempty"` + // Email only; applied when listed in fields. + Html string `protobuf:"bytes,8,opt,name=html,proto3" json:"html,omitempty"` } func (x *PatchQuickReplyRequest) Reset() { @@ -519,6 +565,13 @@ func (x *PatchQuickReplyRequest) GetQueues() []*Lookup { return nil } +func (x *PatchQuickReplyRequest) GetHtml() string { + if x != nil { + return x.Html + } + return "" +} + type UpdateQuickReplyRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -530,6 +583,8 @@ type UpdateQuickReplyRequest struct { Teams []*Lookup `protobuf:"bytes,4,rep,name=teams,proto3" json:"teams,omitempty"` Article *Lookup `protobuf:"bytes,5,opt,name=article,proto3" json:"article,omitempty"` Queues []*Lookup `protobuf:"bytes,6,rep,name=queues,proto3" json:"queues,omitempty"` + // Email only; replaces the stored HTML. + Html string `protobuf:"bytes,7,opt,name=html,proto3" json:"html,omitempty"` } func (x *UpdateQuickReplyRequest) Reset() { @@ -606,6 +661,13 @@ func (x *UpdateQuickReplyRequest) GetQueues() []*Lookup { return nil } +func (x *UpdateQuickReplyRequest) GetHtml() string { + if x != nil { + return x.Html + } + return "" +} + type DeleteQuickReplyRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -660,7 +722,7 @@ var file_quick_replies_proto_rawDesc = []byte{ 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x06, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x0b, 0x63, 0x6f, 0x6e, - 0x73, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xb9, 0x01, 0x0a, 0x17, 0x43, 0x72, 0x65, + 0x73, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xe7, 0x01, 0x0a, 0x17, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x65, 0x78, 0x74, @@ -672,126 +734,136 @@ var file_quick_replies_proto_rawDesc = []byte{ 0x6b, 0x75, 0x70, 0x52, 0x05, 0x74, 0x65, 0x61, 0x6d, 0x73, 0x12, 0x28, 0x0a, 0x07, 0x61, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x2e, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x52, 0x07, 0x61, 0x72, 0x74, - 0x69, 0x63, 0x6c, 0x65, 0x22, 0xd8, 0x02, 0x0a, 0x0a, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x52, 0x65, - 0x70, 0x6c, 0x79, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, - 0x02, 0x69, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, - 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, - 0x41, 0x74, 0x12, 0x2d, 0x0a, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x62, 0x79, - 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x2e, - 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x52, 0x09, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x42, - 0x79, 0x12, 0x1d, 0x0a, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, - 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74, - 0x12, 0x2d, 0x0a, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x62, 0x79, 0x18, 0x05, + 0x69, 0x63, 0x6c, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x18, + 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x12, 0x12, + 0x0a, 0x04, 0x68, 0x74, 0x6d, 0x6c, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x68, 0x74, + 0x6d, 0x6c, 0x22, 0x86, 0x03, 0x0a, 0x0a, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x52, 0x65, 0x70, 0x6c, + 0x79, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x02, 0x69, + 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74, + 0x12, 0x2d, 0x0a, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x62, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x2e, 0x4c, 0x6f, - 0x6f, 0x6b, 0x75, 0x70, 0x52, 0x09, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x42, 0x79, 0x12, - 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, - 0x61, 0x6d, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x65, 0x78, 0x74, 0x18, 0x07, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x04, 0x74, 0x65, 0x78, 0x74, 0x12, 0x24, 0x0a, 0x05, 0x74, 0x65, 0x61, 0x6d, 0x73, - 0x18, 0x08, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x2e, - 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x52, 0x05, 0x74, 0x65, 0x61, 0x6d, 0x73, 0x12, 0x28, 0x0a, - 0x07, 0x61, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x18, 0x09, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, - 0x2e, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x2e, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x52, 0x07, - 0x61, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x12, 0x26, 0x0a, 0x06, 0x71, 0x75, 0x65, 0x75, 0x65, - 0x73, 0x18, 0x0a, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, - 0x2e, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x52, 0x06, 0x71, 0x75, 0x65, 0x75, 0x65, 0x73, 0x22, - 0xcf, 0x01, 0x0a, 0x19, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x52, - 0x65, 0x70, 0x6c, 0x69, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, - 0x04, 0x70, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x70, 0x61, 0x67, - 0x65, 0x12, 0x12, 0x0a, 0x04, 0x73, 0x69, 0x7a, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, - 0x04, 0x73, 0x69, 0x7a, 0x65, 0x12, 0x0c, 0x0a, 0x01, 0x71, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x01, 0x71, 0x12, 0x12, 0x0a, 0x04, 0x73, 0x6f, 0x72, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x04, 0x73, 0x6f, 0x72, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x66, 0x69, 0x65, 0x6c, 0x64, - 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x09, 0x52, 0x06, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x73, 0x12, - 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x06, 0x20, 0x03, 0x28, 0x0d, 0x52, 0x02, 0x69, 0x64, 0x12, - 0x14, 0x0a, 0x05, 0x71, 0x75, 0x65, 0x75, 0x65, 0x18, 0x07, 0x20, 0x03, 0x28, 0x0d, 0x52, 0x05, - 0x71, 0x75, 0x65, 0x75, 0x65, 0x12, 0x2a, 0x0a, 0x11, 0x72, 0x65, 0x73, 0x74, 0x72, 0x69, 0x63, - 0x74, 0x5f, 0x74, 0x6f, 0x5f, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x18, 0x08, 0x20, 0x01, 0x28, 0x08, - 0x52, 0x0f, 0x72, 0x65, 0x73, 0x74, 0x72, 0x69, 0x63, 0x74, 0x54, 0x6f, 0x41, 0x67, 0x65, 0x6e, - 0x74, 0x22, 0x50, 0x0a, 0x10, 0x4c, 0x69, 0x73, 0x74, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x52, 0x65, - 0x70, 0x6c, 0x69, 0x65, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x65, 0x78, 0x74, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x08, 0x52, 0x04, 0x6e, 0x65, 0x78, 0x74, 0x12, 0x28, 0x0a, 0x05, 0x69, 0x74, 0x65, - 0x6d, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x65, 0x6e, 0x67, 0x69, 0x6e, - 0x65, 0x2e, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x52, 0x05, 0x69, 0x74, - 0x65, 0x6d, 0x73, 0x22, 0x27, 0x0a, 0x15, 0x52, 0x65, 0x61, 0x64, 0x51, 0x75, 0x69, 0x63, 0x6b, - 0x52, 0x65, 0x70, 0x6c, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, - 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x02, 0x69, 0x64, 0x22, 0xe0, 0x01, 0x0a, - 0x16, 0x50, 0x61, 0x74, 0x63, 0x68, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x52, 0x65, 0x70, 0x6c, 0x79, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x0d, 0x52, 0x02, 0x69, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x66, 0x69, 0x65, 0x6c, 0x64, - 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x06, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x73, 0x12, - 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, - 0x61, 0x6d, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x65, 0x78, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x04, 0x74, 0x65, 0x78, 0x74, 0x12, 0x24, 0x0a, 0x05, 0x74, 0x65, 0x61, 0x6d, 0x73, - 0x18, 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x2e, - 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x52, 0x05, 0x74, 0x65, 0x61, 0x6d, 0x73, 0x12, 0x28, 0x0a, - 0x07, 0x61, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, - 0x2e, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x2e, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x52, 0x07, - 0x61, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x12, 0x26, 0x0a, 0x06, 0x71, 0x75, 0x65, 0x75, 0x65, - 0x73, 0x18, 0x07, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, - 0x2e, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x52, 0x06, 0x71, 0x75, 0x65, 0x75, 0x65, 0x73, 0x22, - 0xc9, 0x01, 0x0a, 0x17, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x52, - 0x65, 0x70, 0x6c, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, - 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, - 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, - 0x12, 0x0a, 0x04, 0x74, 0x65, 0x78, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, - 0x65, 0x78, 0x74, 0x12, 0x24, 0x0a, 0x05, 0x74, 0x65, 0x61, 0x6d, 0x73, 0x18, 0x04, 0x20, 0x03, + 0x6f, 0x6b, 0x75, 0x70, 0x52, 0x09, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x42, 0x79, 0x12, + 0x1d, 0x0a, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, 0x04, 0x20, + 0x01, 0x28, 0x03, 0x52, 0x09, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74, 0x12, 0x2d, + 0x0a, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x62, 0x79, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x2e, 0x4c, 0x6f, 0x6f, 0x6b, - 0x75, 0x70, 0x52, 0x05, 0x74, 0x65, 0x61, 0x6d, 0x73, 0x12, 0x28, 0x0a, 0x07, 0x61, 0x72, 0x74, - 0x69, 0x63, 0x6c, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x65, 0x6e, 0x67, - 0x69, 0x6e, 0x65, 0x2e, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x52, 0x07, 0x61, 0x72, 0x74, 0x69, - 0x63, 0x6c, 0x65, 0x12, 0x26, 0x0a, 0x06, 0x71, 0x75, 0x65, 0x75, 0x65, 0x73, 0x18, 0x06, 0x20, - 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x2e, 0x4c, 0x6f, 0x6f, - 0x6b, 0x75, 0x70, 0x52, 0x06, 0x71, 0x75, 0x65, 0x75, 0x65, 0x73, 0x22, 0x29, 0x0a, 0x17, 0x44, - 0x65, 0x6c, 0x65, 0x74, 0x65, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x0d, 0x52, 0x02, 0x69, 0x64, 0x32, 0xc4, 0x05, 0x0a, 0x13, 0x51, 0x75, 0x69, 0x63, 0x6b, - 0x52, 0x65, 0x70, 0x6c, 0x69, 0x65, 0x73, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x6e, - 0x0a, 0x10, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x52, 0x65, 0x70, - 0x6c, 0x79, 0x12, 0x1f, 0x2e, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x2e, 0x43, 0x72, 0x65, 0x61, - 0x74, 0x65, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x2e, 0x51, 0x75, 0x69, - 0x63, 0x6b, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x25, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1f, 0x3a, - 0x01, 0x2a, 0x22, 0x1a, 0x2f, 0x63, 0x61, 0x6c, 0x6c, 0x5f, 0x63, 0x65, 0x6e, 0x74, 0x65, 0x72, - 0x2f, 0x71, 0x75, 0x69, 0x63, 0x6b, 0x5f, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x65, 0x73, 0x12, 0x75, - 0x0a, 0x12, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x52, 0x65, 0x70, - 0x6c, 0x69, 0x65, 0x73, 0x12, 0x21, 0x2e, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x2e, 0x53, 0x65, - 0x61, 0x72, 0x63, 0x68, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x52, 0x65, 0x70, 0x6c, 0x69, 0x65, 0x73, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, - 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x52, 0x65, 0x70, 0x6c, 0x69, 0x65, - 0x73, 0x22, 0x22, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1c, 0x12, 0x1a, 0x2f, 0x63, 0x61, 0x6c, 0x6c, - 0x5f, 0x63, 0x65, 0x6e, 0x74, 0x65, 0x72, 0x2f, 0x71, 0x75, 0x69, 0x63, 0x6b, 0x5f, 0x72, 0x65, - 0x70, 0x6c, 0x69, 0x65, 0x73, 0x12, 0x6c, 0x0a, 0x0e, 0x52, 0x65, 0x61, 0x64, 0x51, 0x75, 0x69, - 0x63, 0x6b, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x1d, 0x2e, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, - 0x2e, 0x52, 0x65, 0x61, 0x64, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x2e, - 0x51, 0x75, 0x69, 0x63, 0x6b, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x27, 0x82, 0xd3, 0xe4, 0x93, - 0x02, 0x21, 0x12, 0x1f, 0x2f, 0x63, 0x61, 0x6c, 0x6c, 0x5f, 0x63, 0x65, 0x6e, 0x74, 0x65, 0x72, - 0x2f, 0x71, 0x75, 0x69, 0x63, 0x6b, 0x5f, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x65, 0x73, 0x2f, 0x7b, - 0x69, 0x64, 0x7d, 0x12, 0x71, 0x0a, 0x0f, 0x50, 0x61, 0x74, 0x63, 0x68, 0x51, 0x75, 0x69, 0x63, - 0x6b, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x1e, 0x2e, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x2e, - 0x50, 0x61, 0x74, 0x63, 0x68, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x2e, - 0x51, 0x75, 0x69, 0x63, 0x6b, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x2a, 0x82, 0xd3, 0xe4, 0x93, - 0x02, 0x24, 0x3a, 0x01, 0x2a, 0x32, 0x1f, 0x2f, 0x63, 0x61, 0x6c, 0x6c, 0x5f, 0x63, 0x65, 0x6e, - 0x74, 0x65, 0x72, 0x2f, 0x71, 0x75, 0x69, 0x63, 0x6b, 0x5f, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x65, - 0x73, 0x2f, 0x7b, 0x69, 0x64, 0x7d, 0x12, 0x73, 0x0a, 0x10, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, - 0x51, 0x75, 0x69, 0x63, 0x6b, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x1f, 0x2e, 0x65, 0x6e, 0x67, - 0x69, 0x6e, 0x65, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x52, - 0x65, 0x70, 0x6c, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x65, 0x6e, - 0x67, 0x69, 0x6e, 0x65, 0x2e, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, - 0x2a, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x24, 0x3a, 0x01, 0x2a, 0x1a, 0x1f, 0x2f, 0x63, 0x61, 0x6c, + 0x75, 0x70, 0x52, 0x09, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x42, 0x79, 0x12, 0x12, 0x0a, + 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, + 0x65, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x65, 0x78, 0x74, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x04, 0x74, 0x65, 0x78, 0x74, 0x12, 0x24, 0x0a, 0x05, 0x74, 0x65, 0x61, 0x6d, 0x73, 0x18, 0x08, + 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x2e, 0x4c, 0x6f, + 0x6f, 0x6b, 0x75, 0x70, 0x52, 0x05, 0x74, 0x65, 0x61, 0x6d, 0x73, 0x12, 0x28, 0x0a, 0x07, 0x61, + 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x18, 0x09, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x65, + 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x2e, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x52, 0x07, 0x61, 0x72, + 0x74, 0x69, 0x63, 0x6c, 0x65, 0x12, 0x26, 0x0a, 0x06, 0x71, 0x75, 0x65, 0x75, 0x65, 0x73, 0x18, + 0x0a, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x2e, 0x4c, + 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x52, 0x06, 0x71, 0x75, 0x65, 0x75, 0x65, 0x73, 0x12, 0x18, 0x0a, + 0x07, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, + 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x12, 0x12, 0x0a, 0x04, 0x68, 0x74, 0x6d, 0x6c, 0x18, + 0x0c, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x68, 0x74, 0x6d, 0x6c, 0x22, 0xe9, 0x01, 0x0a, 0x19, + 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x52, 0x65, 0x70, 0x6c, 0x69, + 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x61, 0x67, + 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x70, 0x61, 0x67, 0x65, 0x12, 0x12, 0x0a, + 0x04, 0x73, 0x69, 0x7a, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x73, 0x69, 0x7a, + 0x65, 0x12, 0x0c, 0x0a, 0x01, 0x71, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x01, 0x71, 0x12, + 0x12, 0x0a, 0x04, 0x73, 0x6f, 0x72, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x73, + 0x6f, 0x72, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x73, 0x18, 0x05, 0x20, + 0x03, 0x28, 0x09, 0x52, 0x06, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x73, 0x12, 0x0e, 0x0a, 0x02, 0x69, + 0x64, 0x18, 0x06, 0x20, 0x03, 0x28, 0x0d, 0x52, 0x02, 0x69, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x71, + 0x75, 0x65, 0x75, 0x65, 0x18, 0x07, 0x20, 0x03, 0x28, 0x0d, 0x52, 0x05, 0x71, 0x75, 0x65, 0x75, + 0x65, 0x12, 0x2a, 0x0a, 0x11, 0x72, 0x65, 0x73, 0x74, 0x72, 0x69, 0x63, 0x74, 0x5f, 0x74, 0x6f, + 0x5f, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x18, 0x08, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0f, 0x72, 0x65, + 0x73, 0x74, 0x72, 0x69, 0x63, 0x74, 0x54, 0x6f, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x12, 0x18, 0x0a, + 0x07, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, + 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x22, 0x50, 0x0a, 0x10, 0x4c, 0x69, 0x73, 0x74, 0x51, + 0x75, 0x69, 0x63, 0x6b, 0x52, 0x65, 0x70, 0x6c, 0x69, 0x65, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x6e, + 0x65, 0x78, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x04, 0x6e, 0x65, 0x78, 0x74, 0x12, + 0x28, 0x0a, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x12, + 0x2e, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x2e, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x52, 0x65, 0x70, + 0x6c, 0x79, 0x52, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x22, 0x27, 0x0a, 0x15, 0x52, 0x65, 0x61, + 0x64, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x02, + 0x69, 0x64, 0x22, 0xf4, 0x01, 0x0a, 0x16, 0x50, 0x61, 0x74, 0x63, 0x68, 0x51, 0x75, 0x69, 0x63, + 0x6b, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, + 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x02, 0x69, 0x64, 0x12, 0x16, 0x0a, + 0x06, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x06, 0x66, + 0x69, 0x65, 0x6c, 0x64, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x65, 0x78, + 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x65, 0x78, 0x74, 0x12, 0x24, 0x0a, + 0x05, 0x74, 0x65, 0x61, 0x6d, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x65, + 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x2e, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x52, 0x05, 0x74, 0x65, + 0x61, 0x6d, 0x73, 0x12, 0x28, 0x0a, 0x07, 0x61, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x18, 0x06, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x2e, 0x4c, 0x6f, + 0x6f, 0x6b, 0x75, 0x70, 0x52, 0x07, 0x61, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x12, 0x26, 0x0a, + 0x06, 0x71, 0x75, 0x65, 0x75, 0x65, 0x73, 0x18, 0x07, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, + 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x2e, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x52, 0x06, 0x71, + 0x75, 0x65, 0x75, 0x65, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x68, 0x74, 0x6d, 0x6c, 0x18, 0x08, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x04, 0x68, 0x74, 0x6d, 0x6c, 0x22, 0xdd, 0x01, 0x0a, 0x17, 0x55, 0x70, + 0x64, 0x61, 0x74, 0x65, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x0d, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x65, 0x78, + 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x65, 0x78, 0x74, 0x12, 0x24, 0x0a, + 0x05, 0x74, 0x65, 0x61, 0x6d, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x65, + 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x2e, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x52, 0x05, 0x74, 0x65, + 0x61, 0x6d, 0x73, 0x12, 0x28, 0x0a, 0x07, 0x61, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x18, 0x05, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x2e, 0x4c, 0x6f, + 0x6f, 0x6b, 0x75, 0x70, 0x52, 0x07, 0x61, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x12, 0x26, 0x0a, + 0x06, 0x71, 0x75, 0x65, 0x75, 0x65, 0x73, 0x18, 0x06, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, + 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x2e, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x52, 0x06, 0x71, + 0x75, 0x65, 0x75, 0x65, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x68, 0x74, 0x6d, 0x6c, 0x18, 0x07, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x04, 0x68, 0x74, 0x6d, 0x6c, 0x22, 0x29, 0x0a, 0x17, 0x44, 0x65, 0x6c, + 0x65, 0x74, 0x65, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, + 0x52, 0x02, 0x69, 0x64, 0x32, 0xc4, 0x05, 0x0a, 0x13, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x52, 0x65, + 0x70, 0x6c, 0x69, 0x65, 0x73, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x6e, 0x0a, 0x10, + 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x52, 0x65, 0x70, 0x6c, 0x79, + 0x12, 0x1f, 0x2e, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, + 0x51, 0x75, 0x69, 0x63, 0x6b, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x1a, 0x12, 0x2e, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x2e, 0x51, 0x75, 0x69, 0x63, 0x6b, + 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x25, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1f, 0x3a, 0x01, 0x2a, + 0x22, 0x1a, 0x2f, 0x63, 0x61, 0x6c, 0x6c, 0x5f, 0x63, 0x65, 0x6e, 0x74, 0x65, 0x72, 0x2f, 0x71, + 0x75, 0x69, 0x63, 0x6b, 0x5f, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x65, 0x73, 0x12, 0x75, 0x0a, 0x12, + 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x52, 0x65, 0x70, 0x6c, 0x69, + 0x65, 0x73, 0x12, 0x21, 0x2e, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x2e, 0x53, 0x65, 0x61, 0x72, + 0x63, 0x68, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x52, 0x65, 0x70, 0x6c, 0x69, 0x65, 0x73, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x2e, 0x4c, + 0x69, 0x73, 0x74, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x52, 0x65, 0x70, 0x6c, 0x69, 0x65, 0x73, 0x22, + 0x22, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1c, 0x12, 0x1a, 0x2f, 0x63, 0x61, 0x6c, 0x6c, 0x5f, 0x63, + 0x65, 0x6e, 0x74, 0x65, 0x72, 0x2f, 0x71, 0x75, 0x69, 0x63, 0x6b, 0x5f, 0x72, 0x65, 0x70, 0x6c, + 0x69, 0x65, 0x73, 0x12, 0x6c, 0x0a, 0x0e, 0x52, 0x65, 0x61, 0x64, 0x51, 0x75, 0x69, 0x63, 0x6b, + 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x1d, 0x2e, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x2e, 0x52, + 0x65, 0x61, 0x64, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x2e, 0x51, 0x75, + 0x69, 0x63, 0x6b, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x27, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x21, + 0x12, 0x1f, 0x2f, 0x63, 0x61, 0x6c, 0x6c, 0x5f, 0x63, 0x65, 0x6e, 0x74, 0x65, 0x72, 0x2f, 0x71, + 0x75, 0x69, 0x63, 0x6b, 0x5f, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x65, 0x73, 0x2f, 0x7b, 0x69, 0x64, + 0x7d, 0x12, 0x71, 0x0a, 0x0f, 0x50, 0x61, 0x74, 0x63, 0x68, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x52, + 0x65, 0x70, 0x6c, 0x79, 0x12, 0x1e, 0x2e, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x2e, 0x50, 0x61, + 0x74, 0x63, 0x68, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x2e, 0x51, 0x75, + 0x69, 0x63, 0x6b, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x2a, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x24, + 0x3a, 0x01, 0x2a, 0x32, 0x1f, 0x2f, 0x63, 0x61, 0x6c, 0x6c, 0x5f, 0x63, 0x65, 0x6e, 0x74, 0x65, + 0x72, 0x2f, 0x71, 0x75, 0x69, 0x63, 0x6b, 0x5f, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x65, 0x73, 0x2f, + 0x7b, 0x69, 0x64, 0x7d, 0x12, 0x73, 0x0a, 0x10, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x51, 0x75, + 0x69, 0x63, 0x6b, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x1f, 0x2e, 0x65, 0x6e, 0x67, 0x69, 0x6e, + 0x65, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x52, 0x65, 0x70, + 0x6c, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x65, 0x6e, 0x67, 0x69, + 0x6e, 0x65, 0x2e, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x2a, 0x82, + 0xd3, 0xe4, 0x93, 0x02, 0x24, 0x3a, 0x01, 0x2a, 0x1a, 0x1f, 0x2f, 0x63, 0x61, 0x6c, 0x6c, 0x5f, + 0x63, 0x65, 0x6e, 0x74, 0x65, 0x72, 0x2f, 0x71, 0x75, 0x69, 0x63, 0x6b, 0x5f, 0x72, 0x65, 0x70, + 0x6c, 0x69, 0x65, 0x73, 0x2f, 0x7b, 0x69, 0x64, 0x7d, 0x12, 0x70, 0x0a, 0x10, 0x44, 0x65, 0x6c, + 0x65, 0x74, 0x65, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x1f, 0x2e, + 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x51, 0x75, 0x69, + 0x63, 0x6b, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, + 0x2e, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x2e, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x52, 0x65, 0x70, + 0x6c, 0x79, 0x22, 0x27, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x21, 0x2a, 0x1f, 0x2f, 0x63, 0x61, 0x6c, 0x6c, 0x5f, 0x63, 0x65, 0x6e, 0x74, 0x65, 0x72, 0x2f, 0x71, 0x75, 0x69, 0x63, 0x6b, 0x5f, 0x72, - 0x65, 0x70, 0x6c, 0x69, 0x65, 0x73, 0x2f, 0x7b, 0x69, 0x64, 0x7d, 0x12, 0x70, 0x0a, 0x10, 0x44, - 0x65, 0x6c, 0x65, 0x74, 0x65, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, - 0x1f, 0x2e, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x51, - 0x75, 0x69, 0x63, 0x6b, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x1a, 0x12, 0x2e, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x2e, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x52, - 0x65, 0x70, 0x6c, 0x79, 0x22, 0x27, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x21, 0x2a, 0x1f, 0x2f, 0x63, - 0x61, 0x6c, 0x6c, 0x5f, 0x63, 0x65, 0x6e, 0x74, 0x65, 0x72, 0x2f, 0x71, 0x75, 0x69, 0x63, 0x6b, - 0x5f, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x65, 0x73, 0x2f, 0x7b, 0x69, 0x64, 0x7d, 0x42, 0x22, 0x5a, - 0x20, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x77, 0x65, 0x62, 0x69, - 0x74, 0x65, 0x6c, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2f, 0x65, 0x6e, 0x67, 0x69, 0x6e, - 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x65, 0x70, 0x6c, 0x69, 0x65, 0x73, 0x2f, 0x7b, 0x69, 0x64, 0x7d, 0x42, 0x22, 0x5a, 0x20, 0x67, + 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x77, 0x65, 0x62, 0x69, 0x74, 0x65, + 0x6c, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2f, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/go.mod b/go.mod index 15644241..c09aa692 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 @@ -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 diff --git a/go.sum b/go.sum index d3d91ad0..bc26e7d1 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= @@ -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= diff --git a/grpc_api/cc_quick_reply.go b/grpc_api/cc_quick_reply.go index 6fd12023..30b59f5a 100644 --- a/grpc_api/cc_quick_reply.go +++ b/grpc_api/cc_quick_reply.go @@ -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) @@ -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) @@ -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 @@ -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) @@ -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, } } diff --git a/model/cc_quick_reply.go b/model/cc_quick_reply.go index a7917dfc..89b57ce2 100644 --- a/model/cc_quick_reply.go +++ b/model/cc_quick_reply.go @@ -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 } @@ -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 { diff --git a/model/cc_quick_reply_email.go b/model/cc_quick_reply_email.go new file mode 100644 index 00000000..52ec46b5 --- /dev/null +++ b/model/cc_quick_reply_email.go @@ -0,0 +1,196 @@ +package model + +import ( + "fmt" + "math" + "strings" + + "github.com/microcosm-cc/bluemonday" + "golang.org/x/net/html" +) + +const ( + QuickReplyChannelEmail = "email" + + quickReplyEmailMaxBody = 64 << 10 + quickReplyEmailVarOpen = "${" +) + +var ( + quickReplyEmailVars = map[string]struct{}{ + "agent_name": {}, "contact_name": {}, "thread_id": {}, "thread_subject": {}, + } + // quickReplyEmailPatchFields are the PATCH mask paths of an Email reply. + quickReplyEmailPatchFields = map[string]struct{}{ + "name": {}, "text": {}, "html": {}, "teams": {}, "queues": {}, + } + quickReplyEmailPolicy = newQuickReplyEmailPolicy() +) + +// A small subset of the Email read policy: formatting and static links only. +func newQuickReplyEmailPolicy() *bluemonday.Policy { + p := bluemonday.NewPolicy() + p.AllowElements("p", "br", "div", "span", "b", "strong", "i", "em", "u", "s", + "ul", "ol", "li", "blockquote") + p.AllowAttrs("href").OnElements("a") + p.AllowURLSchemes("http", "https", "mailto") + p.RequireParseableURLs(true) + return p +} + +func IsValidQuickReplyChannel(channel string) bool { + return channel == "" || channel == QuickReplyChannelEmail +} + +func NewQuickReplyChannelError(channel string) AppError { + return NewBadRequestError("quick_reply.email.invalid_channel", fmt.Sprintf("unknown channel %q", channel)) +} + +func NewQuickReplyRestrictionError() AppError { + return NewBadRequestError("quick_reply.email.invalid_restriction", "team or queue is not found in the domain") +} + +func (r *QuickReply) IsEmail() bool { + return r.Channel == QuickReplyChannelEmail +} + +// PatchEmail applies the supported paths of the mask to an Email reply and +// returns them. +func (r *QuickReply) PatchEmail(patch *QuickReplyPatch) (map[string]bool, AppError) { + fields := make(map[string]bool, len(patch.Fields)) + for _, f := range patch.Fields { + if _, ok := quickReplyEmailPatchFields[f]; ok { + fields[f] = true + } + } + if len(fields) == 0 { + return nil, NewBadRequestError("quick_reply.email.empty_patch", "no fields to update") + } + + r.UpdatedAt = patch.UpdatedAt + r.UpdatedBy = &patch.UpdatedBy + if fields["name"] && patch.Name != nil { + r.Name = *patch.Name + } + if fields["text"] && patch.Text != nil { + r.Text = *patch.Text + } + if fields["html"] && patch.Html != nil { + r.Html = *patch.Html + } + if fields["teams"] { + r.Teams = patch.Teams + } + if fields["queues"] { + r.Queues = patch.Queues + } + + return fields, nil +} + +// PrepareEmail validates an Email reply and keeps its sanitized HTML. +func (r *QuickReply) PrepareEmail() AppError { + r.Article = nil + if strings.TrimSpace(r.Text) == "" { + return NewBadRequestError("quick_reply.email.text_required", "text is required") + } + if len(r.Text) > quickReplyEmailMaxBody || len(r.Html) > quickReplyEmailMaxBody { + return quickReplyBodyTooLarge() + } + if err := checkQuickReplyVars(r.Text); err != nil { + return err + } + // Queue ids are integer in the database. + for _, t := range r.Teams { + if t == nil || t.Id <= 0 { + return NewQuickReplyRestrictionError() + } + } + for _, q := range r.Queues { + if q == nil || q.Id <= 0 || q.Id > math.MaxInt32 { + return NewQuickReplyRestrictionError() + } + } + + if r.Html == "" { + return nil + } + // Before sanitizing: the policy drops a link with a variable silently. + if _, err := checkQuickReplyHTMLVars(r.Html, false); err != nil { + return err + } + clean := quickReplyEmailPolicy.Sanitize(r.Html) + if len(clean) > quickReplyEmailMaxBody { + return quickReplyBodyTooLarge() + } + visible, err := checkQuickReplyHTMLVars(clean, true) + if err != nil { + return err + } + if !visible { + clean = "" + } + r.Html = clean + + return nil +} + +func quickReplyBodyTooLarge() AppError { + return NewBadRequestError("quick_reply.email.body_too_large", + fmt.Sprintf("text and html are limited to %d bytes each", quickReplyEmailMaxBody)) +} + +// checkQuickReplyVars requires every "${" to start a supported variable. +func checkQuickReplyVars(s string) AppError { + for { + i := strings.Index(s, quickReplyEmailVarOpen) + if i < 0 { + return nil + } + s = s[i+len(quickReplyEmailVarOpen):] + end := strings.IndexByte(s, '}') + if end < 0 { + return NewBadRequestError("quick_reply.email.invalid_token", "unclosed variable") + } + if _, ok := quickReplyEmailVars[s[:end]]; !ok { + return NewBadRequestError("quick_reply.email.invalid_token", fmt.Sprintf("unknown variable %q", s[:end])) + } + s = s[end+1:] + } +} + +// checkQuickReplyHTMLVars refuses variables in a[href], or with text in any +// attribute and checks text nodes; it reports whether text is visible. +func checkQuickReplyHTMLVars(s string, text bool) (bool, AppError) { + visible := false + z := html.NewTokenizer(strings.NewReader(s)) + for { + switch z.Next() { + case html.ErrorToken: + // Only io.EOF: the input is a string. + return visible, nil + case html.TextToken: + if !text { + continue + } + t := z.Token() + if strings.TrimSpace(t.Data) != "" { + visible = true + } + if err := checkQuickReplyVars(t.Data); err != nil { + return false, err + } + case html.StartTagToken, html.SelfClosingTagToken: + t := z.Token() + for _, a := range t.Attr { + if !text && (t.Data != "a" || a.Key != "href") { + continue + } + if strings.Contains(a.Val, quickReplyEmailVarOpen) { + return false, NewBadRequestError("quick_reply.email.token_in_attribute", + fmt.Sprintf("variable in attribute %q", a.Key)) + } + } + } + } +} diff --git a/model/cc_quick_reply_email_test.go b/model/cc_quick_reply_email_test.go new file mode 100644 index 00000000..f1798660 --- /dev/null +++ b/model/cc_quick_reply_email_test.go @@ -0,0 +1,121 @@ +package model_test + +import ( + "strings" + "testing" + + "github.com/webitel/engine/model" +) + +func appErrId(err model.AppError) string { + if err == nil { + return "" + } + return err.GetId() +} + +func TestQuickReply_PrepareEmail(t *testing.T) { + t.Parallel() + + for _, tc := range []struct { + name, text, html, want, err string + teams, queues []int + }{ + {name: "plain only", text: "Hello ${agent_name}"}, + {name: "formatting kept", text: "x", + html: `

Hi ${contact_name}, ref

`, + want: `

Hi ${contact_name}, ref

`}, + {name: "active content and styles removed", text: "x", + html: `

A

B`, + want: `

A

B`}, + {name: "markup without text cleared", text: "x", html: "


", want: ""}, + {name: "decoded entity checked", text: "x", html: "

${secret}

", err: "quick_reply.email.invalid_token"}, + {name: "unknown variable", text: "${contact_email}", err: "quick_reply.email.invalid_token"}, + {name: "case sensitive", text: "${Agent_name}", err: "quick_reply.email.invalid_token"}, + {name: "unclosed variable", text: "Hi ${agent_name", err: "quick_reply.email.invalid_token"}, + {name: "variable in link", text: "x", html: `t`, + err: "quick_reply.email.token_in_attribute"}, + {name: "variable in removed attribute ignored", text: "x", html: `

t

`, want: "

t

"}, + {name: "variable in removed script ignored", text: "x", html: `

t

`, want: "

t

"}, + {name: "team id", text: "x", teams: []int{0}, err: "quick_reply.email.invalid_restriction"}, + {name: "queue id above integer", text: "x", queues: []int{1 << 31}, err: "quick_reply.email.invalid_restriction"}, + {name: "queue id at integer limit", text: "x", queues: []int{1<<31 - 1}}, + {name: "text required", text: " \n", err: "quick_reply.email.text_required"}, + {name: "text too large", text: strings.Repeat("a", 64<<10+1), err: "quick_reply.email.body_too_large"}, + {name: "html too large", text: "x", html: strings.Repeat("a", 64<<10+1), err: "quick_reply.email.body_too_large"}, + } { + t.Run(tc.name, func(t *testing.T) { + r := &model.QuickReply{Channel: "email", Text: tc.text, Html: tc.html, Article: &model.Lookup{Id: 1}} + for _, id := range tc.teams { + r.Teams = append(r.Teams, &model.Lookup{Id: id}) + } + for _, id := range tc.queues { + r.Queues = append(r.Queues, &model.Lookup{Id: id}) + } + err := r.PrepareEmail() + if got := appErrId(err); got != tc.err { + t.Fatalf("error %q, want %q", got, tc.err) + } + if err != nil { + return + } + if r.Html != tc.want { + t.Fatalf("html %q, want %q", r.Html, tc.want) + } + if r.Article != nil { + t.Fatal("article kept") + } + }) + } +} + +func TestQuickReply_PatchEmail(t *testing.T) { + t.Parallel() + + stored := func() *model.QuickReply { + return &model.QuickReply{Channel: "email", Name: "n", Text: "t", Html: "

h

", + Teams: []*model.Lookup{{Id: 1}}, Queues: []*model.Lookup{{Id: 2}}} + } + patch := func(fields ...string) *model.QuickReplyPatch { + return &model.QuickReplyPatch{Fields: fields, Name: model.NewString(""), Text: model.NewString(""), + Html: model.NewString("")} + } + + for _, fields := range [][]string{nil, {""}, {"fields", "article.id", "id"}} { + if _, err := stored().PatchEmail(patch(fields...)); appErrId(err) != "quick_reply.email.empty_patch" { + t.Fatalf("fields %q: error %q", fields, appErrId(err)) + } + } + + r := stored() + p := patch("name", "fields") + p.Name = model.NewString("renamed") + fields, err := r.PatchEmail(p) + if err != nil { + t.Fatal(err) + } + if len(fields) != 1 || !fields["name"] { + t.Fatalf("fields %v", fields) + } + if r.Name != "renamed" || r.Text != "t" || r.Html != "

h

" || len(r.Teams) != 1 || len(r.Queues) != 1 { + t.Fatalf("name only changed other fields: %+v", r) + } + + r = stored() + if _, err := r.PatchEmail(patch("html", "teams")); err != nil { + t.Fatal(err) + } + if r.Html != "" || r.Teams != nil || r.Text != "t" || len(r.Queues) != 1 { + t.Fatalf("html and teams not cleared: %+v", r) + } +} + +func TestIsValidQuickReplyChannel(t *testing.T) { + t.Parallel() + + for ch, want := range map[string]bool{"": true, "email": true, "Email": false, "chat": false} { + if model.IsValidQuickReplyChannel(ch) != want { + t.Fatalf("channel %q", ch) + } + } +} diff --git a/store/sqlstore/cc_quick_reply_store.go b/store/sqlstore/cc_quick_reply_store.go index 3506bf66..6539f930 100644 --- a/store/sqlstore/cc_quick_reply_store.go +++ b/store/sqlstore/cc_quick_reply_store.go @@ -2,6 +2,8 @@ package sqlstore import ( "context" + "database/sql" + "errors" "fmt" "strings" @@ -28,6 +30,34 @@ func quickReplySearchPattern(q *string) *string { return model.NewString("%" + *q + "%") } +// quickReplyInDomain is true when all :Teams and :Queues exist in :DomainId. +const quickReplyInDomain = `((select count(*) from call_center.cc_team t + where t.domain_id = :DomainId and t.id = any(:Teams::bigint[])) + = (select count(distinct x) from unnest(coalesce(:Teams::bigint[], '{}')) x) + and (select count(*) from call_center.cc_queue q + where q.domain_id = :DomainId and q.id = any(:Queues::int[])) + = (select count(distinct x) from unnest(coalesce(:Queues::int[], '{}')) x))` + +// quickReplyWritten reads the row written by the CTE s. +const quickReplyWritten = ` select s.id + , s.created_at + , call_center.cc_get_lookup(uc.id, coalesce(uc.name, uc.username)) as created_by + , s.updated_at + , call_center.cc_get_lookup(uc.id, coalesce(uc.name, uc.username)) as updated_by + , s.name + , s.text + , s.channel + , s.html + , (select jsonb_agg(call_center.cc_get_lookup(t.id, t.name)) + from call_center.cc_team t + where t.id = any (s.teams)) as teams + , (select jsonb_agg(call_center.cc_get_lookup(a.id::bigint, a.name)) + from call_center.cc_queue a + where a.id = any (s.queues)) as queues + from s + left join directory.wbt_user uc on uc.id = s.created_by + left join directory.wbt_user uu on uu.id = s.updated_by` + func (s SqlQuickReplyStore) Create(ctx context.Context, domainId int64, reply *model.QuickReply) (*model.QuickReply, model.AppError) { var resp *model.QuickReply @@ -42,34 +72,24 @@ func (s SqlQuickReplyStore) Create(ctx context.Context, domainId int64, reply *m "Article": reply.Article.GetSafeId(), "Teams": pq.Array(model.LookupIds(reply.Teams)), "Queues": pq.Array(model.LookupIds(reply.Queues)), + "Channel": reply.Channel, + "Html": reply.Html, } query := `with s as ( insert into call_center.cc_quick_reply (domain_id, created_at, updated_at, created_by, updated_by, - name, text, article, teams, queues) - values (:DomainId, :CreatedAt, :UpdatedAt, :CreatedBy, :UpdatedBy, - :Name, :Text, :Article, :Teams, :Queues) + name, text, article, teams, queues, channel, html) + select :DomainId, :CreatedAt, :UpdatedAt, :CreatedBy, :UpdatedBy, + :Name, :Text, :Article, :Teams::bigint[], :Queues::int[], :Channel, :Html + where :Channel <> 'email' or ` + quickReplyInDomain + ` returning * ) - - select s.id - , s.created_at - , call_center.cc_get_lookup(uc.id, coalesce(uc.name, uc.username)) as created_by - , s.updated_at - , call_center.cc_get_lookup(uc.id, coalesce(uc.name, uc.username)) as updated_by - , s.name - , s.text - , ( SELECT jsonb_agg(call_center.cc_get_lookup(t.id, t.name)) AS jsonb_agg - FROM call_center.cc_team t - WHERE t.id = ANY (s.teams)) AS teams - , ( SELECT jsonb_agg(call_center.cc_get_lookup(a.id::bigint, a.name)) AS jsonb_agg - FROM call_center.cc_queue a - WHERE a.id = ANY (s.queues)) AS queues - from s - left join directory.wbt_user uc on uc.id = s.created_by - left join directory.wbt_user uu on uu.id = s.updated_by` +` + quickReplyWritten if err := s.GetMaster().WithContext(ctx).SelectOne(&resp, query, args); err != nil { + if errors.Is(err, sql.ErrNoRows) && reply.IsEmail() { + return nil, model.NewQuickReplyRestrictionError() + } return nil, model.NewCustomCodeError("store.sql_quick_reply.create.app_error", fmt.Sprintf("name=%v, %v", reply.Name, err.Error()), extractCodeFromErr(err)) } @@ -85,10 +105,12 @@ func (s SqlQuickReplyStore) GetAllPage(ctx context.Context, domainId int64, sear "UserId": userId, "Queue": pq.Array(search.Queue), "RestrictToAgent": search.RestrictToAgent, + "Channel": search.Channel, } where := ` domain_id = :DomainId + AND t.channel = :Channel AND (:Q::varchar isnull OR t.name ILIKE :Q::varchar OR t.text ILIKE :Q::varchar) AND (:Ids::int8[] isnull OR t.id = ANY(:Ids::bigint[])) and ( @@ -124,6 +146,7 @@ func (s SqlQuickReplyStore) GetAllPageByAgentPriority(ctx context.Context, domai "Name": search.Name, "Queue": pq.Array(search.Queue), "RestrictToAgent": search.RestrictToAgent, + "Channel": search.Channel, } fields := GetFields(search.Fields, &model.QuickReply{}) parsedFields := strings.Join(fields, ", ") @@ -151,6 +174,7 @@ func (s SqlQuickReplyStore) GetAllPageByAgentPriority(ctx context.Context, domai end as agent_priority from call_center.cc_quick_reply_list t, agent_info_cte agent_info where t.domain_id = :DomainId + and t.channel = :Channel and (:Q::varchar is null or t.name ilike :Q::varchar or t.text ilike :Q::varchar) and (:Ids::int8[] is null or t.id = any(:Ids::bigint[])) and ( @@ -204,6 +228,8 @@ func (s SqlQuickReplyStore) Update(ctx context.Context, domainId int64, reply *m "Article": reply.Article.GetSafeId(), "Teams": pq.Array(model.LookupIds(reply.Teams)), "Queues": pq.Array(model.LookupIds(reply.Queues)), + "Html": reply.Html, + "Channel": reply.Channel, } query := `with s as ( @@ -214,35 +240,87 @@ func (s SqlQuickReplyStore) Update(ctx context.Context, domainId int64, reply *m text = :Text, article = :Article, teams = :Teams, - queues = :Queues + queues = :Queues, + html = :Html where id = :Id and domain_id = :DomainId + and (:Channel <> 'email' or ` + quickReplyInDomain + `) returning * ) - - select s.id - , s.created_at - , call_center.cc_get_lookup(uc.id, coalesce(uc.name, uc.username)) as created_by - , s.updated_at - , call_center.cc_get_lookup(uc.id, coalesce(uc.name, uc.username)) as updated_by - , s.name - , s.text - , ( SELECT jsonb_agg(call_center.cc_get_lookup(t.id, t.name)) AS jsonb_agg - FROM call_center.cc_team t - WHERE t.id = ANY (s.teams)) AS teams - , ( SELECT jsonb_agg(call_center.cc_get_lookup(a.id::bigint, a.name)) AS jsonb_agg - FROM call_center.cc_queue a - WHERE a.id = ANY (s.queues)) AS queues - from s - left join directory.wbt_user uc on uc.id = s.created_by - left join directory.wbt_user uu on uu.id = s.updated_by` +` + quickReplyWritten + email := reply.IsEmail() if err := s.GetMaster().WithContext(ctx).SelectOne(&reply, query, args); err != nil { + if email { + return nil, s.emailWriteError(ctx, args, err) + } return nil, model.NewCustomCodeError("store.sql_quick_reply.update.app_error", err.Error(), extractCodeFromErr(err)) } return reply, nil } +// PatchEmail writes only the given fields of an Email reply. +func (s SqlQuickReplyStore) PatchEmail(ctx context.Context, domainId int64, reply *model.QuickReply, fields map[string]bool) (*model.QuickReply, model.AppError) { + var teams, queues []int + if fields["teams"] { + teams = model.LookupIds(reply.Teams) + } + if fields["queues"] { + queues = model.LookupIds(reply.Queues) + } + args := map[string]any{ + "DomainId": domainId, + "Id": reply.Id, + "UpdatedAt": reply.UpdatedAt, + "UpdatedBy": reply.UpdatedBy.GetSafeId(), + "Name": reply.Name, + "Text": reply.Text, + "Html": reply.Html, + "Teams": pq.Array(teams), + "Queues": pq.Array(queues), + "SetName": fields["name"], + "SetText": fields["text"], + "SetHtml": fields["html"], + "SetTeams": fields["teams"], + "SetQueues": fields["queues"], + } + + // Unset Teams/Queues are NULL and pass the domain check. + query := `with s as ( + update call_center.cc_quick_reply + set updated_at = :UpdatedAt, + updated_by = :UpdatedBy, + name = case when :SetName then :Name else name end, + text = case when :SetText then :Text else text end, + html = case when :SetHtml then :Html else html end, + teams = case when :SetTeams then :Teams::bigint[] else teams end, + queues = case when :SetQueues then :Queues::int[] else queues end + where id = :Id and domain_id = :DomainId and channel = 'email' + and ` + quickReplyInDomain + ` + returning * + ) +` + quickReplyWritten + + var resp *model.QuickReply + if err := s.GetMaster().WithContext(ctx).SelectOne(&resp, query, args); err != nil { + return nil, s.emailWriteError(ctx, args, err) + } + + return resp, nil +} + +// emailWriteError tells a team or queue of another domain from a missing reply. +func (s SqlQuickReplyStore) emailWriteError(ctx context.Context, args map[string]any, err error) model.AppError { + if errors.Is(err, sql.ErrNoRows) { + ok, e := s.GetMaster().WithContext(ctx).SelectInt(`select (`+quickReplyInDomain+`)::int`, args) + if e == nil && ok == 0 { + return model.NewQuickReplyRestrictionError() + } + } + + return model.NewCustomCodeError("store.sql_quick_reply.update.app_error", err.Error(), extractCodeFromErr(err)) +} + func (s SqlQuickReplyStore) Delete(ctx context.Context, domainId int64, id uint32) model.AppError { if _, err := s.GetMaster().WithContext(ctx).Exec(`delete from call_center.cc_quick_reply c where c.id=:Id and c.domain_id = :DomainId`, map[string]any{"Id": id, "DomainId": domainId}); err != nil { diff --git a/store/store.go b/store/store.go index f5a2b854..b2a82b46 100644 --- a/store/store.go +++ b/store/store.go @@ -474,6 +474,7 @@ type QuickReplyStore interface { Get(ctx context.Context, domainId int64, id uint32) (*model.QuickReply, model.AppError) Update(ctx context.Context, domainId int64, region *model.QuickReply) (*model.QuickReply, model.AppError) Delete(ctx context.Context, domainId int64, id uint32) model.AppError + PatchEmail(ctx context.Context, domainId int64, reply *model.QuickReply, fields map[string]bool) (*model.QuickReply, model.AppError) } type ChatPlanStore interface {