Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static String getSmsTwilio(String phoneNumberTo) throws InterruptedException {
- String sms = null;
- Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
- ResourceSet<Message> messages = Message.reader()
- .setFrom(new com.twilio.type.PhoneNumber("+447480781485"))
- .setTo(new com.twilio.type.PhoneNumber(phoneNumberTo))
- .limit(1)
- .read();
- for (Message record : messages) {
- sms = record.getBody().replaceAll("\\D+", "");
- }
- if (sms != null) {
- logger.info("SMS received.");
- } else {
- logger.info("SMS could not be received.");
- waitSmsCode(phoneNumberTo);
- }
- System.out.println(sms);
- return sms;
- }
- public static boolean waitSmsCode(String phoneNumberTo) {
- try {
- Awaitility.await("Ожидаем sms ")
- .pollInterval(5000, TimeUnit.MILLISECONDS)
- .atMost(180000, TimeUnit.MILLISECONDS)
- .until(() -> getSmsTwilio(phoneNumberTo) != null);
- } catch (ConditionTimeoutException e) {
- logger.error(e.getMessage());
- return false;
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment