76 lines
3.5 KiB
JavaScript
76 lines
3.5 KiB
JavaScript
"use strict";
|
|
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);
|
|
};
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
var TelegramService_1;
|
|
var _a;
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.TelegramService = void 0;
|
|
const common_1 = require("@nestjs/common");
|
|
const config_1 = require("@nestjs/config");
|
|
const axios_1 = __importDefault(require("axios"));
|
|
let TelegramService = TelegramService_1 = class TelegramService {
|
|
configService;
|
|
logger = new common_1.Logger(TelegramService_1.name);
|
|
botToken;
|
|
chatId;
|
|
constructor(configService) {
|
|
this.configService = configService;
|
|
this.botToken = this.configService.get('TELEGRAM_BOT_TOKEN') || '';
|
|
this.chatId = this.configService.get('TELEGRAM_CHAT_ID') || '';
|
|
}
|
|
async sendMessage(text) {
|
|
if (!this.botToken || !this.chatId || this.botToken.includes('YOUR_BOT_TOKEN')) {
|
|
this.logger.warn('Telegram Bot Token or Chat ID not configured. Skipping notification.');
|
|
return false;
|
|
}
|
|
try {
|
|
this.logger.log('Sending report to Telegram...');
|
|
const url = `https://api.telegram.org/bot${this.botToken}/sendMessage`;
|
|
await axios_1.default.post(url, {
|
|
chat_id: this.chatId,
|
|
text: text,
|
|
parse_mode: 'HTML',
|
|
});
|
|
this.logger.log('✅ Telegram notification sent successfully.');
|
|
return true;
|
|
}
|
|
catch (error) {
|
|
this.logger.error(`❌ Failed to send Telegram message: ${error.message}`);
|
|
if (error.response) {
|
|
this.logger.error(`Status: ${error.response.status}, Data: ${JSON.stringify(error.response.data)}`);
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
async sendIntelligenceReport(stats) {
|
|
const message = `
|
|
🚀 <b>Intaleq Map Intelligence Report</b>
|
|
━━━━━━━━━━━━━━━━━━
|
|
📅 <b>Window:</b> Last ${stats.days} days
|
|
📥 <b>Tracks Imported:</b> ${stats.syncResult} points
|
|
🛣️ <b>Roads Updated:</b> ${stats.updatedSegments} segments
|
|
✨ <b>New Roads Found:</b> ${stats.discoveredRoads} candidates
|
|
🕒 <b>Time Profiles:</b> ${stats.timeProfiles || 0} buckets
|
|
📍 <b>Database Total:</b> ${stats.totalPoints} points
|
|
━━━━━━━━━━━━━━━━━━
|
|
✅ <i>Deep Sync and Analysis Complete.</i>
|
|
`;
|
|
return this.sendMessage(message);
|
|
}
|
|
};
|
|
exports.TelegramService = TelegramService;
|
|
exports.TelegramService = TelegramService = TelegramService_1 = __decorate([
|
|
(0, common_1.Injectable)(),
|
|
__metadata("design:paramtypes", [typeof (_a = typeof config_1.ConfigService !== "undefined" && config_1.ConfigService) === "function" ? _a : Object])
|
|
], TelegramService);
|
|
//# sourceMappingURL=telegram.service.js.map
|