mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-28 16:00:56 +00:00
51 lines
1.2 KiB
TypeScript
51 lines
1.2 KiB
TypeScript
import {
|
|
Inject,
|
|
Injectable,
|
|
Logger,
|
|
OnApplicationBootstrap,
|
|
} from "@nestjs/common";
|
|
import { ClientProxy } from "@nestjs/microservices";
|
|
import { BulkMessagesDto, SingleMessageDto } from "./dtos/sms.dto";
|
|
|
|
@Injectable()
|
|
export class SmsClientService implements OnApplicationBootstrap {
|
|
private readonly logger = new Logger(SmsClientService.name);
|
|
|
|
constructor(
|
|
@Inject("SMS_SERVICE")
|
|
private smsClient: ClientProxy,
|
|
) {}
|
|
|
|
private readonly enabled = process.env.RABBITMQ_ENABLED !== "false";
|
|
|
|
async onApplicationBootstrap() {
|
|
if (!this.enabled) return;
|
|
this.smsClient
|
|
.connect()
|
|
.then(() => {
|
|
this.logger.log("connected to SMS service");
|
|
})
|
|
.catch((err) => {
|
|
console.error("Error happened at SMS service", err);
|
|
});
|
|
}
|
|
|
|
async sendSms(dto: SingleMessageDto) {
|
|
if (!this.enabled) return {};
|
|
this.smsClient.emit("send-sms", {
|
|
...dto,
|
|
appKey: "IFHCRS-LICENSE-MANAGEMENT",
|
|
});
|
|
return {};
|
|
}
|
|
|
|
async sendBulkMessages(dto: BulkMessagesDto) {
|
|
if (!this.enabled) return {};
|
|
this.smsClient.emit("ozeking-bulk-sms", {
|
|
...dto,
|
|
appKey: "IFHCRS-LICENSE-MANAGEMENT",
|
|
});
|
|
return {};
|
|
}
|
|
}
|