Reputation: 33
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.
Upvotes: 3
Views: 468
Reputation: 3811
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 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)) {
subscriber.setSubscribed(message.startsWith(SUBSCRIBE_COMMAND));
repository.update(subscriber);
if (!subscriber.isSubscribed())
output = "You have unsubscribed from notifications. Textt 'subscribe' to start receiving updates again";
else
output = "You are now subscribed for updates.";
}
return output;
Upvotes: 1