Indirect object pronouns replace a person introduced by à — the "to/for someone" of a sentence: me/m', te/t', lui (to him/her), nous, vous, leur (to them). They're used with verbs that naturally take à + a person, like parler à, donner à, and écrire à.
Lui and leur don't change for gender — lui means "to him" or "to her" depending on context, and which person lui is standing in for is only clear from what came before: je parle à Marie → je lui parle (I'm talking to her). Like direct object pronouns, they go before the conjugated verb: il nous téléphone (he calls us).