@@ -3,6 +3,9 @@ import { ElaboratedIntervention, checkIfInterventionIsOfCompetence } from './int
33import * as locations from '../data/locations.json'
44import { getGoogleMapsRoute } from '../services/google-maps'
55import { getTelegramUsers } from '../models/telegramuser'
6+ import { MolinellaCoordinates } from '../utilites/constants'
7+
8+ const molinellaWord = 'MOLINELLA'
69
710const separator = '--------------------------------'
811
@@ -15,7 +18,7 @@ export const sendInterventionMessage = async (intervention: ElaboratedInterventi
1518
1619 const mapsUrl = `https://www.google.it/maps/place/${ intervention . intervention . latitude } ,${ intervention . intervention . longitude } `
1720 const appleMapsUrl = `https://maps.apple.com/?ll=${ intervention . intervention . latitude } ,${ intervention . intervention . longitude } `
18- const wazeUrl = `https://waze.com/ul?ll=${ intervention . intervention . latitude } ,${ intervention . intervention . longitude } &navigate=yes `
21+ const wazeUrl = `https://waze.com/ul?ll=${ intervention . intervention . latitude } ,${ intervention . intervention . longitude } `
1922
2023 // Prepare the competence message with MOLINELLA in bold
2124 const competencesMessage = await generateCompetenceMessage ( intervention )
@@ -24,15 +27,11 @@ export const sendInterventionMessage = async (intervention: ElaboratedInterventi
2427 const textMessage = `
2528🚒 ${ title }
2629📟 ${ intervention . intervention . title }
27- 📏 ${ Math . round ( intervention . distance * 100 ) / 100 } km in linea d'aria
2830${ separator }
2931🗺️ Competenze:
3032${ competencesMessage }
3133${ separator }
3234📢 ${ intervention . intervention . sender }
33-
34- ** Note: **
35- - Le distanze dai distaccamenti sono calcolate sul momento sulla base del traffico stradale. I tempi di percorrenza sono indicativi e possono variare in base alle condizioni del traffico.
3635`
3736
3837 const telegramUsers = await getTelegramUsers ( )
@@ -101,5 +100,29 @@ export const generateCompetenceMessage = async (intervention: ElaboratedInterven
101100 }
102101 }
103102
104- return computedCompetences . join ( '\n' )
103+ const hasMolinella = computedCompetences . some ( ( c ) => c . toUpperCase ( ) . includes ( molinellaWord ) )
104+
105+ if ( ! hasMolinella ) {
106+ const routeInformations = await getGoogleMapsRoute (
107+ {
108+ latitude : MolinellaCoordinates . latitude ,
109+ longitude : MolinellaCoordinates . longitude ,
110+ } ,
111+ {
112+ latitude : intervention . intervention . latitude ,
113+ longitude : intervention . intervention . longitude ,
114+ }
115+ )
116+
117+ let distances = '(N/A)'
118+
119+ if ( routeInformations ) {
120+ distances = `(${ routeInformations . distance } km, ${ routeInformations . duration } min)`
121+ }
122+
123+ computedCompetences . push ( `\n*. ${ molinellaWord } ${ distances } ` )
124+ }
125+
126+ // Join and put molinella in bold
127+ return computedCompetences . join ( '\n' ) . replace ( molinellaWord , `<b>${ molinellaWord } </b>` )
105128}
0 commit comments