ADD: new pushtype - arbitrary text message
This commit is contained in:
parent
242fa7f35a
commit
2a2de5423f
18
openapi.yaml
18
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
|
||||
|
||||
@ -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: {},
|
||||
|
||||
@ -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 };
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@ -113,6 +113,12 @@ dataSource
|
||||
await GroundControlToMajorTom.pushOnchainTxidGotConfirmed(connection, GroundControlToMajorTom.getGoogleServerKey(), GroundControlToMajorTom.getApnsJwtToken(), payload);
|
||||
await sendQueueRepository.remove(record);
|
||||
break;
|
||||
case 5:
|
||||
payload = <components["schemas"]["PushNotificationMessage"]>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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user