Opening statements are set to begin Monday in the trial of Ahmad Khan Rahimi, accused of setting off bombs in New York’s Chelsea neighborhood and New Jersey in 2016. (Mel Evans/AP)

Weeks before he allegedly planted bombs in New York City and New Jersey, federal officials say Ahmad Khan Rahimi had a jokey text conversation with a relative about explosives and government surveillance.

"Don't wanna find any bomb plans,'' the unidentified relative texted him in August of 2016, according to court records.

"This is not the place to joke,'' Rahimi replied. "Too late they reading our messages,'' the relative answered, adding "IF THE NSA IS READING THIS I DO NOT KNOW ANYTHING.'' Rahimi then replied: "Give them good reason to invade my privacy.''

On Monday morning, Rahimi will go on trial in Manhattan federal court, accused of detonating a bomb in the Chelsea neighborhood on Sept. 17, 2016, that injured 31 people, sent a dumpster flying, and sparked a frantic manhunt for the suspect. He also left a bomb in New York, detonated one earlier along the course of a charity 5k race in Seaside Park, N.J., and dumped a bag full of pipe bombs outside a train station before trying to disappear, according to investigators.

The two-day manhunt ended when police officers in Linden, N.J., approached a man sleeping in the doorway of a bar. Investigators say the 29-year-old Rahimi pulled a gun from a fanny pack and started shooting. One of the bullets struck an officer in his bulletproof vest. Rahimi was badly wounded in the shootout.

While in the hospital recuperating, Rahimi made several incriminating statements to FBI agents, but Rahimi's attorneys argue that those exchanges were improper because their client was suffering from grave injuries, in and out of consciousness and in no condition to waive his Miranda rights. Prosecutors have said they will not try to use those statements at trial.

Court records show they have a wealth of other evidence. Besides the text messages, there are emails from 2012 showing Rahimi's interest in violent Islamist militant propaganda, sales records indicating he bought the material used to make pressure-cooker bombs and pipe bombs, and video that captures him leaving his neighborhood in New Jersey and traveling to the bomb sites.

There are also videos shot outside his residence on the day the bombs were planted that show a figure who appears to be Rahimi carrying multiple bags, video of his arrival at Penn Station in Manhattan, video of his movements and specifically leaving one of the bombs on West 27th Street. Investigators say they have fingerprint evidence tying Rahimi to the bombs, according to court records.

Prosecutors also hope to show the jury the mangled trash container that was sent flying, allegedly after Rahimi placed one of the pressure-cooker bombs inside it.

The most damning evidence, however, may be the letter written in a notebook Rahimi was carrying when he had the shootout with police. Stained by blood and torn in places, the letter is addressed to the U.S. government and describes his anger over U.S. foreign policy, indicates his admiration of Osama bin Laden and Anwar al-Awlaki, and ends with the declaration: "Inshallah the sounds of bombs will be heard in the streets. Gunshots to your police. Death to your OPPRESSION.''

Rahimi, whose last name is sometimes spelled in government documents as Rahami, faces a possible life prison sentence if convicted in what is expected to be a two-week trial. He also faces separate charges in New Jersey for the bombs allegedly left there.

Counterterrorism officials have described Rahimi as a lone wolf who was not part of any broader conspiracy, but someone inspired by terrorist propaganda — much of it from overseas — who decided to act on his own. Prosecutors say a laptop in Rahimi's home contained 14 issues of al-Qaeda's "Inspire" magazine, which included various bombmaking recipes.

The case also shows the difficulty of preventing terrorist threats even when there is a hint of danger. The FBI briefly looked into Rahimi in 2014, after they learned his father had made comments to others indicating his son might be involved in terrorism. But that investigation ended after an FBI review found no links between Rahimi and terrorist groups.