The House has passed a bill to reauthorise a key foreign intelligence collection programme but with an important tweak: It would require the FBI to get a warrant if it wants to view the contents of Americans’ communications swept up in the process.

Legislation to renew the programme that allows spy agencies to conduct surveillance on foreign targets abroad passed the House 256-164 and now heads to the Senate.

President Donald Trump has said he will sign the bill, which would extend the programme for six years.

Director of national intelligence Dan Coats called foreign intelligence the “holy grail” that provides insight into the thinking and actions of US adversaries.

However, the programme, which is to expire on January 19, also sweeps up Americans’ communications.

Privacy advocates and some lawmakers from both parties want to require the FBI to get a warrant if it wants to query or view the content of Americans’ communications that are in the database to build domestic crime cases.

The bill passed by the House would allow the FBI to continuing querying the database, using search terms, for information on Americans, but would require investigators to get a probable cause warrant if they want to view the actual content of those communications.

Earlier, the House rejected a measure that would have imposed stiffer restrictions on the FBI. It would have required the FBI to get a warrant to continue even querying the database where Americans’ communications are involved.

Mr Trump’s morning tweets caused confusion in advance of the House vote.

One of his tweets suggested that the foreign intelligence programme was used to collect information that might have been used to taint his campaign.

Afterwards, Mr Trump had a phone call with House Speaker Paul Ryan, according to a Republican familiar with the call but not allowed to publicly discuss private discussions.

A short time later, Mr Trump changed his tone on Twitter. “This vote is about foreign surveillance of foreign bad guys on foreign land,” he tweeted. “We need it! Get smart!”

Representative Adam Schiff of California, the top-ranking Democrat on the House intelligence committee, said Mr Trump’s tweets were “inaccurate, conflicting and confusing.” He suggested that a vote on the bill should be delayed but it went forward.

The president appeared to contradict the position of his own administration.

In one tweet, he linked the FISA programme that his White House supports to a dossier that alleges his campaign had ties to Russia. That caught aides and lawmakers off guard. A short time later, he went further.

“House votes on controversial FISA ACT today,” Mr Trump wrote, citing a Fox News headline. “This is the act that may have been used, with the help of the discredited and phony Dossier, to so badly surveil and abuse the Trump Campaign by the previous administration and others?”