From f29e2b58f38d762a4ab34773ff73e9000c09cf39 Mon Sep 17 00:00:00 2001 From: eldpswp99 Date: Tue, 28 Dec 2021 20:12:18 +0900 Subject: [PATCH 1/2] fcm android & iOS separate notification --- src/firebase.ts | 48 +++++++++++++++++++++++++---------------- src/routes/routeList.ts | 2 +- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/firebase.ts b/src/firebase.ts index b671021..dbf4a29 100644 --- a/src/firebase.ts +++ b/src/firebase.ts @@ -4,33 +4,45 @@ import { fbConfig } from './fbconfig'; import { Department } from '../server/src/department/department.entity'; import { Notice } from '../server/src/notice/notice.entity'; import { parseTagsToStringWithSeparator } from './utils'; -import { messaging } from 'firebase-admin'; -import MessagingOptions = messaging.MessagingOptions; +// import MessagingOptions = messaging.MessagingOptions; +// import TokenMessage = messaging.TokenMessage; admin.initializeApp({ credential: admin.credential.cert(fbConfig) }); +const getPayload = (notice: Notice, department: Department, tags: string[]) => { + const previewLength = 250; + + return { + title: `${department.name} 신규 공지사항입니다`, + body: notice.title, + noticeId: `${notice.id}`, + departmentName: department.name, + departmentId: `${department.id}`, + preview: notice.contentText.slice(0, previewLength), + tags: parseTagsToStringWithSeparator(tags, ';'), + }; +}; + export async function sendNoticeCreationMessage( condition: string, notice: Notice, department: Department, tags: string[], ) { - const previewLength = 250; - - const payload = { - data: { - title: `${department.name} 신규 공지사항입니다`, - body: notice.title, - noticeId: `${notice.id}`, - departmentName: department.name, - departmentId: `${department.id}`, - preview: notice.contentText.slice(0, previewLength), - tags: parseTagsToStringWithSeparator(tags, ';'), + const testMessage = { + android: { + data: getPayload(notice, department, tags), }, + apns: { + payload: { + aps: { + alert: getPayload(notice, department, tags), + contentAvailable: true, + }, + customKey: 'customValue', + }, + }, + condition, }; - const options: MessagingOptions = { - contentAvailable: true, - }; - - await admin.messaging().sendToCondition(condition, payload, options); + await admin.messaging().send(testMessage); } diff --git a/src/routes/routeList.ts b/src/routes/routeList.ts index c012845..f187e8d 100644 --- a/src/routes/routeList.ts +++ b/src/routes/routeList.ts @@ -163,7 +163,7 @@ export const earlyStopList: Crawler[] = [ design, ]; -const populationList = [orientalpainting, painting, sculpture, craft, design, sociology]; +const populationList = [oia]; const POPULATION = TRUE_STRING.includes(process.env.POPULATION ?? ''); const crawlerList = POPULATION ? populationList : earlyStopList; From 87e5ed94bdba5f4acf0647c453ac3b3a2cb8d7d8 Mon Sep 17 00:00:00 2001 From: eldpswp99 Date: Tue, 28 Dec 2021 20:16:55 +0900 Subject: [PATCH 2/2] remove populationList --- src/firebase.ts | 2 -- src/routes/routeList.ts | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/firebase.ts b/src/firebase.ts index dbf4a29..2667c4b 100644 --- a/src/firebase.ts +++ b/src/firebase.ts @@ -4,8 +4,6 @@ import { fbConfig } from './fbconfig'; import { Department } from '../server/src/department/department.entity'; import { Notice } from '../server/src/notice/notice.entity'; import { parseTagsToStringWithSeparator } from './utils'; -// import MessagingOptions = messaging.MessagingOptions; -// import TokenMessage = messaging.TokenMessage; admin.initializeApp({ credential: admin.credential.cert(fbConfig) }); diff --git a/src/routes/routeList.ts b/src/routes/routeList.ts index f187e8d..765c946 100644 --- a/src/routes/routeList.ts +++ b/src/routes/routeList.ts @@ -163,7 +163,7 @@ export const earlyStopList: Crawler[] = [ design, ]; -const populationList = [oia]; +const populationList: Crawler[] = []; const POPULATION = TRUE_STRING.includes(process.env.POPULATION ?? ''); const crawlerList = POPULATION ? populationList : earlyStopList;