Skip to content

Commit 48757c7

Browse files
committed
feat: add chat_id to config and update telegram message sending logic
1 parent b1ced89 commit 48757c7

4 files changed

Lines changed: 10 additions & 17 deletions

File tree

src/config/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export enum NodeEnv {
1010
export interface Config {
1111
database: DatabaseConfig
1212
telegram_token: string
13+
chat_id: string
1314
}
1415

1516
export const getNodeEnv = (): NodeEnv => process.env.NODE_ENV as NodeEnv

src/config/development.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ export const developmentConfig: Config = {
1212
port: 5432,
1313
},
1414
telegram_token: process.env.TELEGRAM_2_TOKEN as string,
15+
chat_id: process.env.CHAT_ID as string,
1516
}

src/config/production.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ export const productionConfig: Config = {
99
port: 5432,
1010
},
1111
telegram_token: process.env.TELEGRAM_TOKEN as string,
12+
chat_id: process.env.CHANNEL_ID as string,
1213
}

src/controllers/telegram.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import { sendTelegramMessage } from '../services/telegram'
2-
import { getTelegramUsers } from '../models/telegram-user'
32
import { InlineKeyboardButton } from 'telegraf/typings/core/types/typegram'
43
import { translateKey } from '../utilites/common'
54
import { ParsedMeteoAlert } from '../utilites/meteo-alerts'
5+
import { config } from '../config/config'
66

77
const separator = '--------------------------------'
88

99
export const sendNewTomorrowAlertMessage = async (alert: ParsedMeteoAlert) => {
10-
const telegramUsers = await getTelegramUsers()
11-
1210
const criticDataMessage = Object.keys(alert.criticZoneData)
1311
.map((key) => {
1412
const color = alert.criticZoneData[key]
@@ -36,18 +34,10 @@ ${separator}
3634

3735
const buttons: InlineKeyboardButton[][] = [[{ text: 'Documento pdf', url: alert.link }]]
3836

39-
for (let i = 0; i < telegramUsers.length; i++) {
40-
const user = telegramUsers[i]
41-
42-
try {
43-
await sendTelegramMessage(user.chat_id, textMessage, {
44-
parse_mode: 'HTML',
45-
reply_markup: {
46-
inline_keyboard: buttons,
47-
},
48-
})
49-
} catch (error) {
50-
console.error(`Failed to send message to user ${user.chat_id}:`, error)
51-
}
52-
}
37+
await sendTelegramMessage(config.chat_id, textMessage, {
38+
parse_mode: 'HTML',
39+
reply_markup: {
40+
inline_keyboard: buttons,
41+
},
42+
})
5343
}

0 commit comments

Comments
 (0)