Skip to content
Browse files

added twilio SMS callback

  • Loading branch information...
1 parent c568293 commit 96e63184a97601d8c04861f02d2e1f3acbef7f1c unknown committed
View
4 AndroidApp/PlaxoAndroid/AndroidManifest.xml
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.barryku.android.plaxo"
- android:versionName="1.1" android:versionCode="7">
- <application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="false">
+ android:versionName="1.1" android:versionCode="8">
+ <application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
<activity android:name=".PlaxoSearch"
android:label="@string/app_name" android:launchMode="singleInstance">
<intent-filter>
View
48 AndroidApp/PlaxoAndroid/src/com/barryku/android/plaxo/PlaxoSearch.java
@@ -114,33 +114,35 @@ public String getContactHtml(Contact[] contacts) {
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Uri uri = intent.getData();
- String phoneUri = uri.toString().substring((CUSTOM_SCHEME + "://").length());
- SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
- int historyCount = prefs.getInt(HISTORY_COUNT, 0);
- String history1 = prefs.getString(HISTORY_PREFIX + 1, "");
- if (!history1.equals(phoneUri)) {
- List<String> histories = new ArrayList<String>();
- histories.add(phoneUri);
- historyCount = historyCount < MAX_HISTORY ? historyCount+1 : MAX_HISTORY;
- if (historyCount > 1) {
- for (int i=1; i<historyCount; i++) {
- if (!prefs.getString(HISTORY_PREFIX + i,"").equals(phoneUri)) {
- histories.add(prefs.getString(HISTORY_PREFIX + i,""));
+ if (uri != null && uri.toString().indexOf(CUSTOM_SCHEME)>-1) {
+ String phoneUri = uri.toString().substring((CUSTOM_SCHEME + "://").length());
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
+ int historyCount = prefs.getInt(HISTORY_COUNT, 0);
+ String history1 = prefs.getString(HISTORY_PREFIX + 1, "");
+ if (!history1.equals(phoneUri)) {
+ List<String> histories = new ArrayList<String>();
+ histories.add(phoneUri);
+ historyCount = historyCount < MAX_HISTORY ? historyCount+1 : MAX_HISTORY;
+ if (historyCount > 1) {
+ for (int i=1; i<historyCount; i++) {
+ if (!prefs.getString(HISTORY_PREFIX + i,"").equals(phoneUri)) {
+ histories.add(prefs.getString(HISTORY_PREFIX + i,""));
+ }
}
}
+ SharedPreferences.Editor editor = prefs.edit();
+ historyCount = 0;
+ for (String history:histories) {
+ historyCount++;
+ editor.putString(HISTORY_PREFIX + historyCount, history);
+ }
+ editor.putInt(HISTORY_COUNT, historyCount);
+ editor.commit();
}
- SharedPreferences.Editor editor = prefs.edit();
- historyCount = 0;
- for (String history:histories) {
- historyCount++;
- editor.putString(HISTORY_PREFIX + historyCount, history);
- }
- editor.putInt(HISTORY_COUNT, historyCount);
- editor.commit();
+ Contact contact = getContactFromPhoneUri(phoneUri);
+ intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + contact.getPhones().get(0).getNumber()));
+ startActivity(intent);
}
- Contact contact = getContactFromPhoneUri(phoneUri);
- intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + contact.getPhones().get(0).getNumber()));
- startActivity(intent);
}
private Contact getContactFromPhoneUri(String phoneUri) {
View
31 GaeApp/pom.xml
@@ -20,6 +20,15 @@
<gae.application.version>test</gae.application.version>
</properties>
+ <repositories>
+ <!-- added for Amazon S3 -->
+ <repository>
+ <id>repository.atlassian.com</id>
+ <name>Atlassian Maven Repository</name>
+ <url>http://repository.atlassian.com/maven2</url>
+ </repository>
+ </repositories>
+
<pluginRepositories>
<pluginRepository>
<id>maven-gae-plugin-repo</id>
@@ -166,20 +175,14 @@
<version>1.1</version>
</dependency>
-<!--
- <dependency>
- <groupId>javax.jdo</groupId>
- <artifactId>jdo2-api</artifactId>
- <version>2.3-eb</version>
- <exclusions>
- <exclusion>
- <groupId>javax.transaction</groupId>
- <artifactId>transaction-api</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
--->
-
+ <dependency>
+ <groupId>com.amazonaws</groupId>
+ <artifactId>aws-java-sdk</artifactId>
+ <version>1.1.1</version>
+ <type>jar</type>
+ <scope>compile</scope>
+ </dependency>
+
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
View
24 GaeApp/src/main/java/com/barryku/gae/controller/SmsController.java
@@ -1,7 +1,6 @@
package com.barryku.gae.controller;
import java.io.IOException;
-import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
@@ -14,10 +13,11 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;
-import org.springframework.web.client.RestTemplate;
import com.barryku.gae.controller.helper.TwilioSmsConfig;
import com.barryku.gae.model.SmsText;
+import com.barryku.gae.model.TwilioCallback;
+import com.barryku.gae.service.AmazonSnsService;
import com.google.appengine.api.urlfetch.HTTPHeader;
import com.google.appengine.api.urlfetch.HTTPMethod;
import com.google.appengine.api.urlfetch.HTTPRequest;
@@ -27,7 +27,6 @@
import com.google.appengine.repackaged.com.google.common.util.Base64;
@Controller
-@RequestMapping("/sms")
@SessionAttributes("sms")
public class SmsController {
private static Log log = LogFactory.getLog(SmsController.class);
@@ -35,7 +34,10 @@
@Autowired
private TwilioSmsConfig twilioConfig;
- @RequestMapping(method = RequestMethod.GET)
+ @Autowired
+ private AmazonSnsService amazonSns;
+
+ @RequestMapping(value="/sms", method = RequestMethod.GET)
public String setupForm(Model model){
SmsText sms = new SmsText();
sms.setFrom(twilioConfig.getFromNumber());
@@ -43,10 +45,9 @@ public String setupForm(Model model){
return "smsForm";
}
- @Autowired
- protected RestTemplate restTemplate;
+
- @RequestMapping(method = RequestMethod.POST)
+ @RequestMapping(value = "/sms", method = RequestMethod.POST)
public String sendSms(@ModelAttribute("sms") SmsText sms) throws IOException {
URL url = new URL(twilioConfig.getRestUrl());
HTTPRequest request = new HTTPRequest(url, HTTPMethod.POST);
@@ -63,5 +64,12 @@ public String sendSms(@ModelAttribute("sms") SmsText sms) throws IOException {
return "smsComplete";
}
-
+
+
+ @RequestMapping(value="/twilio", method = RequestMethod.POST)
+ public String processCallback(@ModelAttribute("twilio") TwilioCallback msg) throws IOException {
+ String msgId = amazonSns.sendTwilioMessage(msg);
+ log.info("SNS ID: " + msgId);
+ return null;
+ }
}
View
102 GaeApp/src/main/java/com/barryku/gae/model/TwilioCallback.java
@@ -0,0 +1,102 @@
+package com.barryku.gae.model;
+
+import java.io.Serializable;
+//see http://www.twilio.com/docs/api/2010-04-01/twiml/sms/twilio_request
+public class TwilioCallback implements Serializable{
+ private static final long serialVersionUID = -820978233633870702L;
+ private String smsSid;
+ private String accountSid;
+ private String from;
+ private String to;
+ private String body;
+ private String fromCity;
+ private String fromState;
+ private String fromZip;
+ private String fromCountry;
+ private String toCity;
+ private String toState;
+ private String toZip;
+ private String toCountry;
+ public String getSmsSid() {
+ return smsSid;
+ }
+ public void setSmsSid(String smsSid) {
+ this.smsSid = smsSid;
+ }
+ public String getAccountSid() {
+ return accountSid;
+ }
+ public void setAccountSid(String accountSid) {
+ this.accountSid = accountSid;
+ }
+ public String getFrom() {
+ return from;
+ }
+ public void setFrom(String from) {
+ this.from = from;
+ }
+ public String getTo() {
+ return to;
+ }
+ public void setTo(String to) {
+ this.to = to;
+ }
+ public String getBody() {
+ return body;
+ }
+ public void setBody(String body) {
+ this.body = body;
+ }
+ public String getFromCity() {
+ return fromCity;
+ }
+ public void setFromCity(String fromCity) {
+ this.fromCity = fromCity;
+ }
+ public String getFromState() {
+ return fromState;
+ }
+ public void setFromState(String fromState) {
+ this.fromState = fromState;
+ }
+ public String getFromZip() {
+ return fromZip;
+ }
+ public void setFromZip(String fromZip) {
+ this.fromZip = fromZip;
+ }
+ public String getFromCountry() {
+ return fromCountry;
+ }
+ public void setFromCountry(String fromCountry) {
+ this.fromCountry = fromCountry;
+ }
+ public String getToCity() {
+ return toCity;
+ }
+ public void setToCity(String toCity) {
+ this.toCity = toCity;
+ }
+ public String getToState() {
+ return toState;
+ }
+ public void setToState(String toState) {
+ this.toState = toState;
+ }
+ public String getToZip() {
+ return toZip;
+ }
+ public void setToZip(String toZip) {
+ this.toZip = toZip;
+ }
+ public String getToCountry() {
+ return toCountry;
+ }
+ public void setToCountry(String toCountry) {
+ this.toCountry = toCountry;
+ }
+ public static long getSerialversionuid() {
+ return serialVersionUID;
+ }
+
+}
View
31 GaeApp/src/main/java/com/barryku/gae/service/AmazonSnsService.java
@@ -0,0 +1,31 @@
+package com.barryku.gae.service;
+
+import com.amazonaws.services.sns.AmazonSNSClient;
+import com.amazonaws.services.sns.model.PublishRequest;
+import com.amazonaws.services.sns.model.PublishResult;
+import com.barryku.gae.model.TwilioCallback;
+
+public class AmazonSnsService {
+
+ private AmazonSNSClient sns;
+ private String topicArn;
+
+ public AmazonSnsService(AmazonSNSClient sns) {
+ this.sns = sns;
+ }
+
+ public String sendTwilioMessage(TwilioCallback msg) {
+ PublishRequest request = new PublishRequest(topicArn, msg.getBody(), msg.getFrom());
+ PublishResult result = sns.publish(request);
+ return result.getMessageId();
+ }
+
+ public void setTopicArn(String topicArn) {
+ this.topicArn = topicArn;
+ }
+
+ public String getTopicArn() {
+ return topicArn;
+ }
+
+}
View
17 GaeApp/src/main/webapp/WEB-INF/mvc-servlet.xml
@@ -39,6 +39,21 @@
<property name="sid" value="${twilio.sid}"/>
<property name="authToken" value ="${twilio.authToken}"/>
</bean>
-
+
+<!-- Amazon SNS -->
+ <bean id="amazonSns" class="com.barryku.gae.service.AmazonSnsService">
+
+ <constructor-arg>
+ <bean class="com.amazonaws.services.sns.AmazonSNSClient">
+ <constructor-arg>
+ <bean class="com.amazonaws.auth.BasicAWSCredentials">
+ <constructor-arg value="${amazon.accessKey}"/>
+ <constructor-arg value="${amazon.accessSecret}"/>
+ </bean>
+ </constructor-arg>
+ </bean>
+ </constructor-arg>
+ <property name="topicArn" value="${amazon.topicArn}"/>
+ </bean>
</beans>
View
11 GaeApp/src/main/webapp/WEB-INF/spring.properties
@@ -1,6 +1,11 @@
repositoryService = googleAppRepositoryService
-twilio.authToken = xxx
-twilio.sid = xxx
+twilio.authToken = x
+twilio.sid = x
twilio.restUrl = https://api.twilio.com/2010-04-01/Accounts
-twilio.fromNumber = 408-555-12-12
+twilio.fromNumber = x
+
+
+amazon.accessKey = x
+amazon.accessSecret = x
+amazon.topicArn= x

0 comments on commit 96e6318

Please sign in to comment.
Something went wrong with that request. Please try again.