diff --git a/openapi.yaml b/openapi.yaml index 9f1c209..f17a8c0 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -2,7 +2,7 @@ openapi: 3.0.0 info: title: GroundControl push server API description: Push notifications server for BlueWallet - version: 0.0.12 + version: 0.0.13 servers: - url: http://localhost:3001 - url: https://groundcontrol-bluewallet-stg.herokuapp.com @@ -231,12 +231,14 @@ components: - 2 - 3 - 4 + - 5 description: > type: * `1` - Your lightning invoice was paid * `2` - New transaction to one of your addresses * `3` - New unconfirmed transaction to one of your addresses * `4` - Transaction confirmed + * `5` - Arbitrary text message "token": type: "string" "os": @@ -340,3 +342,17 @@ components: txid: type: "string" description: txid of the transaction that got confirmed + + PushNotificationMessage: + allOf: # Combines PushNotificationBase and the inline model + - $ref: "#/components/schemas/PushNotificationBase" + - type: object + required: + - text + properties: + type: + type: "integer" + enum: [5] + text: + type: "string" + description: custom text thats displayed on push notification buble diff --git a/src/class/GroundControlToMajorTom.ts b/src/class/GroundControlToMajorTom.ts index e55a556..117021a 100644 --- a/src/class/GroundControlToMajorTom.ts +++ b/src/class/GroundControlToMajorTom.ts @@ -119,6 +119,31 @@ export class GroundControlToMajorTom { if (pushNotification.os === "ios") return GroundControlToMajorTom._pushToApns(dataSource, apnsP8, pushNotification.token, apnsPayload, pushNotification, pushNotification.txid); } + static async pushMessage(dataSource: DataSource, serverKey: string, apnsP8: string, pushNotification: components["schemas"]["PushNotificationMessage"]): Promise<[object, object]> { + const fcmPayload = { + data: {}, + notification: { + title: "Message", + body: pushNotification.text, + }, + }; + + const apnsPayload = { + aps: { + badge: pushNotification.badge, + alert: { + title: "Message", + body: pushNotification.text, + }, + sound: "default", + }, + data: {}, + }; + + if (pushNotification.os === "android") return GroundControlToMajorTom._pushToFcm(dataSource, serverKey, pushNotification.token, fcmPayload, pushNotification); + if (pushNotification.os === "ios") return GroundControlToMajorTom._pushToApns(dataSource, apnsP8, pushNotification.token, apnsPayload, pushNotification, pushNotification.txid); + } + static async pushOnchainAddressWasPaid(dataSource: DataSource, serverKey: string, apnsP8: string, pushNotification: components["schemas"]["PushNotificationOnchainAddressGotPaid"]): Promise<[object, object]> { const fcmPayload = { data: {}, diff --git a/src/openapi/api.ts b/src/openapi/api.ts index f132704..9596e83 100644 --- a/src/openapi/api.ts +++ b/src/openapi/api.ts @@ -165,10 +165,11 @@ export type components = { * * `2` - New transaction to one of your addresses * * `3` - New unconfirmed transaction to one of your addresses * * `4` - Transaction confirmed + * * `5` - Arbitrary text message * * @enum {integer} */ - type: 1 | 2 | 3 | 4; + type: 1 | 2 | 3 | 4 | 5; token: string; /** @enum {string} */ os: "android" | "ios"; @@ -223,6 +224,13 @@ export type components = { /** @description txid of the transaction that got confirmed */ txid: string; } & { [key: string]: unknown }) & { [key: string]: unknown }; + PushNotificationMessage: components["schemas"]["PushNotificationBase"] & + ({ + /** @enum {integer} */ + type?: 5; + /** @description custom text thats displayed on push notification buble */ + text: string; + } & { [key: string]: unknown }) & { [key: string]: unknown }; }; }; diff --git a/src/worker-sender.ts b/src/worker-sender.ts index e8bb1f4..e1f9dcb 100644 --- a/src/worker-sender.ts +++ b/src/worker-sender.ts @@ -113,6 +113,12 @@ dataSource await GroundControlToMajorTom.pushOnchainTxidGotConfirmed(connection, GroundControlToMajorTom.getGoogleServerKey(), GroundControlToMajorTom.getApnsJwtToken(), payload); await sendQueueRepository.remove(record); break; + case 5: + payload = payload; + process.env.VERBOSE && console.warn("pushing to token", payload.token, payload.os); + await GroundControlToMajorTom.pushMessage(connection, GroundControlToMajorTom.getGoogleServerKey(), GroundControlToMajorTom.getApnsJwtToken(), payload); + await sendQueueRepository.remove(record); + break; default: process.env.VERBOSE && console.warn("malformed payload:", payload); await sendQueueRepository.remove(record);