mirror of
https://github.com/warmbly/warmbly.git
synced 2026-11-25 00:07:07 +00:00
Merge pull request #1225 from warmbly/feat/positive-reply-notifications
feat: notify about positive replies by default
This commit is contained in:
@@ -372,6 +372,15 @@ jobs:
|
||||
WARMBLY_TEST_DB: postgres://warmbly:warmbly@127.0.0.1:5432/warmbly_test?sslmode=disable
|
||||
run: go test -race ./internal/repository -run '^TestLiveInvitedSignup$' -count=1
|
||||
|
||||
- name: Notification preference save regressions (PostgreSQL)
|
||||
if: matrix.suite == 'live-1'
|
||||
env:
|
||||
WARMBLY_TEST_DB: postgres://warmbly:warmbly@127.0.0.1:5432/warmbly_test?sslmode=disable
|
||||
run: |
|
||||
set -o pipefail
|
||||
go test -race -v ./internal/repository -run '^TestLiveNotificationPreferencesKeepKeysASaveOmits$' -count=1 | tee notification-preferences.log
|
||||
grep -q '^--- PASS: TestLiveNotificationPreferencesKeepKeysASaveOmits ' notification-preferences.log
|
||||
|
||||
- name: Tester initial password and sample data regressions (PostgreSQL)
|
||||
if: matrix.suite == 'live-1'
|
||||
env:
|
||||
|
||||
@@ -691,6 +691,7 @@ Auth: Session only (not available to API keys).
|
||||
{
|
||||
"preferences": {
|
||||
"inbound_reply": { "enabled": false, "channels": { "in_app": true, "email": false, "slack": false, "push": true } },
|
||||
"inbound_positive_reply": { "enabled": true, "channels": { "in_app": true, "email": false, "slack": false, "push": true } },
|
||||
"inbound_out_of_office": { "enabled": false, "channels": { "in_app": true, "email": false, "slack": false, "push": true } },
|
||||
"health_bounce": { "enabled": true, "channels": { "in_app": true, "email": false, "slack": false, "push": true } },
|
||||
"health_complaint": { "enabled": true, "channels": { "in_app": true, "email": false, "slack": false, "push": true } },
|
||||
@@ -712,7 +713,7 @@ Auth: Session only (not available to API keys).
|
||||
|
||||
`PUT /auth/me/notification-preferences`
|
||||
|
||||
Replaces the caller's preferences. The full preferences object is sent under a `preferences` key and echoed back.
|
||||
Saves the caller's preferences. The preferences object is sent under a `preferences` key and the saved result is returned.
|
||||
|
||||
Auth: Session only (not available to API keys).
|
||||
|
||||
@@ -720,12 +721,13 @@ Auth: Session only (not available to API keys).
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
|-------|------|----------|-------------|
|
||||
| `preferences` | object | yes | The complete preferences object. Each category has `enabled` plus a `channels` object (`in_app`, `email`, `slack`, `push`), alongside `email_digest_minutes` (the email bundling window, `30` to `1440`). Categories absent from the request fall back to their defaults. |
|
||||
| `preferences` | object | yes | The preferences object. Each category has `enabled` plus a `channels` object (`in_app`, `email`, `slack`, `push`), alongside `email_digest_minutes` (the email bundling window, `30` to `1440`). A category or field absent from the request keeps its saved value, so a client that does not know a newer category never changes it. While `inbound_reply.enabled` is true, a positive reply is delivered under `inbound_reply` with its channels, whatever `inbound_positive_reply` is set to; `inbound_positive_reply` applies only while `inbound_reply` is off. |
|
||||
|
||||
```json
|
||||
{
|
||||
"preferences": {
|
||||
"inbound_reply": { "enabled": true, "channels": { "in_app": true, "email": false, "slack": false, "push": true } },
|
||||
"inbound_positive_reply": { "enabled": true, "channels": { "in_app": true, "email": false, "slack": false, "push": true } },
|
||||
"inbound_out_of_office": { "enabled": false, "channels": { "in_app": true, "email": false, "slack": false, "push": true } },
|
||||
"health_bounce": { "enabled": true, "channels": { "in_app": true, "email": false, "slack": false, "push": true } },
|
||||
"health_complaint": { "enabled": true, "channels": { "in_app": true, "email": false, "slack": false, "push": true } },
|
||||
@@ -745,7 +747,7 @@ Auth: Session only (not available to API keys).
|
||||
|
||||
#### Response
|
||||
|
||||
The same `{ "preferences": { ... } }` object that was sent.
|
||||
The saved `{ "preferences": { ... } }` object: what was sent, merged over the values already saved for anything the request left out.
|
||||
|
||||
### List notifications
|
||||
|
||||
|
||||
@@ -381,7 +381,7 @@ Before this rule, older mail could open tasks and record reply intents when its
|
||||
|
||||
Automated replies are off deliberately. A vacation notice is not follow-up work, and a week of sending makes enough of them to bury the real replies. Tick **Automated** if you do want one per machine reply, or untick the human ones you do not need. Unticking everything is the same as turning the switch off.
|
||||
|
||||
The classification does more than decide the task: an automated reply never counts as a reply for **stop on reply** or for a **replied** branch in a sequence, and its notification goes to the **Out-of-office detected** preference rather than **New reply**, so muting one does not mute the other.
|
||||
The classification does more than decide the task: an automated reply never counts as a reply for **stop on reply** or for a **replied** branch in a sequence, and its notification goes to the **Out-of-office detected** preference rather than **Positive reply** or **Reply received**, so muting one does not mute the other.
|
||||
|
||||
</Fold>
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ Under Email delivery, pick how often unread notifications are emailed to you.
|
||||
## Good to know
|
||||
|
||||
- Feeds are per user, not shared across the workspace.
|
||||
- Health alerts are on by default. **Reply received** is off by default, so a large campaign does not flood the feed.
|
||||
- Health alerts and **Positive reply** are on by default. **Reply received**, which covers every reply a person writes, is off by default, so a large campaign does not flood the feed.
|
||||
- Nothing is emailed the moment it happens: unread notifications go out as one bundled email, every 30 minutes by default.
|
||||
- Anything you read in the dashboard before the email goes out is never emailed.
|
||||
- Every reply still lands in the [Unibox](/guides/unibox/), even with reply notifications off.
|
||||
@@ -71,10 +71,13 @@ The feed and the bell count update live, without refreshing.
|
||||
| New sign-in | Security | On | Your account is accessed from a new device, with browser, OS, and rough location |
|
||||
| Billing alerts | Billing | On, including email | A trial expired or sending was paused for billing |
|
||||
| Teammate joined | Team | On | Someone accepted an invitation |
|
||||
| Reply received | Inbound | Off | A recipient replied to a cold email |
|
||||
| Positive reply | Inbound | On | A recipient answered a cold email and the reply was classified as positive |
|
||||
| Reply received | Inbound | Off | A person replied to a cold email, whatever they said. Automatic replies are not included |
|
||||
| Out-of-office detected | Inbound | Off | An auto-responder hit one of your sends |
|
||||
|
||||
Health defaults **on** because those alerts are operationally important and low volume. Inbound defaults **off** because a large campaign would generate one notification per recipient and flood the feed. Turn **Reply received** on only for smaller, higher-touch campaigns.
|
||||
Health defaults **on** because those alerts are operationally important and low volume. **Positive reply** defaults **on** for the same reason: interested replies are few, and they are what a campaign is for. The other inbound categories default **off** because a large campaign would generate one notification per recipient and flood the feed. Turn **Reply received** on only for smaller, higher-touch campaigns.
|
||||
|
||||
**Positive reply** and **Reply received** never announce the same message twice. With **Reply received** on, a positive reply is delivered as a **Reply received** notification, on that category's channels. With it off, positive replies use the **Positive reply** channels and every other reply from a person stays quiet. Automatic replies follow their own **Out-of-office detected** preference either way. All three need reply intent on in the workspace's outreach settings, which is the default. A positive reply is one the [reply classification](/guides/contacts-crm/) read as interested. A reply it read as neutral, a question or negative raises only **Reply received**, and classification can be wrong, so the [Unibox](/guides/unibox/) remains the full record.
|
||||
|
||||
<Callout type="info" title="Who gets notified">
|
||||
Workspace events never fan out to everyone. Reply and bounce alerts go to the owner of the mailbox or campaign, worker downtime to members who can manage mailboxes, mailbox mail that needs action to members who can both manage mailboxes and use the inbox, a finished placement test to whoever started it, a placement monitor alert to members who can view campaigns, billing to those who can manage billing, and team changes to those who can manage the team. The person who joined is not notified about themselves.
|
||||
@@ -86,12 +89,12 @@ Workspace events never fan out to everyone. Reply and bounce alerts go to the ow
|
||||
|
||||
## Notifications about a message follow it
|
||||
|
||||
A **Reply received**, **Out-of-office detected** or **Mail that needs action** notification is about one message in the [Unibox](/guides/unibox/), and it stays in step with it:
|
||||
A **Positive reply**, **Reply received**, **Out-of-office detected** or **Mail that needs action** notification is about one message in the [Unibox](/guides/unibox/), and it stays in step with it:
|
||||
|
||||
- **Clicking it opens that conversation**, not the inbox in general.
|
||||
- **Reading the message reads the notification**, wherever you read it: in the Unibox, through the API, or in Gmail or Outlook, which Warmbly picks up on the next sync. A notification read this way is not emailed later either.
|
||||
- **Removing the message removes the notification.** Deleted mail, and mail later confirmed to be [warmup](/guides/warmup/), takes its notification out of the feed and the bell count. Warmup never raises one in the first place; this covers anything identified after it arrived. A push or Slack message already delivered cannot be recalled.
|
||||
- **Routine automated mail is not a reply.** DMARC aggregate reports, delivery failures and other system notices do not raise **Reply received** or **Out-of-office detected** alerts. If a message is identified as routine automated mail later, its false reply alert disappears from the feed and bell count, and its pending email is cancelled. Genuine out-of-office and automatic replies still use **Out-of-office detected** when enabled. Automated mail that needs your action keeps its separate **Mail that needs action** alert, and bounce and domain-authentication health alerts are unchanged.
|
||||
- **Routine automated mail is not a reply.** DMARC aggregate reports, delivery failures and other system notices do not raise **Positive reply**, **Reply received** or **Out-of-office detected** alerts. If a message is identified as routine automated mail later, its false reply alert disappears from the feed and bell count, and its pending email is cancelled. Genuine out-of-office and automatic replies still use **Out-of-office detected** when enabled. Automated mail that needs your action keeps its separate **Mail that needs action** alert, and bounce and domain-authentication health alerts are unchanged.
|
||||
|
||||
<Callout type="info" title="Where to read replies">
|
||||
Even with reply notifications off you never miss anything: every reply still lands in the [Unibox](/guides/unibox/). The notification is only an optional ping.
|
||||
|
||||
@@ -217,7 +217,7 @@ Warmbly posts a notification to Slack when the category is enabled for Slack in
|
||||
|
||||
The channel picker lists public channels and the private channels the bot has been invited to. To post to a private channel, invite the bot there first.
|
||||
|
||||
Each post carries an **Open in Warmbly** button. A **Reply received** notification also has **Draft a reply**, which starts the assistant in a thread on that post, for whoever pressed it, with the reply already in front of it. The draft is never sent without your approval. Pressing it needs a linked account.
|
||||
Each post carries an **Open in Warmbly** button. A **Positive reply** or **Reply received** notification also has **Draft a reply**, which starts the assistant in a thread on that post, for whoever pressed it, with the reply already in front of it. The draft is never sent without your approval. Pressing it needs a linked account.
|
||||
|
||||
**Personal DMs** are off until you turn them on, from **Integrations > Slack** in Warmbly (they need a linked account). You then get a DM for every category you have enabled for Slack in **Settings > Notifications**.
|
||||
|
||||
|
||||
@@ -49,13 +49,19 @@ func (h *Handler) GetNotificationPreferences(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{"preferences": prefs, "email_delivery": emailDeliveryInfo()})
|
||||
}
|
||||
|
||||
// UpdateNotificationPreferences replaces the caller's notification preferences.
|
||||
// UpdateNotificationPreferences saves the caller's notification preferences.
|
||||
func (h *Handler) UpdateNotificationPreferences(c *gin.Context) {
|
||||
uid, ok := notifActor(c)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
var req models.UpdateNotificationPreferencesRequest
|
||||
current, xerr := h.NotificationService.GetPreferences(c.Request.Context(), uid)
|
||||
if xerr != nil {
|
||||
errx.JSON(c, xerr)
|
||||
return
|
||||
}
|
||||
// Decoded over the stored value, so a client that predates a category leaves it alone.
|
||||
req := models.UpdateNotificationPreferencesRequest{Preferences: *current}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
errx.JSON(c, errx.InvalidBody(err))
|
||||
return
|
||||
|
||||
@@ -41,6 +41,7 @@ func TestProcessIncomingReplyHonorsMachineVerdicts(t *testing.T) {
|
||||
review string
|
||||
subject string
|
||||
sender string
|
||||
snippet string
|
||||
flags []string
|
||||
want models.NotificationCategory
|
||||
}{
|
||||
@@ -54,6 +55,7 @@ func TestProcessIncomingReplyHonorsMachineVerdicts(t *testing.T) {
|
||||
{name: "out of office without recognizable subject", kind: inboxtag.KindAutoReplyOOO, confidence: 0.95, want: models.NotifInboundOOO},
|
||||
{name: "ticket acknowledgement without recognizable subject", kind: inboxtag.KindAutoReplyTicket, confidence: 0.95, want: models.NotifInboundOOO},
|
||||
{name: "human reply", kind: inboxtag.KindHumanReply, confidence: 0.95, want: models.NotifInboundReply},
|
||||
{name: "interested human reply", kind: inboxtag.KindHumanReply, confidence: 0.95, snippet: "Yes, I am interested. Can we book a call next week?", want: models.NotifInboundPositiveReply},
|
||||
{name: "uncertain kind", kind: inboxtag.KindNotification, confidence: 0.3, review: "kind", want: models.NotifInboundReply},
|
||||
{name: "kind awaiting review", kind: inboxtag.KindNotification, confidence: 0.95, review: "kind", want: models.NotifInboundReply},
|
||||
} {
|
||||
@@ -78,6 +80,9 @@ func TestProcessIncomingReplyHonorsMachineVerdicts(t *testing.T) {
|
||||
if tc.sender != "" {
|
||||
msg.FromAddr = []string{tc.sender}
|
||||
}
|
||||
if tc.snippet != "" {
|
||||
msg.Snippet = tc.snippet
|
||||
}
|
||||
if err := s.ProcessIncomingReply(context.Background(), accountID, msg); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -1880,6 +1880,10 @@ func (s *service) ProcessIncomingReply(ctx context.Context, emailAccountID uuid.
|
||||
cat := models.NotifInboundReply
|
||||
title := "New reply from " + sender
|
||||
body := msg.Subject
|
||||
if intent == models.ReplyIntentPositive {
|
||||
cat = models.NotifInboundPositiveReply
|
||||
title = "Positive reply from " + sender
|
||||
}
|
||||
if models.IsAutomatedIntent(intent) {
|
||||
// The "out-of-office detected" preference is what someone mutes to
|
||||
// stop hearing about auto-responders, so every machine reply goes
|
||||
|
||||
@@ -62,7 +62,7 @@ func RegisterSlackTools(r *Registry, slack SlackControl, audit audit.AuditServic
|
||||
|
||||
func slackCategoryNames() []string {
|
||||
return []string{
|
||||
string(models.NotifInboundReply), string(models.NotifInboundOOO), string(models.NotifInboxActionRequired),
|
||||
string(models.NotifInboundReply), string(models.NotifInboundPositiveReply), string(models.NotifInboundOOO), string(models.NotifInboxActionRequired),
|
||||
string(models.NotifCampaignPaused), string(models.NotifHealthBounce), string(models.NotifHealthComplaint),
|
||||
string(models.NotifDomainAuth), string(models.NotifPlacementFinished), string(models.NotifPlacementAlert),
|
||||
string(models.NotifWorkerDowntime), string(models.NotifSecuritySignIn), string(models.NotifBillingAlert), string(models.NotifTeamActivity),
|
||||
|
||||
@@ -291,7 +291,7 @@ func (s *service) keepEligibleEmailMessages(ctx context.Context, rows []models.N
|
||||
// of mail Warmbly sends; the in-app feed still shows it.
|
||||
func emailBody(n models.Notification) string {
|
||||
switch n.Category {
|
||||
case models.NotifInboundReply, models.NotifInboundOOO:
|
||||
case models.NotifInboundReply, models.NotifInboundPositiveReply, models.NotifInboundOOO:
|
||||
return "Open the conversation in your inbox to read it."
|
||||
}
|
||||
return n.Body
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
|
||||
func TestEmailBodyLeavesAnInboundSubjectOut(t *testing.T) {
|
||||
subject := "Claim your prize at evil.example"
|
||||
for _, cat := range []models.NotificationCategory{models.NotifInboundReply, models.NotifInboundOOO} {
|
||||
for _, cat := range []models.NotificationCategory{models.NotifInboundReply, models.NotifInboundPositiveReply, models.NotifInboundOOO} {
|
||||
if got := emailBody(models.Notification{Category: cat, Body: subject}); strings.Contains(got, subject) {
|
||||
t.Errorf("%s: email body carries the sender's subject", cat)
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ func TestPendingPushRechecksTheMessageButKeepsActionAlerts(t *testing.T) {
|
||||
id := uuid.New()
|
||||
r := &messageNotificationRepo{}
|
||||
s := &service{repo: r}
|
||||
for _, category := range []models.NotificationCategory{models.NotifInboundReply, models.NotifInboundOOO} {
|
||||
for _, category := range []models.NotificationCategory{models.NotifInboundReply, models.NotifInboundPositiveReply, models.NotifInboundOOO} {
|
||||
if s.canPushMessage(context.Background(), category, pendingPush{MessageID: &id}) {
|
||||
t.Errorf("%s accepted an automated message", category)
|
||||
}
|
||||
|
||||
@@ -253,7 +253,7 @@ func (s *service) canPushMessage(ctx context.Context, category models.Notificati
|
||||
}
|
||||
|
||||
func (s *service) pushMessageEligibility(ctx context.Context, category models.NotificationCategory, p pendingPush) (bool, error) {
|
||||
if (category == models.NotifInboundReply || category == models.NotifInboundOOO) &&
|
||||
if category.IsInboundReply() &&
|
||||
replyclassify.IsSystemReport(replyclassify.Input{Subject: p.Body}) {
|
||||
return false, nil
|
||||
}
|
||||
@@ -277,6 +277,8 @@ func digestTitle(category models.NotificationCategory, n int) string {
|
||||
switch category {
|
||||
case models.NotifInboundReply:
|
||||
return fmt.Sprintf("%d new replies", n)
|
||||
case models.NotifInboundPositiveReply:
|
||||
return fmt.Sprintf("%d positive replies", n)
|
||||
case models.NotifInboundOOO:
|
||||
return fmt.Sprintf("%d out-of-office replies", n)
|
||||
case models.NotifHealthBounce:
|
||||
|
||||
@@ -259,6 +259,7 @@ func (s *service) notifyOneWithError(ctx context.Context, userID uuid.UUID, orgI
|
||||
if err != nil || prefs == nil {
|
||||
return false, err
|
||||
}
|
||||
category = prefs.DeliveryCategory(category)
|
||||
cat := prefs.CategoryPref(category)
|
||||
if !cat.Enabled {
|
||||
return false, nil
|
||||
@@ -363,7 +364,7 @@ func (s *service) canNotifyMessage(ctx context.Context, category models.Notifica
|
||||
}
|
||||
|
||||
func (s *service) messageEligibility(ctx context.Context, category models.NotificationCategory, messageID *uuid.UUID) (bool, error) {
|
||||
if messageID == nil || (category != models.NotifInboundReply && category != models.NotifInboundOOO) {
|
||||
if messageID == nil || !category.IsInboundReply() {
|
||||
return true, nil
|
||||
}
|
||||
return s.repo.CanNotifyAboutMessage(ctx, *messageID, category)
|
||||
|
||||
@@ -97,7 +97,7 @@ func noticeMessage(n notification.SlackNotice) Message {
|
||||
text += "\n" + escapeMrkdwn(body)
|
||||
}
|
||||
var draft Block
|
||||
if n.Category == models.NotifInboundReply {
|
||||
if n.Category.IsHumanReply() {
|
||||
v := draftReplyValue{EmailID: metaString(n.Meta, "unibox_email_id"), ThreadID: metaString(n.Meta, "thread_id")}
|
||||
if v.EmailID != "" || v.ThreadID != "" {
|
||||
raw, _ := json.Marshal(v)
|
||||
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
DROP TRIGGER IF EXISTS users_keep_notification_preferences ON users;
|
||||
DROP FUNCTION IF EXISTS users_keep_notification_preferences();
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
-- A save from a release that does not know a category keeps that category's saved value.
|
||||
CREATE OR REPLACE FUNCTION users_keep_notification_preferences() RETURNS trigger AS $$
|
||||
BEGIN
|
||||
NEW.notification_preferences := OLD.notification_preferences || NEW.notification_preferences;
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
DROP TRIGGER IF EXISTS users_keep_notification_preferences ON users;
|
||||
CREATE TRIGGER users_keep_notification_preferences
|
||||
BEFORE UPDATE OF notification_preferences ON users
|
||||
FOR EACH ROW
|
||||
WHEN (jsonb_typeof(OLD.notification_preferences) = 'object' AND jsonb_typeof(NEW.notification_preferences) = 'object')
|
||||
EXECUTE FUNCTION users_keep_notification_preferences();
|
||||
@@ -12,14 +12,17 @@ import (
|
||||
type NotificationCategory string
|
||||
|
||||
const (
|
||||
NotifInboundReply NotificationCategory = "inbound_reply"
|
||||
NotifInboundOOO NotificationCategory = "inbound_out_of_office"
|
||||
NotifHealthBounce NotificationCategory = "health_bounce"
|
||||
NotifHealthComplaint NotificationCategory = "health_complaint"
|
||||
NotifWorkerDowntime NotificationCategory = "health_worker_downtime"
|
||||
NotifSecuritySignIn NotificationCategory = "security_new_signin"
|
||||
NotifBillingAlert NotificationCategory = "billing_alert"
|
||||
NotifTeamActivity NotificationCategory = "team_activity"
|
||||
NotifInboundReply NotificationCategory = "inbound_reply"
|
||||
// NotifInboundPositiveReply is a human reply classified as positive. It is
|
||||
// the one inbound category on by default.
|
||||
NotifInboundPositiveReply NotificationCategory = "inbound_positive_reply"
|
||||
NotifInboundOOO NotificationCategory = "inbound_out_of_office"
|
||||
NotifHealthBounce NotificationCategory = "health_bounce"
|
||||
NotifHealthComplaint NotificationCategory = "health_complaint"
|
||||
NotifWorkerDowntime NotificationCategory = "health_worker_downtime"
|
||||
NotifSecuritySignIn NotificationCategory = "security_new_signin"
|
||||
NotifBillingAlert NotificationCategory = "billing_alert"
|
||||
NotifTeamActivity NotificationCategory = "team_activity"
|
||||
// NotifCampaignPaused fires when the platform pauses a campaign on its
|
||||
// own — today, when an auto-pause guardrail band is breached. Rare and
|
||||
// always actionable, so it defaults on with email.
|
||||
@@ -58,16 +61,18 @@ type CategoryPref struct {
|
||||
// NotificationPreferences is the per-user singleton (jsonb on users). Always
|
||||
// returned fully populated via DefaultNotificationPreferences merge.
|
||||
type NotificationPreferences struct {
|
||||
InboundReply CategoryPref `json:"inbound_reply"`
|
||||
InboundOOO CategoryPref `json:"inbound_out_of_office"`
|
||||
HealthBounce CategoryPref `json:"health_bounce"`
|
||||
HealthComplaint CategoryPref `json:"health_complaint"`
|
||||
WorkerDowntime CategoryPref `json:"health_worker_downtime"`
|
||||
SecuritySignIn CategoryPref `json:"security_new_signin"`
|
||||
BillingAlert CategoryPref `json:"billing_alert"`
|
||||
TeamActivity CategoryPref `json:"team_activity"`
|
||||
CampaignPaused CategoryPref `json:"campaign_paused"`
|
||||
DomainAuth CategoryPref `json:"health_domain_auth"`
|
||||
InboundReply CategoryPref `json:"inbound_reply"`
|
||||
// InboundPositiveReply covers positive replies while InboundReply is off.
|
||||
InboundPositiveReply CategoryPref `json:"inbound_positive_reply"`
|
||||
InboundOOO CategoryPref `json:"inbound_out_of_office"`
|
||||
HealthBounce CategoryPref `json:"health_bounce"`
|
||||
HealthComplaint CategoryPref `json:"health_complaint"`
|
||||
WorkerDowntime CategoryPref `json:"health_worker_downtime"`
|
||||
SecuritySignIn CategoryPref `json:"security_new_signin"`
|
||||
BillingAlert CategoryPref `json:"billing_alert"`
|
||||
TeamActivity CategoryPref `json:"team_activity"`
|
||||
CampaignPaused CategoryPref `json:"campaign_paused"`
|
||||
DomainAuth CategoryPref `json:"health_domain_auth"`
|
||||
// PlacementFinished and PlacementAlert are the inbox placement test pair.
|
||||
PlacementFinished CategoryPref `json:"placement_finished"`
|
||||
PlacementAlert CategoryPref `json:"placement_alert"`
|
||||
@@ -83,7 +88,8 @@ type NotificationPreferences struct {
|
||||
|
||||
// DefaultNotificationPreferences is the merge base. Health categories default ON
|
||||
// (operationally important + low volume); inbound categories default OFF (a big
|
||||
// campaign would otherwise flood the feed with a notification per recipient).
|
||||
// campaign would otherwise flood the feed with a notification per recipient),
|
||||
// except positive replies, which are few and are what the campaign is for.
|
||||
// Push defaults on: it only fires for devices the user explicitly registered by
|
||||
// granting the OS notification permission, and enabled categories should reach
|
||||
// those devices without a second opt-in.
|
||||
@@ -100,18 +106,19 @@ func DefaultNotificationPreferences() NotificationPreferences {
|
||||
// whoever can edit the DNS, so this one emails by default too.
|
||||
domainAuth := CategoryPref{Enabled: true, Channels: ChannelPrefs{InApp: true, Push: true, Email: true}}
|
||||
return NotificationPreferences{
|
||||
InboundReply: off,
|
||||
InboundOOO: off,
|
||||
HealthBounce: on,
|
||||
HealthComplaint: on,
|
||||
WorkerDowntime: on,
|
||||
SecuritySignIn: on,
|
||||
BillingAlert: billing,
|
||||
TeamActivity: on,
|
||||
CampaignPaused: campaignPaused,
|
||||
DomainAuth: domainAuth,
|
||||
PlacementFinished: on,
|
||||
PlacementAlert: domainAuth,
|
||||
InboundReply: off,
|
||||
InboundPositiveReply: on,
|
||||
InboundOOO: off,
|
||||
HealthBounce: on,
|
||||
HealthComplaint: on,
|
||||
WorkerDowntime: on,
|
||||
SecuritySignIn: on,
|
||||
BillingAlert: billing,
|
||||
TeamActivity: on,
|
||||
CampaignPaused: campaignPaused,
|
||||
DomainAuth: domainAuth,
|
||||
PlacementFinished: on,
|
||||
PlacementAlert: domainAuth,
|
||||
// A mailbox about to lose its subscription has to reach whoever can
|
||||
// fix it even when nobody reads the inbox, so this emails too.
|
||||
InboxActionRequired: domainAuth,
|
||||
@@ -124,6 +131,8 @@ func (p NotificationPreferences) CategoryPref(c NotificationCategory) CategoryPr
|
||||
switch c {
|
||||
case NotifInboundReply:
|
||||
return p.InboundReply
|
||||
case NotifInboundPositiveReply:
|
||||
return p.InboundPositiveReply
|
||||
case NotifInboundOOO:
|
||||
return p.InboundOOO
|
||||
case NotifHealthBounce:
|
||||
@@ -153,6 +162,26 @@ func (p NotificationPreferences) CategoryPref(c NotificationCategory) CategoryPr
|
||||
}
|
||||
}
|
||||
|
||||
// DeliveryCategory is the category a notification is raised under for this
|
||||
// user: with every reply on, a positive one is delivered as a plain reply, so
|
||||
// it keeps that category's channels and is never announced twice.
|
||||
func (p NotificationPreferences) DeliveryCategory(c NotificationCategory) NotificationCategory {
|
||||
if c == NotifInboundPositiveReply && p.InboundReply.Enabled {
|
||||
return NotifInboundReply
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
// IsHumanReply reports a category raised by a person answering a send.
|
||||
func (c NotificationCategory) IsHumanReply() bool {
|
||||
return c == NotifInboundReply || c == NotifInboundPositiveReply
|
||||
}
|
||||
|
||||
// IsInboundReply reports a category raised by a reply, automatic ones included.
|
||||
func (c NotificationCategory) IsInboundReply() bool {
|
||||
return c.IsHumanReply() || c == NotifInboundOOO
|
||||
}
|
||||
|
||||
// Notification is one row in the in-app feed.
|
||||
type Notification struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPositiveRepliesNotifyByDefault(t *testing.T) {
|
||||
p := DefaultNotificationPreferences()
|
||||
if !p.CategoryPref(NotifInboundPositiveReply).Enabled {
|
||||
t.Fatal("positive replies must notify by default")
|
||||
}
|
||||
if p.CategoryPref(NotifInboundReply).Enabled || p.CategoryPref(NotifInboundOOO).Enabled {
|
||||
t.Fatal("other inbound categories must stay off by default")
|
||||
}
|
||||
}
|
||||
|
||||
// Preferences saved before the category existed carry no key for it.
|
||||
func TestStoredPreferencesWithoutPositiveReplyKeepTheDefault(t *testing.T) {
|
||||
p := DefaultNotificationPreferences()
|
||||
stored := `{"inbound_reply":{"enabled":false,"channels":{"in_app":true}},"email_digest_minutes":60}`
|
||||
if err := json.Unmarshal([]byte(stored), &p); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !p.InboundPositiveReply.Enabled || !p.InboundPositiveReply.Channels.InApp {
|
||||
t.Fatalf("got %+v", p.InboundPositiveReply)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeliveryCategory(t *testing.T) {
|
||||
p := DefaultNotificationPreferences()
|
||||
if got := p.DeliveryCategory(NotifInboundPositiveReply); got != NotifInboundPositiveReply {
|
||||
t.Fatalf("every reply off: got %s", got)
|
||||
}
|
||||
p.InboundReply.Enabled = true
|
||||
if got := p.DeliveryCategory(NotifInboundPositiveReply); got != NotifInboundReply {
|
||||
t.Fatalf("every reply on: got %s", got)
|
||||
}
|
||||
if got := p.DeliveryCategory(NotifInboundOOO); got != NotifInboundOOO {
|
||||
t.Fatalf("other categories are untouched: got %s", got)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/warmbly/warmbly/internal/models"
|
||||
)
|
||||
|
||||
// A save from a release that predates a category arrives without its key.
|
||||
func TestLiveNotificationPreferencesKeepKeysASaveOmits(t *testing.T) {
|
||||
handle := liveUniboxFolderDB(t)
|
||||
f := newUniboxFolderFixture(t, handle.Pool)
|
||||
ctx := context.Background()
|
||||
notifs := NewNotificationRepository(handle.Pool)
|
||||
|
||||
prefs := models.DefaultNotificationPreferences()
|
||||
prefs.InboundPositiveReply.Enabled = false
|
||||
if err := notifs.UpdatePreferences(ctx, f.user, &prefs); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
older := `{"inbound_reply":{"enabled":true,"channels":{"in_app":true}},"email_digest_minutes":60}`
|
||||
if _, err := handle.Pool.Exec(ctx, `UPDATE users SET notification_preferences = $2::jsonb WHERE id = $1`, f.user, older); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got, err := notifs.GetPreferences(ctx, f.user)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got.InboundPositiveReply.Enabled {
|
||||
t.Fatal("an omitted category lost its saved value")
|
||||
}
|
||||
if !got.InboundReply.Enabled || got.EmailDigestMinutes != 60 {
|
||||
t.Fatalf("the keys the save carried were not applied: %+v", got)
|
||||
}
|
||||
if !got.HealthBounce.Enabled {
|
||||
t.Fatal("an omitted category lost its saved value")
|
||||
}
|
||||
}
|
||||
@@ -85,6 +85,7 @@ func (r *notificationRepository) GetPreferences(ctx context.Context, userID uuid
|
||||
return &prefs, nil
|
||||
}
|
||||
|
||||
// UpdatePreferences saves the blob; a trigger (000387) keeps saved keys it omits.
|
||||
func (r *notificationRepository) UpdatePreferences(ctx context.Context, userID uuid.UUID, prefs *models.NotificationPreferences) error {
|
||||
raw, err := json.Marshal(prefs)
|
||||
if err != nil {
|
||||
@@ -152,13 +153,13 @@ var ErrNotificationMessageAutomated = errors.New("notification: message is not a
|
||||
|
||||
// Legacy thread alerts are hidden only when every verdict in that mailbox's thread is automated.
|
||||
const notificationReplyVisibleSQL = `(
|
||||
n.category NOT IN ('inbound_reply', 'inbound_out_of_office') OR (
|
||||
n.category NOT IN ('inbound_reply', 'inbound_positive_reply', 'inbound_out_of_office') OR (
|
||||
NOT EXISTS (
|
||||
SELECT 1 FROM unibox_emails ue
|
||||
LEFT JOIN inbox_tag_results r ON r.email_account_id = ue.email_id
|
||||
AND r.message_id = ue.message_id AND r.status = 'complete'
|
||||
WHERE ue.id = n.unibox_email_id AND (
|
||||
(n.category = 'inbound_reply' AND ue.automated)
|
||||
(n.category IN ('inbound_reply', 'inbound_positive_reply') AND ue.automated)
|
||||
OR (r.kind IN ('notification', 'bounce_hard', 'bounce_soft')
|
||||
AND r.kind_confidence >= 0.70 AND r.review_reason <> 'kind')
|
||||
)
|
||||
@@ -170,14 +171,14 @@ const notificationReplyVisibleSQL = `(
|
||||
AND r.thread_id <> '' AND r.thread_id = n.metadata->>'thread_id'
|
||||
AND r.status = 'complete' AND r.kind_confidence >= 0.70 AND r.review_reason <> 'kind'
|
||||
AND (r.kind IN ('notification', 'bounce_hard', 'bounce_soft')
|
||||
OR (n.category = 'inbound_reply' AND r.automated))
|
||||
OR (n.category IN ('inbound_reply', 'inbound_positive_reply') AND r.automated))
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM inbox_tag_results other
|
||||
WHERE other.organization_id = r.organization_id AND other.email_account_id = r.email_account_id
|
||||
AND other.thread_id = r.thread_id AND NOT (
|
||||
other.status = 'complete' AND other.kind_confidence >= 0.70 AND other.review_reason <> 'kind'
|
||||
AND (other.kind IN ('notification', 'bounce_hard', 'bounce_soft')
|
||||
OR (n.category = 'inbound_reply' AND other.automated))
|
||||
OR (n.category IN ('inbound_reply', 'inbound_positive_reply') AND other.automated))
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
@@ -119,7 +119,7 @@ final class MoreNotificationsStore {
|
||||
private enum MoreNotificationMeta {
|
||||
static func icon(_ category: String?) -> String {
|
||||
switch category {
|
||||
case "inbound_reply": return "arrowshape.turn.up.left.fill"
|
||||
case "inbound_reply", "inbound_positive_reply": return "arrowshape.turn.up.left.fill"
|
||||
case "inbound_out_of_office": return "moon.zzz.fill"
|
||||
case "health_bounce": return "arrow.uturn.left.circle.fill"
|
||||
case "health_complaint": return "flag.fill"
|
||||
@@ -133,7 +133,7 @@ private enum MoreNotificationMeta {
|
||||
|
||||
static func tone(_ category: String?) -> Tone {
|
||||
switch category {
|
||||
case "inbound_reply": return .emerald
|
||||
case "inbound_reply", "inbound_positive_reply": return .emerald
|
||||
case "inbound_out_of_office": return .slate
|
||||
case "health_bounce": return .rose
|
||||
case "health_complaint": return .rose
|
||||
@@ -147,7 +147,8 @@ private enum MoreNotificationMeta {
|
||||
|
||||
static func label(_ key: String) -> String {
|
||||
switch key {
|
||||
case "inbound_reply": return "Replies"
|
||||
case "inbound_positive_reply": return "Positive replies"
|
||||
case "inbound_reply": return "All replies"
|
||||
case "inbound_out_of_office": return "Out of office"
|
||||
case "health_bounce": return "Bounces"
|
||||
case "health_complaint": return "Spam complaints"
|
||||
@@ -163,7 +164,8 @@ private enum MoreNotificationMeta {
|
||||
|
||||
static func caption(_ key: String) -> String? {
|
||||
switch key {
|
||||
case "inbound_reply": return "A contact replies to your outreach"
|
||||
case "inbound_positive_reply": return "A contact answers your outreach with interest"
|
||||
case "inbound_reply": return "Every reply a person writes to your outreach, positive ones included. Auto-replies have their own setting"
|
||||
case "inbound_out_of_office": return "Auto-replies detected on your sends"
|
||||
case "health_bounce": return "A campaign email hard bounces"
|
||||
case "health_complaint": return "A recipient marks your mail as spam"
|
||||
@@ -176,7 +178,7 @@ private enum MoreNotificationMeta {
|
||||
}
|
||||
|
||||
static let knownGroups: [(title: String, keys: [String])] = [
|
||||
("Inbound", ["inbound_reply", "inbound_out_of_office"]),
|
||||
("Inbound", ["inbound_positive_reply", "inbound_reply", "inbound_out_of_office"]),
|
||||
("Mailbox health", ["health_bounce", "health_complaint", "health_worker_downtime"]),
|
||||
("Security", ["security_new_signin"]),
|
||||
("Account", ["billing_alert", "team_activity"]),
|
||||
|
||||
@@ -34,6 +34,7 @@ import type { AppNotification } from "@/lib/api/models/app/notifications/Notific
|
||||
// Per-category icon + tone so the list scans by kind before reading titles.
|
||||
const CATEGORY_META: Record<string, { icon: LucideIcon; tone: string }> = {
|
||||
inbound_reply: { icon: ReplyIcon, tone: "bg-sky-50 text-sky-600" },
|
||||
inbound_positive_reply: { icon: ReplyIcon, tone: "bg-emerald-50 text-emerald-600" },
|
||||
inbound_out_of_office: { icon: ClockIcon, tone: "bg-slate-100 text-slate-500" },
|
||||
health_bounce: { icon: TriangleAlertIcon, tone: "bg-amber-50 text-amber-600" },
|
||||
health_complaint: { icon: ShieldAlertIcon, tone: "bg-rose-50 text-rose-600" },
|
||||
|
||||
@@ -22,6 +22,7 @@ export const EMAIL_WINDOW_MAX_MINUTES = 1440;
|
||||
|
||||
export interface NotificationPreferences {
|
||||
inbound_reply: CategoryPref;
|
||||
inbound_positive_reply: CategoryPref;
|
||||
inbound_out_of_office: CategoryPref;
|
||||
health_bounce: CategoryPref;
|
||||
health_complaint: CategoryPref;
|
||||
@@ -52,7 +53,8 @@ export const NOTIFICATION_CATEGORY_GROUPS: { id: string; label: string; categori
|
||||
id: "inbound",
|
||||
label: "Inbound activity",
|
||||
categories: [
|
||||
{ key: "inbound_reply", label: "Reply received", hint: "A recipient replied to a cold email." },
|
||||
{ key: "inbound_positive_reply", label: "Positive reply", hint: "A recipient answered a cold email with interest. On by default." },
|
||||
{ key: "inbound_reply", label: "Reply received", hint: "A person replied to a cold email, whatever they said. When on, it covers positive replies too. Automatic replies have their own setting below." },
|
||||
{ key: "inbound_out_of_office", label: "Out-of-office detected", hint: "An auto-responder hit one of your sends." },
|
||||
],
|
||||
},
|
||||
@@ -122,6 +124,7 @@ export function normalizeNotificationPreferences(
|
||||
const minutes = p?.email_digest_minutes ?? EMAIL_WINDOW_MIN_MINUTES;
|
||||
return {
|
||||
inbound_reply: p?.inbound_reply ?? off,
|
||||
inbound_positive_reply: p?.inbound_positive_reply ?? on,
|
||||
inbound_out_of_office: p?.inbound_out_of_office ?? off,
|
||||
health_bounce: p?.health_bounce ?? on,
|
||||
health_complaint: p?.health_complaint ?? on,
|
||||
|
||||
Reference in New Issue
Block a user