Skip to content

Commit

Permalink
Switches to latest FCM APIs (#473)
Browse files Browse the repository at this point in the history
  • Loading branch information
pushchris authored Jun 28, 2024
1 parent bf268e4 commit 4361767
Show file tree
Hide file tree
Showing 9 changed files with 1,145 additions and 42 deletions.
1,131 changes: 1,100 additions & 31 deletions apps/platform/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/platform/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"koa-static": "^5.0.0",
"libphonenumber-js": "^1.10.24",
"mysql2": "^3.9.4",
"node-pushnotifications": "^2.1.0",
"node-pushnotifications": "^3.0.0",
"node-schedule": "^2.1.0",
"nodemailer": "^6.9.5",
"nodemailer-mailgun-transport": "^2.1.5",
Expand Down
6 changes: 4 additions & 2 deletions apps/platform/src/campaigns/CampaignService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,10 @@ export const updateCampaign = async (id: number, projectId: number, { tags, ...p
await abortCampaign(campaign)
}

// If we are rescheduling, abort sends to they are reset
if (data.send_at && data.send_at !== campaign.send_at) {
// If we are rescheduling, abort sends so they are reset
if (data.send_at
&& campaign.send_at
&& data.send_at !== campaign.send_at) {
data.state = 'pending'
await abortCampaign(campaign)
}
Expand Down
36 changes: 29 additions & 7 deletions apps/platform/src/providers/push/LocalPushProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ interface APNParams {
}

interface FCMParams {
id: string
appName: string
serviceAccountKey: {
projectId: string
privateKey: string
clientEmail: string
}
}

interface PushDataParams {
Expand Down Expand Up @@ -81,14 +86,31 @@ export default class LocalPushProvider extends PushProvider {
fcm: {
type: 'object',
nullable: true,
required: ['id'],
required: ['appName', 'serviceAccountKey'],
title: 'FCM',
description: 'Settings for Firebase Cloud Messaging to send messages to Android devices.',
properties: {
id: {
appName: {
type: 'string',
title: 'Server Key',
minLength: 80,
title: 'App Name',
},
serviceAccountKey: {
type: 'object',
required: ['projectId', 'privateKey', 'clientEmail'],
properties: {
projectId: {
type: 'string',
title: 'Project ID',
},
privateKey: {
type: 'string',
title: 'Private Key',
},
clientEmail: {
type: 'string',
title: 'Client Email',
},
},
},
},
},
Expand All @@ -99,8 +121,8 @@ export default class LocalPushProvider extends PushProvider {
boot() {
this.transport = new PushNotifications({
apn: this.apn,
gcm: this.fcm, // Uses historical name GCM, we'll use modern name
})
fcm: this.fcm,
} as unknown as PushNotifications.Settings) // Types are not up to date
}

async send(push: Push): Promise<PushResponse> {
Expand Down
1 change: 1 addition & 0 deletions apps/ui/public/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@
"time": "Time",
"timezone": "Timezone",
"title": "Title",
"topic": "Topic",
"translations": "Translations",
"translations_description": "Manage the translations your campaign supports and will send to.",
"trigger": "Trigger",
Expand Down
1 change: 1 addition & 0 deletions apps/ui/public/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@
"time": "Tiempo",
"timezone": "Zona Horaria",
"title": "Título",
"topic": "Tema",
"translations": "Traducciones",
"translations_description": "Administre las traducciones que su campaña admite y a las que enviará.",
"trigger": "Individual (API)",
Expand Down
2 changes: 1 addition & 1 deletion apps/ui/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ export type CampaignSendState = 'pending' | 'throttled' | 'bounced' | 'sent' | '

export type CampaignUpdateParams = Partial<Pick<Campaign, 'name' | 'state' | 'list_ids' | 'exclusion_list_ids' | 'subscription_id' | 'tags'>>
export type CampaignCreateParams = Pick<Campaign, 'name' | 'type' | 'list_ids' | 'exclusion_list_ids' | 'channel' | 'subscription_id' | 'provider_id' | 'tags'>
export type CampaignLaunchParams = Pick<Campaign, 'send_at' | 'send_in_user_timezone'>
export type CampaignLaunchParams = Pick<Campaign, 'send_at' | 'send_in_user_timezone' | 'state'>
// export type ListUpdateParams = Pick<List, 'name' | 'rule'>
export type CampaignUser = User & { state: CampaignSendState, send_at: string }

Expand Down
1 change: 1 addition & 0 deletions apps/ui/src/views/campaign/LaunchCampaign.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export default function LaunchCampaign({ open, onClose }: LaunchCampaignParams)
return
}
params.send_at = formatISO(sendAt)
params.state = 'scheduled'

try {
const value = await api.campaigns.update(project.id, campaign.id, params)
Expand Down
7 changes: 7 additions & 0 deletions apps/ui/src/views/campaign/TemplateDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ const PushTable = ({ data }: { data: PushTemplateData }) => {
return <InfoTable rows={{
[t('title')]: data.title ?? <Tag variant="warn">{t('missing')}</Tag>,
[t('body')]: data.body ?? <Tag variant="warn">{t('missing')}</Tag>,
[t('topic')]: data.topic ?? <Tag variant="warn">{t('missing')}</Tag>,
[t('deeplink')]: data.url,
[t('raw_json')]: JSON.stringify(data.custom),
}} />
Expand All @@ -114,6 +115,12 @@ const PushForm = ({ form }: { form: UseFormReturn<TemplateUpdateParams, any> })
label={t('body')}
textarea
required />
<TextInput.Field
form={form}
name="data.topic"
label={t('topic')}
textarea
required />
<TextInput.Field
form={form}
name="data.url"
Expand Down

0 comments on commit 4361767

Please sign in to comment.