Skip to content
Snippets Groups Projects
Commit 37b4cbe3 authored by Daniel Gultsch's avatar Daniel Gultsch
Browse files

use phone number from config file as sender for nexmo

parent e3946202
Branches
No related merge requests found
* Create Adhoc-Commands method to look up single phone number
* Allow users in the directory to loop up others
* Allow users in the directory to look up others
* Allow multiple entries (phone numbers) per Jabber ID
* Generalize look up method and allow email addresses (and potentially all sort of uris) to be stored in the directory
* XEPify look up method
......
......@@ -46,6 +46,8 @@ public class Configuration {
private String twilioAuthToken;
private String nexmoApiKey;
private String nexmoPhoneNumber;
private String nexmoApiSecret;
private String cimAuthToken;
private Version minVersion;
......@@ -145,6 +147,10 @@ public class Configuration {
return nexmoApiSecret;
}
public String getNexmoPhoneNumber() {
return nexmoPhoneNumber;
}
public Optional<String> getCimAuthToken() {
return Optional.ofNullable(cimAuthToken);
}
......
......@@ -10,13 +10,13 @@ import com.google.i18n.phonenumbers.Phonenumber;
import im.quicksy.server.configuration.Configuration;
import im.quicksy.server.verification.nexmo.GenericResponse;
import okhttp3.*;
import okhttp3.logging.HttpLoggingInterceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.security.SecureRandom;
import java.time.Duration;
import java.util.Arrays;
import java.util.List;
public class NexmoVerificationProvider implements VerificationProvider {
......@@ -34,6 +34,10 @@ public class NexmoVerificationProvider implements VerificationProvider {
private static final String BRAND_NAME = "Quicksy.im";
private static final String MESSAGE = "Your Quicksy code is: %s\n\nDon't share this code with others.\n\nOYITl6r6eIp";
private static final List<Integer> COUNTRY_CODES_SUPPORTING_ALPHA_NUMERIC = Arrays.asList(
49
);
private static final int MAX_ATTEMPTS = 3;
private static final SecureRandom SECURE_RANDOM = new SecureRandom();
private final Cache<Phonenumber.PhoneNumber, Pin> PIN_CACHE = CacheBuilder.newBuilder()
......@@ -59,10 +63,17 @@ public class NexmoVerificationProvider implements VerificationProvider {
PIN_CACHE.put(phoneNumber, pin);
System.out.println("pin: " + pin);
final String to = String.format("%d%d", phoneNumber.getCountryCode(), phoneNumber.getNationalNumber());
final String nexmoPhoneNumber = Configuration.getInstance().getNexmoPhoneNumber();
final String from;
if (Strings.isNullOrEmpty(nexmoPhoneNumber) || COUNTRY_CODES_SUPPORTING_ALPHA_NUMERIC.contains(phoneNumber.getCountryCode())) {
from = BRAND_NAME;
} else {
from = nexmoPhoneNumber;
}
LOGGER.info("requesting SMS through nexmo for {}", to);
final Call call = OK_HTTP_CLIENT.newCall(new Request.Builder()
.post(new FormBody.Builder()
.add("from", BRAND_NAME)
.add("from", from)
.add("text", String.format(MESSAGE, pin.toString()))
.add("to", to)
.add("api_key", Configuration.getInstance().getNexmoApiKey())
......@@ -87,7 +98,7 @@ public class NexmoVerificationProvider implements VerificationProvider {
final GenericResponse.Message message = messages.get(0);
final String status = message.getStatus();
if (!"0".equals(status)) {
LOGGER.error("Unable to requests SMS. Status={} text={}",message.getStatus(), message.getErrorText());
LOGGER.error("Unable to requests SMS. Status={} text={}", message.getStatus(), message.getErrorText());
throw new RequestFailedException(message.getErrorText());
}
} else {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment