You would need something that can monitor iMessages and be triggered by a message from a specific person or by keywords in the received message. As far as I know, even Apple’s own Shortcuts app doesn’t support that.
I don’t know if it would be possible, but you’d be more likely to be able to do this using Messages on a Mac. I vaguely remember trying to do something with Automator and applescript when I was using Indigo.