From bd634f97421ce851781a13f42cd84400a2036e91 Mon Sep 17 00:00:00 2001 From: Collin Duncan <3679940+cgduncan7@users.noreply.github.com> Date: Wed, 13 Sep 2023 20:52:25 +0200 Subject: [PATCH] Adding auth and bootstrap message --- src/ntfy/client.ts | 2 ++ src/ntfy/provider.ts | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/ntfy/client.ts b/src/ntfy/client.ts index d90dc42..14e87b2 100644 --- a/src/ntfy/client.ts +++ b/src/ntfy/client.ts @@ -14,10 +14,12 @@ export class NtfyClient { ) { const host = this.configService.getOrThrow('NTFY_HOST') this.topic = this.configService.getOrThrow('NTFY_TOPIC') + const token = this.configService.getOrThrow('NTFY_TOKEN') this.httpClient = new Axios({ baseURL: `https://${host}`, headers: { 'Content-Type': 'application/json', + Authorization: `Bearer ${token}`, }, }) } diff --git a/src/ntfy/provider.ts b/src/ntfy/provider.ts index 2023806..91aa6af 100644 --- a/src/ntfy/provider.ts +++ b/src/ntfy/provider.ts @@ -1,5 +1,5 @@ import { InjectQueue, Process, Processor } from '@nestjs/bull' -import { Inject, Injectable } from '@nestjs/common' +import { Inject, Injectable, OnApplicationBootstrap } from '@nestjs/common' import { Job, JobOptions, Queue } from 'bull' import { Dayjs } from 'dayjs' @@ -13,7 +13,7 @@ import { @Processor(NTFY_PUBLISH_QUEUE_NAME) @Injectable() -export class NtfyProvider { +export class NtfyProvider implements OnApplicationBootstrap { constructor( @Inject(NtfyClient) private readonly ntfyClient: NtfyClient, @@ -22,6 +22,10 @@ export class NtfyProvider { private readonly publishQueue: Queue, ) {} + async onApplicationBootstrap() { + await this.sendBootstrappedNotification() + } + @Process() async handlePublishJob(job: Job>) { await this.ntfyClient.publish({ @@ -44,6 +48,15 @@ export class NtfyProvider { ] } + async sendBootstrappedNotification() { + await this.publishQueue.add( + ...NtfyProvider.defaultJob({ + title: 'Autobaan up and running', + tags: [MessageTags.badminton], + }), + ) + } + async sendCronStartNotification(title: string) { await this.publishQueue.add( ...NtfyProvider.defaultJob({