From c8752d6153a0a3cd4351b7b94e09bc2e3f6126d1 Mon Sep 17 00:00:00 2001 From: Brian Evans Date: Sat, 6 May 2023 18:27:09 +0100 Subject: [PATCH] Added repl method for sending notifications Not tested yet Signed-off-by: Brian Evans --- repl/index.ts | 2 ++ repl/utils/sendNotification.ts | 8 ++++++++ 2 files changed, 10 insertions(+) create mode 100644 repl/utils/sendNotification.ts diff --git a/repl/index.ts b/repl/index.ts index 419eadc..9709cfe 100644 --- a/repl/index.ts +++ b/repl/index.ts @@ -18,6 +18,7 @@ import {getFeedback} from "./getFeedback.js"; import {getUser} from "./getUserAndOrg.js"; import {setOrgActiveMembers} from "./migrations/setOrgActiveMembers.js"; import {clearSessions} from "./utils/clearSessions.js"; +import {sendNotification} from "./utils/sendNotification.js"; if(process.argv.slice(1).includes('--help')) console.log("This is a custom repl for managing the database and queues. Try\n\n\t" + "docker compose exec repl node index.js") @@ -42,6 +43,7 @@ server.context.backupClientLists = ()=>backupClientLists(redis) server.context.getFeedback = ()=>getFeedback(redis) server.context.getUser = (userId: string)=>getUser(redis, userId).then(console.log) server.context.clearSessions = ()=>clearSessions(redis) +server.context.sendNotification = (userId: string, {title, message})=>sendNotification(redis,userId, {title, message}) server.context.exit = ()=>{shutdown('exit()');return 'exiting...'} // could be a Proxy to allow for simply "exit" rather than "exit()" diff --git a/repl/utils/sendNotification.ts b/repl/utils/sendNotification.ts new file mode 100644 index 0000000..bc4801b --- /dev/null +++ b/repl/utils/sendNotification.ts @@ -0,0 +1,8 @@ +import {RedisClient} from "bullmq"; +import {sendWebNotification, WebNotification} from "../../backend-shared/notifications/sendWebNotification.js"; + +export async function sendNotification(redis: RedisClient,userId: string, {title, message}){ + const notification: WebNotification = {title, options:{body: message,tag: 'custom-repl-notification', + icon: 'https://filingdeadlines.co.uk/icon/icon500.svg',}} + await sendWebNotification({userId: userId, notification}) +}