Repository navigation
Add campaign segment and drip sequence commands #81
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ae1c32e
Add campaign segments, drip settings, enrollment and step analytics
purpshell a8adf54
Merge frequency cap CLI into segments and drip stack
purpshell 1a7e86d
test: cover combined campaign caps and drip commands
purpshell 02b1f21
Merge branch 'feat/campaign-frequency-cap' into feat/campaign-segment…
purpshell ebb274c
Merge remote-tracking branch 'origin/main' into feat/campaign-segment…
purpshell 7d63b99
fix: reject drip removal when creating a campaign
purpshell 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import {Args, Flags} from '@oclif/core' | ||
| import {BaseCommand} from '../../base-command.js' | ||
| import {readJsonInput} from '../../api/request.js' | ||
| import { | ||
| campaignRequest, | ||
| objectInput, | ||
| type Enrollment, | ||
| } from '../../services/campaign-segments-drip.js' | ||
| export default class CampaignEnroll extends BaseCommand { | ||
| static override description = | ||
| 'Enroll one phone in a running or paused continuous drip (beta). Existing enrollments never restart.' | ||
| static override args = { | ||
| campaign: Args.string({required: true, description: 'Campaign ID.'}), | ||
| } | ||
| static override flags = { | ||
| phone: Flags.string({ | ||
| required: true, | ||
| description: 'International phone number.', | ||
| }), | ||
| variables: Flags.string({description: 'Variables JSON file or stdin (-).'}), | ||
| 'project-slug': Flags.string({ | ||
| required: true, | ||
| description: 'Owning project slug.', | ||
| }), | ||
| } | ||
| async run(): Promise<void> { | ||
| const {args, flags} = await this.parse(CampaignEnroll) | ||
| const variables = | ||
| flags.variables === undefined | ||
| ? undefined | ||
| : objectInput(await readJsonInput(flags.variables)) | ||
| const result = await campaignRequest<Enrollment>( | ||
| await this.messagingClient(flags, {serverApiKeyOnly: 'Campaign'}), | ||
| { | ||
| method: 'POST', | ||
| path: `/messaging/projects/${encodeURIComponent(flags['project-slug'])}/campaigns/${encodeURIComponent(args.campaign)}/enrollments`, | ||
| body: { | ||
| phone: flags.phone, | ||
| ...(variables === undefined ? {} : {variables}), | ||
| }, | ||
| }, | ||
| ) | ||
| this.writeValue( | ||
| result, | ||
| `${result.data.created ? 'Enrolled' : 'Already enrolled'}\t${result.data.recipientId}\nStatus\t${result.data.status}`, | ||
| flags, | ||
| ) | ||
| } | ||
| } |
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,46 @@ | ||
| import {campaignRequest} from '../../../services/campaign-segments-drip.js' | ||
| import {Flags} from '@oclif/core' | ||
| import {Args} from '@oclif/core' | ||
| import {readJsonInput} from '../../../api/request.js' | ||
| import { | ||
| objectInput, | ||
| segmentPath, | ||
| } from '../../../services/campaign-segments-drip.js' | ||
| import type {AudienceSegmentPreview} from '../../../services/campaign-segment-types.js' | ||
| import {BaseCommand} from '../../../base-command.js' | ||
| export default class SegmentCount extends BaseCommand { | ||
| static override description = | ||
| 'Count audience segments (team key; beta gates and observed revisions apply).' | ||
| static override args = { | ||
| segment: Args.string({required: false, description: 'Saved segment ID.'}), | ||
| } | ||
| static override flags = { | ||
| input: Flags.string({ | ||
| description: | ||
| 'Unsaved rules object from JSON file or stdin (-). Use instead of a segment ID.', | ||
| }), | ||
| } | ||
| async run(): Promise<void> { | ||
| const {args, flags} = await this.parse(SegmentCount) | ||
| const client = await this.platformClient(flags) | ||
| if ((args.segment === undefined) === (flags.input === undefined)) | ||
| this.error('Pass a segment ID or --input, exclusively.') | ||
| const result = await campaignRequest< | ||
| AudienceSegmentPreview & {revision?: number} | ||
| >( | ||
| client, | ||
| flags.input === undefined | ||
| ? {method: 'GET', path: segmentPath(args.segment) + '/preview'} | ||
| : { | ||
| method: 'POST', | ||
| path: segmentPath() + '/preview', | ||
| body: {rules: objectInput(await readJsonInput(flags.input))}, | ||
| }, | ||
| ) | ||
| this.writeValue( | ||
| result, | ||
| `Matched\t${result.data.matchedCount}\nEligible\t${result.data.eligibleCount}\nOpted out\t${result.data.optedOutCount}\nConsent withheld\t${result.data.consentWithheldCount}\nRevision\t${result.data.revision ?? 'unsaved'}`, | ||
| flags, | ||
| ) | ||
| } | ||
| } |
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,32 @@ | ||
| import {campaignRequest} from '../../../services/campaign-segments-drip.js' | ||
| import {Flags} from '@oclif/core' | ||
| import {readJsonInput} from '../../../api/request.js' | ||
| import { | ||
| objectInput, | ||
| segmentPath, | ||
| } from '../../../services/campaign-segments-drip.js' | ||
| import type {AudienceSegment} from '../../../services/campaign-segment-types.js' | ||
| import {BaseCommand} from '../../../base-command.js' | ||
| export default class SegmentCreate extends BaseCommand { | ||
| static override description = | ||
| 'Create audience segments (team key; beta gates and observed revisions apply).' | ||
| static override args = {} | ||
| static override flags = { | ||
| input: Flags.string({ | ||
| required: true, | ||
| description: | ||
| 'JSON object from file or stdin (-). Update includes expectedRevision.', | ||
| }), | ||
| } | ||
| async run(): Promise<void> { | ||
| const {flags} = await this.parse(SegmentCreate) | ||
| const client = await this.platformClient(flags) | ||
| const body = objectInput(await readJsonInput(flags.input)) | ||
| const result = await campaignRequest<AudienceSegment>(client, { | ||
| method: 'POST', | ||
| path: segmentPath(), | ||
| body, | ||
| }) | ||
| this.writeValue(result, JSON.stringify(result.data, null, 2), flags) | ||
| } | ||
| } |
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,36 @@ | ||
| import {campaignRequest} from '../../../services/campaign-segments-drip.js' | ||
| import {Flags} from '@oclif/core' | ||
| import {Args} from '@oclif/core' | ||
| import { | ||
| revision, | ||
| segmentPath, | ||
| } from '../../../services/campaign-segments-drip.js' | ||
| import {terminalText} from '../../../developer/render.js' | ||
| import {BaseCommand} from '../../../base-command.js' | ||
| export default class SegmentDelete extends BaseCommand { | ||
| static override description = | ||
| 'Delete audience segments (team key; beta gates and observed revisions apply).' | ||
| static override args = { | ||
| segment: Args.string({required: true, description: 'Saved segment ID.'}), | ||
| } | ||
| static override flags = { | ||
| revision: Flags.integer({ | ||
| required: true, | ||
| description: 'Observed segment revision.', | ||
| }), | ||
| } | ||
| async run(): Promise<void> { | ||
| const {args, flags} = await this.parse(SegmentDelete) | ||
| const client = await this.platformClient(flags) | ||
| const result = await campaignRequest<{deleted: true; id: string}>(client, { | ||
| method: 'DELETE', | ||
| path: segmentPath(args.segment), | ||
| query: {expectedRevision: revision(flags.revision)}, | ||
| }) | ||
| this.writeValue( | ||
| result, | ||
| `Deleted segment ${terminalText(result.data.id)}`, | ||
| flags, | ||
| ) | ||
| } | ||
| } |
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,22 @@ | ||
| import {campaignRequest} from '../../../services/campaign-segments-drip.js' | ||
| import {Args} from '@oclif/core' | ||
| import {segmentPath} from '../../../services/campaign-segments-drip.js' | ||
| import type {AudienceSegment} from '../../../services/campaign-segment-types.js' | ||
| import {BaseCommand} from '../../../base-command.js' | ||
| export default class SegmentGet extends BaseCommand { | ||
| static override description = | ||
| 'Get audience segments (team key; beta gates and observed revisions apply).' | ||
| static override args = { | ||
| segment: Args.string({required: true, description: 'Saved segment ID.'}), | ||
| } | ||
| static override flags = {} | ||
| async run(): Promise<void> { | ||
| const {args, flags} = await this.parse(SegmentGet) | ||
| const client = await this.platformClient(flags) | ||
| const result = await campaignRequest<AudienceSegment>(client, { | ||
| method: 'GET', | ||
| path: segmentPath(args.segment), | ||
| }) | ||
| this.writeValue(result, JSON.stringify(result.data, null, 2), flags) | ||
| } | ||
| } |
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,40 @@ | ||
| import {Flags} from '@oclif/core' | ||
| import {segmentPath} from '../../../services/campaign-segments-drip.js' | ||
| import {terminalText} from '../../../developer/render.js' | ||
| import type {AudienceSegmentsEnvelope} from '../../../services/campaign-segment-types.js' | ||
| import {BaseCommand} from '../../../base-command.js' | ||
| export default class SegmentList extends BaseCommand { | ||
| static override description = | ||
| 'List audience segments (team key; beta gates and observed revisions apply).' | ||
| static override args = {} | ||
| static override flags = { | ||
| cursor: Flags.string({description: 'Next page cursor.'}), | ||
| limit: Flags.integer({min: 1, max: 100, description: 'Page size (1-100).'}), | ||
| } | ||
| async run(): Promise<void> { | ||
| const {flags} = await this.parse(SegmentList) | ||
| const client = await this.platformClient(flags) | ||
| const response = await client.raw.request<AudienceSegmentsEnvelope>({ | ||
| method: 'GET', | ||
| path: segmentPath(), | ||
| query: { | ||
| ...(flags.cursor === undefined ? {} : {cursor: flags.cursor}), | ||
| ...(flags.limit === undefined ? {} : {limit: flags.limit}), | ||
| }, | ||
| }) | ||
| const result = {data: response.data, metadata: response.metadata} | ||
| this.writeValue( | ||
| result, | ||
| result.data.data | ||
| .map( | ||
| (s) => | ||
| `${terminalText(s.id)}\t${s.revision}\t${terminalText(s.name)}`, | ||
| ) | ||
| .join('\n') + | ||
| (result.data.page.hasMore | ||
| ? `\nNext cursor\t${terminalText(result.data.page.nextCursor ?? '')}` | ||
| : ''), | ||
| flags, | ||
| ) | ||
| } | ||
| } |
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.