Guest User

Untitled

a guest
Jun 29th, 2021
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. public static String getSmsTwilio(String phoneNumberTo) throws InterruptedException {
  2. String sms = null;
  3. Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
  4. ResourceSet<Message> messages = Message.reader()
  5. .setFrom(new com.twilio.type.PhoneNumber("+447480781485"))
  6. .setTo(new com.twilio.type.PhoneNumber(phoneNumberTo))
  7. .limit(1)
  8. .read();
  9. for (Message record : messages) {
  10. sms = record.getBody().replaceAll("\\D+", "");
  11. }
  12. if (sms != null) {
  13. logger.info("SMS received.");
  14. } else {
  15. logger.info("SMS could not be received.");
  16. waitSmsCode(phoneNumberTo);
  17. }
  18. System.out.println(sms);
  19. return sms;
  20. }
  21.  
  22. public static boolean waitSmsCode(String phoneNumberTo) {
  23. try {
  24. Awaitility.await("Ожидаем sms ")
  25. .pollInterval(5000, TimeUnit.MILLISECONDS)
  26. .atMost(180000, TimeUnit.MILLISECONDS)
  27. .until(() -> getSmsTwilio(phoneNumberTo) != null);
  28. } catch (ConditionTimeoutException e) {
  29. logger.error(e.getMessage());
  30. return false;
  31. }
  32. return true;
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment