witness commit

This commit is contained in:
Ben
2023-07-09 16:24:01 -04:00
parent 4b4b04a52c
commit b6ddca5a8f
6 changed files with 39 additions and 23 deletions
+5 -6
View File
@@ -14,8 +14,7 @@ export class TelegramService implements OnModuleInit {
private readonly telegramSubscriptionsService: TelegramSubscriptionsService
) {
const token: string | null = this.configService.get('TELEGRAM_BOT_TOKEN');
if (token == null || token.length < 1) {
console.log('No Telegram token found');
if (token.length < 1) {
return;
}
this.bot = new TelegramBot(token, { polling: true });
@@ -27,7 +26,7 @@ export class TelegramService implements OnModuleInit {
async onModuleInit(): Promise<void> {
if (this.bot == null) {
return null;
return;
}
this.bot.onText(/\/subscribe/, async (msg) => {
@@ -49,14 +48,14 @@ export class TelegramService implements OnModuleInit {
});
}
public async notifySubscribersBlockFound(address: string) {
public async notifySubscribersBlockFound(address: string, message: string) {
if (this.bot == null) {
return null;
return;
}
const subscribers = await this.telegramSubscriptionsService.getSubscriptions(address);
subscribers.forEach(subscriber => {
this.bot.sendMessage(subscriber.telegramChatId, 'You found a block!');
this.bot.sendMessage(subscriber.telegramChatId, `You found a block! ${message}`);
});
}
}