nestwhats
Version:
A whatsapp-web.js wrapper for NestJS to create WhatsApp bots
53 lines (52 loc) • 2.83 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.NestWhatsHealthIndicator = void 0;
const common_1 = require("@nestjs/common");
const clients_registry_service_1 = require("./clients-registry.service");
const commands_registry_service_1 = require("./commands/commands-registry.service");
const listener_registry_service_1 = require("./listeners/listener-registry.service");
let NestWhatsHealthIndicator = class NestWhatsHealthIndicator {
constructor(clientsRegistry, commandsRegistry, listenerRegistry) {
this.clientsRegistry = clientsRegistry;
this.commandsRegistry = commandsRegistry;
this.listenerRegistry = listenerRegistry;
}
isHealthy(key = "whatsapp") {
const entries = this.clientsRegistry.getAll();
const now = Date.now();
const breakdown = Object.fromEntries(Object.values(clients_registry_service_1.ClientStatus).map((s) => [s, 0]));
for (const e of entries)
breakdown[e.status]++;
const clients = Object.fromEntries(entries.map((e) => [
e.name,
{ status: e.status, since: Math.floor((now - e.statusAt) / 1000) },
]));
const up = entries.every((e) => e.status === clients_registry_service_1.ClientStatus.Ready ||
e.status === clients_registry_service_1.ClientStatus.Authenticated);
return {
[key]: {
status: up ? "up" : "down",
commands: this.commandsRegistry.getAll().length,
listeners: this.listenerRegistry.getAll().length,
breakdown,
clients,
},
};
}
};
exports.NestWhatsHealthIndicator = NestWhatsHealthIndicator;
exports.NestWhatsHealthIndicator = NestWhatsHealthIndicator = __decorate([
(0, common_1.Injectable)(),
__metadata("design:paramtypes", [clients_registry_service_1.ClientsRegistryService,
commands_registry_service_1.CommandsRegistryService,
listener_registry_service_1.ListenerRegistryService])
], NestWhatsHealthIndicator);