MEXICO CITY (Reuters) - Trapped under tons of rubble and in complete darkness, Diana Pacheco’s hopes were fading fast for making it out alive from a collapsed office building after a huge earthquake in Mexico City, despite rescuers’ frantic attempts to reach her.

Then the trapped woman had a great stroke of luck: a series of short messages she had written and sent to her husband some 16 hours earlier lit up his phone screen.

“My love”

“The ceiling fell”

“We’re trapped”

“I love you”

“I love you a lot”

“We’re on the fourth floor”

“Near the emergency stairway”

“There’s four of us,” read the WhatsApp messages, which finally reached her husband Juan Jesus Garcia on Wednesday at 5:34 a.m.

Garcia, 33, an Uber driver, had been waiting, often in tears, beside the collapsed building all night and immediately ran over to rescue workers.

“It was like a miracle because I was the only one who got the message and since I was there with the rescue workers I talked to them and they could locate her,” said Garcia.

The messages on Garcia’s phone, seen by Reuters shortly after they were received on Wednesday, could have been delayed due to erratic cell phone coverage in parts of Mexico City after the quake, or the fact that Pacheco’s phone signal was blocked by the tons of concrete that kept her trapped in the collapsed building.

When asked whether WhatsApp messages can be delivered hours after they were sent in an area without good cellphone coverage, a spokeswoman for the company confirmed it is possible.

Pacheco, a recruiter for a human resources and accounting firm, said she sent the messages shortly after the 7.1 magnitude earthquake struck at 1:14 p.m. on Tuesday.

“Those messages helped them know more or less where we were located,” Pacheco said on Friday from her hospital bed, her voice weak.

Using the information to pinpoint their location, rescuers freed Pacheco, 30, and the three other survivors shortly after 6 a.m. on Wednesday.

Rescue operations were still underway on Friday at the building, where Pacheco says there were some 60 people on her floor alone at the time of the quake.

“I think there are people (alive) there because we had oxygen, air was coming in,” she said.

Despite having bruises all over her body and wearing a neck brace, Pacheco was generally in good health.

She said she tried to send WhatsApp and text messages to other people from under the building, as well as make phone calls and post on Facebook, but only the messages to her husband got through.

She said when the building fell, the force of two floors above collapsing violently knocked her down, but a wall of concrete stopped just short of crushing her and three of her coworkers. They found themselves huddled together in a cramped space.

They screamed out every time they heard voices from outside the building.

“We heard them (rescue workers) when they asked us to yell or make noise, but regardless of how much we yelled they couldn’t hear us,” Pacheco said.

The quake, Mexico’s deadliest in a generation, has already claimed close to 300 lives. [nL5N1M330H]

(This version of the story has been refiled to change the date in dateline.)