Trump's warning, posted on social media, came after it was confirmed US officials had held direct talks with Hamas.