File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ export enum NodeEnv {
1010export interface Config {
1111 database : DatabaseConfig
1212 telegram_token : string
13+ chat_id : string
1314}
1415
1516export const getNodeEnv = ( ) : NodeEnv => process . env . NODE_ENV as NodeEnv
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change 11import { sendTelegramMessage } from '../services/telegram'
2- import { getTelegramUsers } from '../models/telegram-user'
32import { InlineKeyboardButton } from 'telegraf/typings/core/types/typegram'
43import { translateKey } from '../utilites/common'
54import { ParsedMeteoAlert } from '../utilites/meteo-alerts'
5+ import { config } from '../config/config'
66
77const separator = '--------------------------------'
88
99export 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}
You can’t perform that action at this time.
0 commit comments