Rule reminder
Context determines the right phrase: time of day → greeting; first meeting → Piacere; departing → farewell; asking wellbeing → Come stai/sta?; bad news → Mi dispiace; register (formal/informal) must match the situation.
Your friend has just told you some bad news. What do you say?