Its not really a twilio issue, but for every text you receive, you need to store the number in a database of some sort, and do a lookup against that table to check if a reply should be sent.
You won't be able to do this with just twiml, you'll need to add a bit of custom code in the language of your choice.