The Messenger of Allah ﷺ said, "When the imam says, 'Allah hears whoever praises Him,' say, 'Our Lord, to You belongs all praise.'"
حدثنا هشام بن عمار حدثنا سفيان عن الزهري
أن رسول الله ﷺ قال إذا قال الإمام سمع الله لمن حمده فقولوا ربنا ولك الحمد
Bukhari narrated it in the Book of Adhan, Chapter: He lowers himself with the takbir when he prostrates, Hadith: 805, and Muslim narrated it in the Book of Prayer, Chapter: The follower's following of the imam, Hadith: 411, from the hadith of Sufyan bin Uyayna, with it in full.