I used this directly in botpress to calculate driv...
# 🌎general
b
I used this directly in botpress to calculate driving time between 2 places
Copy code
const startLocation = `${user.town} ${user.iso2}`
const endLocation = `${bot.currentStreet} ${bot.currentLocation} ${bot.currentCountryIso2}`;
const apiKey = <api-key>

const response = await axios.get(
  `https://www.mapquestapi.com/directions/v2/route?key=${apiKey}&from=${startLocation}&to=${endLocation}&routeType=fastest&unit=m`
)
const travelTime = response.data.route.formattedTime
console.log(`Driving time: ${travelTime}`)

// Parse the travelTime string to get hours and minutes as integers
const timeComponents = travelTime.split(':')
const hours = parseInt(timeComponents[0])
const minutes = parseInt(timeComponents[1])

console.log(`Hours: ${hours}`)
console.log(`Minutes: ${minutes}`)



if (hours === 0) {
  workflow.driveTimeString = `a ${minutes} ${minutes > 1 ? 'minutes' : 'minute'} drive`;
} else if (hours === 1) {
  workflow.driveTimeString = `an hour and ${minutes} ${minutes > 1 ? 'minutes' : 'minute'} drive`;
} else {
  workflow.driveTimeString = `${hours} hours and ${minutes} ${minutes > 1 ? 'minutes' : 'minute'} drive`;
}