Skip to content

Instantly share code, notes, and snippets.

@mattbajorek
Created April 20, 2022 01:05
Show Gist options
  • Save mattbajorek/377e30c724494ca33e5260bd4bca1613 to your computer and use it in GitHub Desktop.
Save mattbajorek/377e30c724494ca33e5260bd4bca1613 to your computer and use it in GitHub Desktop.
sendAll wrapper
import { Injectable } from '@nestjs/common';
import * as firebase from 'firebase-admin';
import { BatchResponse } from 'firebase-admin/lib/messaging/messaging-api';
import * as shell from 'shelljs';
@Injectable()
export class NotificationsService {
...
public async sendAll(messages: firebase.messaging.TokenMessage[], dryRun?: boolean): Promise<BatchResponse> {
if (process.env.NODE_ENV === 'local') {
for (const { notification, token } of messages) {
shell.exec(
`echo '{ "aps": { "alert": ${JSON.stringify(notification)}, "token": "${token}" } }' | xcrun simctl push booted com.company.appname -`,
);
}
}
return firebase.messaging().sendAll(messages, dryRun);
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment