There are three steps to it:
Step 1: Affirm the relationship. e.g. “It really is good to hear from you.”
Step 2: Thank the person sincerely for the opportunity. e.g. “Thank you ever so much for thinking of me! It sounds like such a brilliant project. I am complimented that you thought of me.”
Step 3: Decline firmly and politely. e.g.For several reasons I need to pass on this at the moment.