telegram bot

This commit is contained in:
Ben
2023-07-07 11:30:38 -04:00
parent 896125c08b
commit 5a49c83ed3
11 changed files with 1393 additions and 31 deletions
@@ -0,0 +1,19 @@
import { Column, Entity, Index, PrimaryGeneratedColumn } from 'typeorm';
import { TrackedEntity } from '../utils/TrackedEntity.entity';
@Entity()
export class TelegramSubscriptionsEntity extends TrackedEntity {
@PrimaryGeneratedColumn()
id: number;
@Index()
@Column({ length: 62, type: 'varchar' })
address: string;
@Column()
telegramChatId: number;
}
@@ -0,0 +1,14 @@
import { Global, Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { TelegramSubscriptionsEntity } from './telegram-subscriptions.entity';
import { TelegramSubscriptionsService } from './telegram-subscriptions.service';
@Global()
@Module({
imports: [TypeOrmModule.forFeature([TelegramSubscriptionsEntity])],
providers: [TelegramSubscriptionsService],
exports: [TypeOrmModule, TelegramSubscriptionsService],
})
export class TelegramSubscriptionsModule { }
@@ -0,0 +1,27 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { TelegramSubscriptionsEntity } from './telegram-subscriptions.entity';
@Injectable()
export class TelegramSubscriptionsService {
constructor(
@InjectRepository(TelegramSubscriptionsEntity)
private telegramSubscriptions: Repository<TelegramSubscriptionsEntity>
) {
}
public async getSubscriptions(address: string) {
return await this.telegramSubscriptions.find({ where: { address } })
}
public async saveSubscription(chatId: number, address: string) {
return await this.telegramSubscriptions.save({
telegramChatId: chatId,
address
});
}
}