An open-source, faster Devin alternative
TypeScript
api-edge: alert #signups for free-email trial starts too (#988)
opencomputer-app[bot]ed001f79d2bc
diff --git a/cloudflare-workers/api-edge/src/slack_alerts.test.ts b/cloudflare-workers/api-edge/src/slack_alerts.test.tsindex 59d5bbb4..d035b772 100644--- a/cloudflare-workers/api-edge/src/slack_alerts.test.ts+++ b/cloudflare-workers/api-edge/src/slack_alerts.test.ts@@ -144,7 +144,7 @@ describe("billing-event alerts", () => {]);});- it("skips free-email trial starts and every internal account", async () => {+ it("alerts free-email trial starts and skips every internal account", async () => {const db = schemaDB();const { posts, fetchImpl } = slack();const free = addOrg(db, "[email protected]");@@ -154,10 +154,8 @@ describe("billing-event alerts", () => {await sendSlackAlert(env(db), alertForBillingEvent({}, "billing.trial_started", org, {}, NOW)!, fetchImpl, NOW);}await sendSlackAlert(env(db), trialEndedAlert(staff, "days"), fetchImpl, NOW);- expect(posts).toEqual([]);- // A free-email account still alerts on everything after the trial start.- await sendSlackAlert(env(db), trialEndedAlert(free, "minutes"), fetchImpl, NOW);- expect(posts.map((p) => p.text)).toEqual(["⏹️ [email protected] ended their trial unpaid · trial · out of work minutes"]);+ expect(posts).toHaveLength(1);+ expect(posts[0].text).toMatch(/^🟢 joe@gmail\.com started a trial/);});it("renders each revenue event", async () => {diff --git a/cloudflare-workers/api-edge/src/slack_alerts.ts b/cloudflare-workers/api-edge/src/slack_alerts.tsindex 903005ce..7482166a 100644--- a/cloudflare-workers/api-edge/src/slack_alerts.ts+++ b/cloudflare-workers/api-edge/src/slack_alerts.ts@@ -9,14 +9,13 @@// own channel without a deploy. Dormant unless the token and a channel are set.//// Unlike the billing events (work 054) the message carries the owner's email:-// it is looked up here, for Slack only. Internal accounts never alert;-// free-email accounts skip trial_started and first show up when they activate.-// Both lists are slack_connect.ts's, shared with 089.+// it is looked up here, for Slack only. Internal accounts never alert; the+// list is slack_connect.ts's, shared with 089.//// Each alert is claimed once in slack_alerts before it is posted. One bounded// attempt; never throws, so a billing or login path can await it.-import { isFreeEmail, isInternalEmail } from "./slack_connect";+import { isInternalEmail } from "./slack_connect";// The settings; OPENCOMPUTER_DB comes from the caller's env (AlertsDBEnv), kept// out of here so env interfaces that require it can still extend this one.@@ -258,7 +257,6 @@ export async function sendSlackAlert(try {const c = await orgContext(db, alert.orgId);if (!c?.email || isInternalEmail(c.email)) return false;- if (alert.kind === "trial_started" && isFreeEmail(c.email)) return false;const claimed = await db.prepare(`INSERT OR IGNORE INTO slack_alerts (org_id, event, key, sent_at) VALUES (?1, ?2, ?3, ?4)`)