Repository navigation
feat(transactional-email): add a command that sets up the first email send #1507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Silthus
wants to merge
18
commits into
main
Choose a base branch
from
feat/transactional-email-program
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+336
−7
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
6fca57b
feat(transactional-email): add a command that sets up the first email…
Silthus 8e6f184
fix(transactional-email): follow main's program contract and skill cl…
Silthus 6654b67
feat(analytics): say which provider a migrate-email run moves from
Silthus 1c077af
fix(transactional-email): link the transactional emails docs
Silthus a90f038
fix(analytics): drop migrated_from when a run moves on from an email …
Silthus 6da6fc9
fix(transactional-email): link the docs from both abort outros
Silthus df5cfbd
refactor(transactional-email): spell out the program's binding
Silthus 5ceda4a
fix(transactional-email): run the sending-transactional-emails skill
Silthus cc90dfc
feat(transactional-email): keep the email in code by default
Silthus f95c37b
refactor(transactional-email): leave the code-or-template choice to t…
Silthus 8cb8ad7
docs(transactional-email): name every backend's SDK in the README
Silthus 04b7915
Merge remote-tracking branch 'origin/main' into feat/transactional-em…
Silthus 287887f
fix(agent): end a linear Pi run on a program's [ABORT]
Silthus b09af2e
test(transactional-email): assert migrated_from on the delivered event
Silthus 226aad6
fix(pi): end a run only on a line that starts with [ABORT]
Silthus 904543a
fix(pi): read an [ABORT] reason from the line after a bare marker
Silthus 60445c7
fix(tui): show an agent's [ABORT] on its own outro, not the busy handoff
Silthus 7c9de7e
test(pi): assert the abort tests' outcomes, not their prompt counts
Silthus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { config as transactionalEmailConfig } from '@programs/transactional-email'; | ||
|
|
||
| import type { Command } from './command'; | ||
| import { nativeCommandFactory } from './factories/native-command-factory'; | ||
|
|
||
| export const transactionalEmailCommand: Command = nativeCommandFactory( | ||
| transactionalEmailConfig, | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import { GPT5_6_SOL_MODEL, Harness, Sequence } from '@shared/constants'; | ||
| import type { AbortCase } from '@agent/types'; | ||
| import { createSkillProgram } from '../shared/skill-program'; | ||
| import type { ProgramConfig } from '@programs/program-contract'; | ||
|
|
||
| const SKILL_ID = 'sending-transactional-emails'; | ||
| const REPORT_FILE = 'posthog-transactional-email-report.md'; | ||
| const DOCS_URL = 'https://posthog.com/docs/workflows/transactional-emails'; | ||
|
|
||
| const TRANSACTIONAL_EMAIL_ABORT_CASES: AbortCase[] = [ | ||
| { | ||
| match: /^transactional email api not enabled$/i, | ||
| message: "Transactional email isn't enabled for this project", | ||
| body: | ||
| 'The transactional email API is in beta, and PostHog turns it on per ' + | ||
| 'project. Ask PostHog in the app to enable it for your project, then ' + | ||
| 'run this command again.', | ||
| docsUrl: DOCS_URL, | ||
| }, | ||
| { | ||
| match: /^no server code found$/i, | ||
| message: 'No server code found', | ||
| body: | ||
| 'A transactional email is sent from server code, because the send needs ' + | ||
| "a secret key. The setup agent didn't find server code in this project. " + | ||
| 'Run this command again from the project that runs your server.', | ||
| docsUrl: DOCS_URL, | ||
| }, | ||
| ]; | ||
|
|
||
| export const config: ProgramConfig = { | ||
| ...createSkillProgram({ | ||
| skillId: SKILL_ID, | ||
| command: 'transactional-email', | ||
| id: 'transactional-email', | ||
| description: 'Send your first transactional email from code', | ||
| integrationLabel: 'transactional-email', | ||
| customPrompt: | ||
| `Set up transactional email in this project with the \`${SKILL_ID}\` ` + | ||
| 'skill: a verified sender, the email, the project secret API key, and ' + | ||
| 'the first send. Follow the skill\'s "Inside the PostHog ' + | ||
| `Wizard" section. Write the final report to ./${REPORT_FILE}: the email ` + | ||
| 'the app sends, where its content lives and its template key or ID, ' + | ||
| 'the files you changed, the ' + | ||
| 'environment variables every deployment needs, and what the person ' + | ||
| 'still has to do.', | ||
| successMessage: `Transactional email is set up. View the report at ./${REPORT_FILE}`, | ||
| reportFile: REPORT_FILE, | ||
| docsUrl: DOCS_URL, | ||
| spinnerMessage: 'Setting up transactional email...', | ||
| estimatedDurationMinutes: 5, | ||
| abortCases: TRANSACTIONAL_EMAIL_ABORT_CASES, | ||
| }), | ||
| binding: { | ||
| sequence: Sequence.linear, | ||
| harness: Harness.pi, | ||
|
Silthus marked this conversation as resolved.
Resolved
|
||
| model: GPT5_6_SOL_MODEL, | ||
| thinkingLevel: 'medium', | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "extends": "../../../tsconfig.no-tui.json", | ||
| "references": [{ "path": "../tsconfig.core.json" }] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| type SentEvent = { event: string; properties?: Record<string, unknown> }; | ||
|
|
||
| const sent = vi.hoisted(() => [] as SentEvent[]); | ||
|
|
||
| vi.mock('posthog-node', () => ({ | ||
| PostHog: class { | ||
| capture(event: SentEvent) { | ||
| sent.push(event); | ||
| } | ||
| shutdown() { | ||
| return Promise.resolve(); | ||
| } | ||
| }, | ||
| })); | ||
|
|
||
| async function finishedEventAfter(...skillIds: (string | null)[]) { | ||
| vi.resetModules(); | ||
| sent.length = 0; | ||
| const { analytics } = await import('@utils/analytics'); | ||
| const { SessionStore } = await import('../session-store'); | ||
| const { buildSession } = await import('../wizard-session'); | ||
| const store = new SessionStore(buildSession({})); | ||
| for (const skillId of skillIds) store.setSkillId(skillId); | ||
| await analytics.shutdown('success'); | ||
| return sent.find((e) => e.event === 'setup wizard finished')?.properties; | ||
| } | ||
|
|
||
| describe('migrated_from on setup wizard finished', () => { | ||
| it('names the provider an email migration skill moves from', async () => { | ||
| const finished = await finishedEventAfter('migrate-email-resend'); | ||
|
|
||
| expect(finished).toMatchObject({ migrated_from: 'resend' }); | ||
| }); | ||
|
|
||
| it('is absent from a run of any other skill', async () => { | ||
| const finished = await finishedEventAfter('migrate-statsig'); | ||
|
|
||
| expect(finished).toBeDefined(); | ||
| expect(finished?.migrated_from).toBeUndefined(); | ||
| }); | ||
|
|
||
| it.each([['migrate-statsig'], [null]])( | ||
| 'is absent when the run moves on from an email migration to %s', | ||
| async (nextSkillId) => { | ||
| const finished = await finishedEventAfter( | ||
| 'migrate-email-resend', | ||
| nextSkillId, | ||
| ); | ||
|
|
||
| expect(finished).toBeDefined(); | ||
| expect(finished?.migrated_from).toBeUndefined(); | ||
| }, | ||
| ); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.