Skip to content

Commit

Permalink
Merge pull request #22 from ethereum-push-notification-service/add-su…
Browse files Browse the repository at this point in the history
…bset-notif

feat: caip conversion for subset recipients
  • Loading branch information
Xand6r authored Apr 20, 2023
2 parents e86a22d + 25ba4dd commit 2fce11d
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/helpers/epnschannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { AccountId } from 'caip';
import { IAnalyticsLog } from '../models/analytics';
import mongoose from 'mongoose';
import { ENV } from '@pushprotocol/restapi/src/lib/constants';
import { forEach } from 'lodash';

export interface ChannelSettings {
networkToMonitor: string;
Expand All @@ -23,7 +24,7 @@ export interface ChannelSettings {
}

export interface ISendNotificationParams {
recipient: string;
recipient: string | Array<string>;
title: string;
message: string;
payloadTitle: string;
Expand Down Expand Up @@ -204,10 +205,19 @@ export class EPNSChannel {
env: config.showrunnersEnv,
};

if (params.notificationType != 1) {
if (params.notificationType == 3) {
const caipRecipients = this.convertToCAIP(params.recipient);
apiResponsePayload['recipients'] = caipRecipients;
}

if (params.notificationType === 4 && Array.isArray(params.recipient)) {
const caipRecipients = [];
params.recipient.forEach((recipient) => {
if(recipient) caipRecipients.push(this.getCAIPAddress(recipient));
});
apiResponsePayload['recipients'] = caipRecipients;
}

const payloadAPI: any = PushAPI.payloads;
const apiResponse = await payloadAPI.sendNotification(apiResponsePayload);
if (apiResponse?.status === 204) {
Expand Down

0 comments on commit 2fce11d

Please sign in to comment.