TAGS :Viewed: 5 - Published at: a few seconds ago

[ How to recieve and store incomming messages in twilio using a java tomcat application? ]

Im using java and I'm successfully implemented twilio messaging API and now I can send messages from my application. I want to know How can I receive and store messages if someone replies to that message.

Twilio Docs shows how to receive and set auto response but I'm not able to catch up.

Twilio: Receiving Incoming Text Messages

I'm only a few months experienced in java so any help is deeply appreciated.

thank you.

Answer 1

Amal you can check out more fully featured examples in Java via Twilio tutorials. Like this one for example: https://www.twilio.com/docs/tutorials/walkthrough/marketing-notifications/java/servlets#3

Where this controller logic handles the incoming text message to do a couple things:

  • If the texter is a person already in the database, parse the message they sent to see if it's a command we recognize.
  • If it is a subscribe or unsubscribe command, update their subscription status in the database.
  • If it is a command we don't recognize, send them a message explaining available commands.

  • String output = "Sorry, we don't recognize that command. Available commands are: 'subscribe' or 'unsubscribe'.";
    if (message.startsWith(SUBSCRIBE_COMMAND) || message.startsWith(UNSUBSCRIBE_COMMAND)) {
        if (!subscriber.isSubscribed())
            output = "You have unsubscribed from notifications. Textt 'subscribe' to start receiving updates again";
            output = "You are now subscribed for updates.";
    return output;