<aside> 💡 fcm 과 sns 연동하여 iOS, AOS 모두 전송 푸시 알림은 SNS로 위임하여 전송되도록 하기 위해 분리 iOS APN을 firebase에 등록하여 GCM 포맷으로 전송해도 전송된다.
</aside>
import { INestApplication } from '@nestjs/common';
import { initTestingApp } from 'test-e2e/common/InitTestingApp';
import AWS from 'aws-sdk';
describe('푸쉬 알림 서버 구축', () => {
let app: INestApplication;
const SNS_ACESS_KEY = 'SNS_ACESS_KEY';
const SNS_SECRET_KEY = 'SNS_SECRET_KEY';
//AOS FCM 토큰
const AOS_TOKEN = 'AOS_TOKEN';
//IOS FCM 토큰
const iOS_TOKEN = 'iOS_TOKEN';
const REGION = 'ap-northeast-2';
const PlatformApplicationArn = 'arn';
AWS.config.update({
accessKeyId: SNS_ACESS_KEY,
secretAccessKey: SNS_SECRET_KEY,
region: REGION,
});
const awsSNS = new AWS.SNS();
beforeAll(async () => {
app = await initTestingApp();
});
it('sns push 서비스', async () => {
const params = {
PlatformApplicationArn,
Token: AOS_TOKEN,
};
const payload2 = { GCM: {} };
payload2.GCM = {
notification: {
body: '메시지',
title: '타이틀',
},
};
payload2.GCM = JSON.stringify(payload2.GCM);
const createdEndPoint = await awsSNS.createPlatformEndpoint(params).promise();
await awsSNS
.publish({
Message: JSON.stringify(payload2),
MessageStructure: 'json',
TargetArn: createdEndPoint.EndpointArn,
})
.promise();
});
it('iOS FCM 테스트', async () => {
const params = {
PlatformApplicationArn,
Token: iOS_TOKEN,
};
const payload2 = { GCM: {} };
payload2.GCM = {
notification: {
body: 'i바디',
title: '타이틀',
},
};
payload2.GCM = JSON.stringify(payload2.GCM);
const createdEndPoint = await awsSNS.createPlatformEndpoint(params).promise();
await awsSNS
.publish({
Message: JSON.stringify(payload2),
MessageStructure: 'json',
TargetArn: createdEndPoint.EndpointArn,
})
.promise();
});
});