Batch signature and approval notifications via debounced worker
Replace the immediate per-document approval email and the manual "send signing notifications" action with a single debounced worker that batches pending requests per recipient and organization. The worker (go.gearno.de/kit/worker) polls on an interval (default 5m) and claims one (organization, recipient) group at a time, sending one consolidated signing email and/or one approval email per recipient/org that lists every document awaiting their signature or approval. The claim is a conditional UPDATE that doubles as concurrency-safe dedup, so several workers never email the same group twice. Each request is notified once it has been pending past the debounce delay (default 15m), then reminded at 1x, 2x and 3x the reminder interval (default 1 day) after the previous email, after which it stops. New last_notified_at and notification_count columns on signatures and approval decisions drive the debounce, the widening reminder cadence and the four-email cap. Email copy lists each document with its title, type and a deep link to the employee page. Removed the inline approval-on-publish email, the SendSigningNotifications service method/mutation/MCP tool, its IAM action, and the related console UI and n8n operation. Signed-off-by: Sacha Al Himdani <sacha@probo.com>
This commit is contained in:
committed by
Sacha Al Himdani
parent
c9b74bac4a
commit
f462b124e6
@@ -20,7 +20,6 @@ import (
|
||||
"embed"
|
||||
"fmt"
|
||||
htmltemplate "html/template"
|
||||
"net/url"
|
||||
texttemplate "text/template"
|
||||
"time"
|
||||
|
||||
@@ -60,6 +59,12 @@ type (
|
||||
config PresenterConfig
|
||||
RecipientFullName string
|
||||
}
|
||||
|
||||
DocumentSummary struct {
|
||||
Title string
|
||||
Type string
|
||||
URL string
|
||||
}
|
||||
)
|
||||
|
||||
func DefaultPresenterConfig(baseURL string) PresenterConfig {
|
||||
@@ -92,7 +97,7 @@ const (
|
||||
subjectConfirmEmail = "Confirm your email address"
|
||||
subjectPasswordReset = "Reset your password"
|
||||
subjectInvitation = "Invitation to join %s on Probo"
|
||||
subjectDocumentApproval = "Action Required – Please review and approve %s"
|
||||
subjectDocumentApproval = "Action Required – Please review and approve %s compliance documents"
|
||||
subjectDocumentSigning = "Action Required – Please review and sign %s compliance documents"
|
||||
subjectDocumentExport = "Your document export is ready"
|
||||
subjectFrameworkExport = "Your framework export is ready"
|
||||
@@ -231,62 +236,53 @@ func (p *Presenter) RenderInvitation(ctx context.Context, invitationURLPath stri
|
||||
|
||||
func (p *Presenter) RenderDocumentApproval(
|
||||
ctx context.Context,
|
||||
approvalURLPath string,
|
||||
approvalURLQuery url.Values,
|
||||
approvalURL string,
|
||||
organizationName string,
|
||||
documentName string,
|
||||
documents []DocumentSummary,
|
||||
) (subject string, textBody string, htmlBody *string, err error) {
|
||||
vars, err := p.getCommonVariables()
|
||||
if err != nil {
|
||||
return "", "", nil, fmt.Errorf("cannot get common variables: %w", err)
|
||||
}
|
||||
|
||||
approvalURL := baseurl.MustParse(vars.BaseURL).
|
||||
AppendPath(approvalURLPath).
|
||||
WithQueryValues(approvalURLQuery).
|
||||
MustString()
|
||||
|
||||
data := struct {
|
||||
*CommonVariables
|
||||
ApprovalUrl string
|
||||
OrganizationName string
|
||||
DocumentName string
|
||||
Documents []DocumentSummary
|
||||
}{
|
||||
CommonVariables: vars,
|
||||
ApprovalUrl: approvalURL,
|
||||
OrganizationName: organizationName,
|
||||
DocumentName: documentName,
|
||||
Documents: documents,
|
||||
}
|
||||
|
||||
textBody, htmlBody, err = renderEmail(documentApprovalTextTemplate, documentApprovalHTMLTemplate, data)
|
||||
|
||||
return fmt.Sprintf(subjectDocumentApproval, documentName), textBody, htmlBody, err
|
||||
return fmt.Sprintf(subjectDocumentApproval, organizationName), textBody, htmlBody, err
|
||||
}
|
||||
|
||||
func (p *Presenter) RenderDocumentSigning(
|
||||
ctx context.Context,
|
||||
signingURLPath string,
|
||||
signingURLQuery url.Values,
|
||||
signingURL string,
|
||||
organizationName string,
|
||||
documents []DocumentSummary,
|
||||
) (subject string, textBody string, htmlBody *string, err error) {
|
||||
vars, err := p.getCommonVariables()
|
||||
if err != nil {
|
||||
return "", "", nil, fmt.Errorf("cannot get common variables: %w", err)
|
||||
}
|
||||
|
||||
signingURL := baseurl.MustParse(vars.BaseURL).
|
||||
AppendPath(signingURLPath).
|
||||
WithQueryValues(signingURLQuery).
|
||||
MustString()
|
||||
|
||||
data := struct {
|
||||
*CommonVariables
|
||||
SigningUrl string
|
||||
OrganizationName string
|
||||
Documents []DocumentSummary
|
||||
}{
|
||||
CommonVariables: vars,
|
||||
SigningUrl: signingURL,
|
||||
OrganizationName: organizationName,
|
||||
Documents: documents,
|
||||
}
|
||||
|
||||
textBody, htmlBody, err = renderEmail(documentSigningTextTemplate, documentSigningHTMLTemplate, data)
|
||||
|
||||
@@ -16,14 +16,22 @@ import { Button, Section, Text } from 'react-email';
|
||||
import * as React from 'react';
|
||||
import EmailLayout, { bodyText, button, buttonContainer, footerText } from './components/EmailLayout';
|
||||
|
||||
const documentList = {
|
||||
...bodyText,
|
||||
paddingLeft: '20px',
|
||||
};
|
||||
|
||||
export const DocumentApproval = () => {
|
||||
return (
|
||||
<EmailLayout subject={'Action Required – Please review and approve {{.DocumentName}}'}>
|
||||
<EmailLayout subject={'Action Required – Please review and approve {{.OrganizationName}} compliance documents'}>
|
||||
<Text style={bodyText}>
|
||||
You're receiving this message because <strong>{'{{.OrganizationName}}'}</strong> has requested your approval on the document <strong>{'{{.DocumentName}}'}</strong>.
|
||||
You're receiving this message because <strong>{'{{.OrganizationName}}'}</strong> has requested your approval on the following documents:
|
||||
</Text>
|
||||
|
||||
<ul style={documentList} dangerouslySetInnerHTML={{ __html: '{{range .Documents}}<li><a href="{{.URL}}">{{.Title}}</a> ({{.Type}})</li>{{end}}' }} />
|
||||
|
||||
<Text style={bodyText}>
|
||||
Please take a moment to review the document and approve or reject it by clicking the button below:
|
||||
Please take a moment to review them and approve or reject each one by clicking the button below:
|
||||
</Text>
|
||||
|
||||
<Section style={buttonContainer}>
|
||||
|
||||
@@ -16,14 +16,22 @@ import { Button, Section, Text } from 'react-email';
|
||||
import * as React from 'react';
|
||||
import EmailLayout, { bodyText, button, buttonContainer, footerText } from './components/EmailLayout';
|
||||
|
||||
const documentList = {
|
||||
...bodyText,
|
||||
paddingLeft: '20px',
|
||||
};
|
||||
|
||||
export const DocumentSigning = () => {
|
||||
return (
|
||||
<EmailLayout subject={'Action Required – Please review and sign {{.OrganizationName}} compliance documents'}>
|
||||
<Text style={bodyText}>
|
||||
You're receiving this message because your company, <strong>{'{{.OrganizationName}}'}</strong>, has shared a new compliance document that requires your review and signature.
|
||||
You're receiving this message because your company, <strong>{'{{.OrganizationName}}'}</strong>, has shared compliance documents that require your review and signature:
|
||||
</Text>
|
||||
|
||||
<ul style={documentList} dangerouslySetInnerHTML={{ __html: '{{range .Documents}}<li><a href="{{.URL}}">{{.Title}}</a> ({{.Type}})</li>{{end}}' }} />
|
||||
|
||||
<Text style={bodyText}>
|
||||
To stay compliant with company policies, please take a moment to review and sign the document by clicking the button below:
|
||||
To stay compliant with company policies, please take a moment to review and sign them by clicking the button below:
|
||||
</Text>
|
||||
|
||||
<Section style={buttonContainer}>
|
||||
|
||||
@@ -2,9 +2,11 @@ Probo
|
||||
|
||||
Hi {{.RecipientFullName}},
|
||||
|
||||
You're receiving this message because {{.OrganizationName}} has requested your approval on the document {{.DocumentName}}.
|
||||
You're receiving this message because {{.OrganizationName}} has requested your approval on the following documents:
|
||||
|
||||
Please take a moment to review the document and approve or reject it by clicking the link below:
|
||||
{{range .Documents}}- {{.Title}} ({{.Type}}): {{.URL}}
|
||||
{{end}}
|
||||
Please take a moment to review them and approve or reject each one by clicking the link below:
|
||||
|
||||
{{.ApprovalUrl}}
|
||||
|
||||
|
||||
@@ -2,9 +2,11 @@ Probo
|
||||
|
||||
Hi {{.RecipientFullName}},
|
||||
|
||||
You're receiving this message because your company, {{.OrganizationName}}, has shared a new compliance document that requires your review and signature.
|
||||
You're receiving this message because your company, {{.OrganizationName}}, has shared compliance documents that require your review and signature:
|
||||
|
||||
To stay compliant with company policies, please take a moment to review and sign the document by clicking the link below:
|
||||
{{range .Documents}}- {{.Title}} ({{.Type}}): {{.URL}}
|
||||
{{end}}
|
||||
To stay compliant with company policies, please take a moment to review and sign them by clicking the link below:
|
||||
|
||||
{{.SigningUrl}}
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@ import * as getSignatureOp from './getSignature.operation';
|
||||
import * as getAllSignaturesOp from './getAllSignatures.operation';
|
||||
import * as requestSignatureOp from './requestSignature.operation';
|
||||
import * as cancelSignatureOp from './cancelSignature.operation';
|
||||
import * as sendSigningNotificationsOp from './sendSigningNotifications.operation';
|
||||
import * as getApprovalQuorumOp from './getApprovalQuorum.operation';
|
||||
import * as getAllApprovalQuorumsOp from './getAllApprovalQuorums.operation';
|
||||
import * as getApprovalDecisionOp from './getApprovalDecision.operation';
|
||||
@@ -157,12 +156,6 @@ export const description: INodeProperties[] = [
|
||||
description: 'Request a signature for a document version',
|
||||
action: 'Request a document version signature',
|
||||
},
|
||||
{
|
||||
name: 'Send Signing Notifications',
|
||||
value: 'sendSigningNotifications',
|
||||
description: 'Send signing notifications to all pending signatories',
|
||||
action: 'Send signing notifications',
|
||||
},
|
||||
{
|
||||
name: 'Unarchive',
|
||||
value: 'unarchive',
|
||||
@@ -208,7 +201,6 @@ export const description: INodeProperties[] = [
|
||||
...getAllSignaturesOp.description,
|
||||
...requestSignatureOp.description,
|
||||
...cancelSignatureOp.description,
|
||||
...sendSigningNotificationsOp.description,
|
||||
...getApprovalQuorumOp.description,
|
||||
...getAllApprovalQuorumsOp.description,
|
||||
...getApprovalDecisionOp.description,
|
||||
@@ -234,7 +226,6 @@ export {
|
||||
getAllSignaturesOp as getAllSignatures,
|
||||
requestSignatureOp as requestSignature,
|
||||
cancelSignatureOp as cancelSignature,
|
||||
sendSigningNotificationsOp as sendSigningNotifications,
|
||||
getApprovalQuorumOp as getApprovalQuorum,
|
||||
getAllApprovalQuorumsOp as getAllApprovalQuorums,
|
||||
getApprovalDecisionOp as getApprovalDecision,
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
// Copyright (c) 2025-2026 Probo Inc <hello@probo.com>.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import type { INodeProperties, IExecuteFunctions, INodeExecutionData } from 'n8n-workflow';
|
||||
import { proboApiRequest } from '../../GenericFunctions';
|
||||
|
||||
export const description: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Organization ID',
|
||||
name: 'organizationId',
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['document'],
|
||||
operation: ['sendSigningNotifications'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'The ID of the organization',
|
||||
required: true,
|
||||
},
|
||||
];
|
||||
|
||||
export async function execute(
|
||||
this: IExecuteFunctions,
|
||||
itemIndex: number,
|
||||
): Promise<INodeExecutionData> {
|
||||
const organizationId = this.getNodeParameter('organizationId', itemIndex) as string;
|
||||
|
||||
const query = `
|
||||
mutation SendSigningNotifications($input: SendSigningNotificationsInput!) {
|
||||
sendSigningNotifications(input: $input) {
|
||||
success
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const responseData = await proboApiRequest.call(this, query, { input: { organizationId } });
|
||||
|
||||
return {
|
||||
json: responseData,
|
||||
pairedItem: { item: itemIndex },
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user