"I had told you when we were at dinner."
Translation:Te l'avevo detto quando eravamo a cena.
There is no "it" in the original, so it shoud be just "ti avevo" "I told you", not "I told you it."
that's just the way italian works - they always stick an 'it' in, where you wouldnt in english, as in the very common 'non lo so' meaning ' i don't know'.
if the correct answer is understood as "I had told it to you" why isn't you understood as the indirect object and thus would be "ti l'avevo detto"
'Ti' becomes 'te' because it is followed immediately by 'la' or 'lo', in l'avevo. See the link below provided by Alipaulam.
When there are two pronouns in a row, the first (indirect object) pronoun changes its 'i' to 'e';
mi -> me ti - > te si -> se ci-> ce vi -> ve gli -> glie
and glie runs together with the direct object pronoun eg Gliel'ho dato - I gave it to him.
At the end of an imperative, infinitive or gerund, the same thing happens eg dammelo (give it to me, you double the m) non posso darglielo (I can't give it to him, you drop the e on the infinitive) dandomelo (giving it to me).
See for example http://dante-learning.com/eng/2013/07/combining-italian-direct-and-indirect-pronouns-pronomi-combinati-quiz/. for full explanation