You could try using DCOP as follows:
dcop kopete KopeteIface messageContact "$contact" "`figlet.sh`"
However, I don't know how you'd go about figuring where the last message was sent to/is being sent to. Fire up kdcop and poke around the Kopete DCOP interface - I've been doing this for the past few days