Update remove-twilio patch to more completely remove it
This commit is contained in:
parent
37f43a05f8
commit
6b8592d1d6
1 changed files with 39 additions and 101 deletions
|
@ -1,118 +1,56 @@
|
||||||
diff --git a/src/main/java/org/whispersystems/textsecuregcm/sms/TwilioSmsSender.java b/src/main/java/org/whispersystems/textsecuregcm/sms/TwilioSmsSender.java
|
diff --git a/src/main/java/org/whispersystems/textsecuregcm/sms/SmsSender.java b/src/main/java/org/whispersystems/textsecuregcm/sms/SmsSender.java
|
||||||
index 481965d..9e130f8 100644
|
index 8b62e0f..3bde269 100644
|
||||||
--- a/src/main/java/org/whispersystems/textsecuregcm/sms/TwilioSmsSender.java
|
--- a/src/main/java/org/whispersystems/textsecuregcm/sms/SmsSender.java
|
||||||
+++ b/src/main/java/org/whispersystems/textsecuregcm/sms/TwilioSmsSender.java
|
+++ b/src/main/java/org/whispersystems/textsecuregcm/sms/SmsSender.java
|
||||||
@@ -19,105 +19,36 @@ package org.whispersystems.textsecuregcm.sms;
|
@@ -17,27 +17,17 @@
|
||||||
import com.codahale.metrics.Meter;
|
package org.whispersystems.textsecuregcm.sms;
|
||||||
import com.codahale.metrics.MetricRegistry;
|
|
||||||
import com.codahale.metrics.SharedMetricRegistries;
|
|
||||||
-import com.twilio.sdk.TwilioRestClient;
|
|
||||||
-import com.twilio.sdk.TwilioRestException;
|
-import com.twilio.sdk.TwilioRestException;
|
||||||
-import com.twilio.sdk.resource.factory.CallFactory;
|
import org.slf4j.Logger;
|
||||||
-import com.twilio.sdk.resource.factory.MessageFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
-import org.apache.http.NameValuePair;
|
|
||||||
-import org.apache.http.message.BasicNameValuePair;
|
|
||||||
import org.whispersystems.textsecuregcm.configuration.TwilioConfiguration;
|
|
||||||
import org.whispersystems.textsecuregcm.util.Constants;
|
|
||||||
-import org.whispersystems.textsecuregcm.util.Util;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
-import java.util.ArrayList;
|
|
||||||
-import java.util.HashMap;
|
|
||||||
-import java.util.LinkedList;
|
|
||||||
-import java.util.List;
|
|
||||||
-import java.util.Map;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
-import java.util.Random;
|
|
||||||
+
|
|
||||||
+import org.slf4j.Logger;
|
|
||||||
+import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import static com.codahale.metrics.MetricRegistry.name;
|
|
||||||
|
|
||||||
-@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
|
-@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
|
||||||
public class TwilioSmsSender {
|
public class SmsSender {
|
||||||
|
|
||||||
- public static final String SAY_TWIML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
|
|
||||||
- "<Response>\n" +
|
|
||||||
- " <Say voice=\"woman\" language=\"en\" loop=\"3\">" + SmsSender.VOX_VERIFICATION_TEXT + "%s.</Say>\n" +
|
|
||||||
- "</Response>";
|
|
||||||
-
|
-
|
||||||
private final MetricRegistry metricRegistry = SharedMetricRegistries.getOrCreate(Constants.METRICS_NAME);
|
- static final String SMS_IOS_VERIFICATION_TEXT = "Your Signal verification code: %s\n\nOr tap: sgnl://verify/%s";
|
||||||
private final Meter smsMeter = metricRegistry.meter(name(getClass(), "sms", "delivered"));
|
- static final String SMS_VERIFICATION_TEXT = "Your Signal verification code: %s";
|
||||||
private final Meter voxMeter = metricRegistry.meter(name(getClass(), "vox", "delivered"));
|
- static final String VOX_VERIFICATION_TEXT = "Your Signal verification code is: ";
|
||||||
|
-
|
||||||
|
private final Logger logger = LoggerFactory.getLogger(SmsSender.class);
|
||||||
|
|
||||||
- private final String accountId;
|
- private final TwilioSmsSender twilioSender;
|
||||||
- private final String accountToken;
|
+ public SmsSender(TwilioSmsSender twilioSender) {
|
||||||
- private final ArrayList<String> numbers;
|
|
||||||
- private final String messagingServicesId;
|
|
||||||
- private final String localDomain;
|
|
||||||
- private final Random random;
|
|
||||||
+ private final Logger logger = LoggerFactory.getLogger(TwilioSmsSender.class);
|
|
||||||
|
|
||||||
public TwilioSmsSender(TwilioConfiguration config) {
|
- public SmsSender(TwilioSmsSender twilioSender)
|
||||||
- this.accountId = config.getAccountId ();
|
|
||||||
- this.accountToken = config.getAccountToken();
|
|
||||||
- this.numbers = new ArrayList<>(config.getNumbers());
|
|
||||||
- this.localDomain = config.getLocalDomain();
|
|
||||||
- this.messagingServicesId = config.getMessagingServicesId();
|
|
||||||
- this.random = new Random(System.currentTimeMillis());
|
|
||||||
}
|
|
||||||
|
|
||||||
- public void deliverSmsVerification(String destination, Optional<String> clientType, String verificationCode)
|
|
||||||
- throws IOException, TwilioRestException
|
|
||||||
- {
|
- {
|
||||||
- TwilioRestClient client = new TwilioRestClient(accountId, accountToken);
|
- this.twilioSender = twilioSender;
|
||||||
- MessageFactory messageFactory = client.getAccount().getMessageFactory();
|
|
||||||
- List<NameValuePair> messageParams = new LinkedList<>();
|
|
||||||
- messageParams.add(new BasicNameValuePair("To", destination));
|
|
||||||
-
|
|
||||||
- if (Util.isEmpty(messagingServicesId)) {
|
|
||||||
- messageParams.add(new BasicNameValuePair("From", getRandom(random, numbers)));
|
|
||||||
- } else {
|
|
||||||
- messageParams.add(new BasicNameValuePair("MessagingServiceSid", messagingServicesId));
|
|
||||||
- }
|
|
||||||
-
|
|
||||||
- if ("ios".equals(clientType.orElse(null))) {
|
|
||||||
- messageParams.add(new BasicNameValuePair("Body", String.format(SmsSender.SMS_IOS_VERIFICATION_TEXT, verificationCode, verificationCode)));
|
|
||||||
- } else {
|
|
||||||
- messageParams.add(new BasicNameValuePair("Body", String.format(SmsSender.SMS_VERIFICATION_TEXT, verificationCode)));
|
|
||||||
- }
|
|
||||||
-
|
|
||||||
- try {
|
|
||||||
- messageFactory.create(messageParams);
|
|
||||||
- } catch (RuntimeException damnYouTwilio) {
|
|
||||||
- throw new IOException(damnYouTwilio);
|
|
||||||
- }
|
|
||||||
-
|
|
||||||
+ public void deliverSmsVerification(String destination, Optional<String> clientType, String verificationCode) throws IOException {
|
|
||||||
+ logger.info("Pretending to send SMS verification to " + destination + ": " + verificationCode);
|
|
||||||
smsMeter.mark();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- public void deliverVoxVerification(String destination, String verificationCode)
|
public void deliverSmsVerification(String destination, Optional<String> clientType, String verificationCode)
|
||||||
- throws IOException, TwilioRestException
|
@@ -48,20 +38,12 @@ public class SmsSender {
|
||||||
- {
|
destination = "+521" + destination.substring(3);
|
||||||
- TwilioRestClient client = new TwilioRestClient(accountId, accountToken);
|
|
||||||
- CallFactory callFactory = client.getAccount().getCallFactory();
|
|
||||||
- Map<String, String> callParams = new HashMap<>();
|
|
||||||
- callParams.put("To", destination);
|
|
||||||
- callParams.put("From", getRandom(random, numbers));
|
|
||||||
- callParams.put("Url", "https://" + localDomain + "/v1/accounts/voice/twiml/" + verificationCode);
|
|
||||||
-
|
|
||||||
- try {
|
|
||||||
- callFactory.create(callParams);
|
|
||||||
- } catch (RuntimeException damnYouTwilio) {
|
|
||||||
- throw new IOException(damnYouTwilio);
|
|
||||||
- }
|
|
||||||
-
|
|
||||||
+ public void deliverVoxVerification(String destination, String verificationCode) throws IOException {
|
|
||||||
+ logger.info("Pretending to send voice verification to " + destination + ": " + verificationCode);
|
|
||||||
voxMeter.mark();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- private String getRandom(Random random, ArrayList<String> elements) {
|
- try {
|
||||||
- return elements.get(random.nextInt(elements.size()));
|
- twilioSender.deliverSmsVerification(destination, clientType, verificationCode);
|
||||||
|
- } catch (TwilioRestException e) {
|
||||||
|
- logger.info("Twilio SMS Failed: " + e.getErrorMessage());
|
||||||
- }
|
- }
|
||||||
-
|
+ logger.info("Sending SMS verification code to " + destination + ": " + destination);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deliverVoxVerification(String destination, String verificationCode)
|
||||||
|
throws IOException
|
||||||
|
{
|
||||||
|
- try {
|
||||||
|
- twilioSender.deliverVoxVerification(destination, verificationCode);
|
||||||
|
- } catch (TwilioRestException e) {
|
||||||
|
- logger.info("Twilio Vox Failed: " + e.getErrorMessage());
|
||||||
|
- }
|
||||||
|
+ logger.info("Sending voice verification code to " + destination + ": " + verificationCode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue