WASHINGTON (Reuters) - Dining on rib-eye steak and peach cobbler with a group of senators, President Donald Trump was cautiously optimistic that Republican efforts to overhaul Obamacare were in good shape.

U.S. President Donald Trump speaks during a lunch meeting with Senate Republicans to discuss healthcare at the White House in Washington, U.S., July 19, 2017. From left are U.S. Senators Shelley Moore Capito (R-WV), Dean Heller (R-NV), Tim Scott (R-SC) and Lisa Murkowski (R-AK). REUTERS/Kevin Lamarque

Then came word that two Republican senators not at the dinner - Mike Lee of Utah and Jerry Moran of Kansas - had announced their opposition to the healthcare proposals put forward by party leaders in the Senate.

The setback on Monday night triggered a last-gasp effort by the president and top aides to keep the legislation from dying. He called 49 Republican senators over to the White House for lunch and a scolding on Wednesday, telling them they needed to settle their differences and that they should postpone their summer recess until a deal was done.

“For seven years you promised the American people you would repeal Obamacare. People are hurting and frankly inaction is not an option,” said Trump, who desperately wants a legislative victory to make good on his campaign promises to repeal and replace the Affordable Care Act, commonly known as Obamacare.

It is by no means clear if Trump’s pressure can help Republicans overcome sharp differences between moderates who want to preserve health insurance for their constituents and conservatives insisting on lower costs.

But after doing little over the past few weeks to win senators’ support for the controversial legislation, Trump is now staking his reputation on getting them to cut a deal.

Senior White House aides said on Wednesday the president sensed the healthcare effort could be salvaged despite the grim outlook.

After a series of conversations with Senate Majority Leader Mitch McConnell as well as Lee, Senator John Cornyn of Texas and others, White House chief of staff Reince Priebus told Trump he felt it was possible to keep the effort alive.

Trump agreed, based on his own talks with senators, and told aides he was hearing that “a lot of people don’t want this to be over,” an aide said.

Senator Ted Cruz, who has led conservative criticisms of the proposals, was also sounding more positive.

So Trump dispatched Vice President Mike Pence and Priebus to Capitol Hill on Tuesday to see if there was room to maneuver, the aides said.

Pence and Priebus worked the room, talking to nearly every senator present and urging them not to concede defeat.

The two men reported back to Trump and he decided to invite the Republican senators for lunch, the aides said.

At that lunch, beneath the portrait of Abraham Lincoln in the White House’s State Dining Room, Trump made clear he wanted the senators to go back to the drawing board before heading out on vacation in August.

“Any senator who doesn’t vote to open debate is really saying they’re okay with Obamacare,” he told the room. “We shouldn’t leave town until this is complete, until this bill is on my desk and until we all go over to the Oval Office, I’ll sign it and we can celebrate with the American people.”

Some of the senators who have opposed parts of the legislative effort were strategically placed around the room. Next to Trump was Senator Dean Heller of Nevada and Lee was next to Pence.

Trump referred to Heller with a chuckle, “Look, he wants to remain a senator, doesn’t he?”

The comment drew a wry smile from Heller.

After nearly two hours of talks over lunch, the group agreed to meet on Wednesday night to start talks on whether the hurdles could be overcome. But Cruz said after the meeting that they were still divided on some issues.

Every Democrat in the Senate is opposed to the repeal of Obamacare, so it can only pass if Republicans are united. Polls show the proposals are unpopular, so some Republican lawmakers fear a backlash.

White House aides said they hope an agreement can be worked out by next week.