app/features/sms/twilio/TwilioSmsServiceImpl.java
/**
     * Sends a MMS message with Media URLs to the provided phoneNumber via Twilio.
     *
     * @param phoneNumber Phone number String with no special characters
     * @param messageBody SMS message String between 1-140 characters
     * @param mediaUrls   Collection of up to 10 mediaUrls to be included in the MMS
     */
Sends a MMS message with Media URLs to the provided phoneNumber via Twilio.
@param phoneNumber Phone number String with no special characters
@param messageBody SMS message String between 1-140 characters
@param mediaUrls   Collection of up to 10 mediaUrls to be included in the MMS
Sends a MMS message with Media URLs to the provided phoneNumber via Twilio . @param phoneNumber Phone number String with no special characters @param messageBody SMS message String between 1 - 140 characters @param mediaUrls Collection of up to 10 mediaUrls to be included in the MMS
public void sendMmsMessage(String phoneNumber, String messageBody, List<String> mediaUrls)
            throws SmsMessagingException {
        if (messageBody.length() > 140 || messageBody.length() == 0) {
            throw new SmsMessagingException(
                    new IllegalArgumentException("The provided messageBody needs to be between 1-140 characters."));
        }
        if(mediaUrls.size()>10) {
            throw new SmsMessagingException("You can only have 1-10 media URLs included on a MMS message");
        }
        try {
            List<NameValuePair> params = new ArrayList<>();
            params.add(new BasicNameValuePair("To",
                    PhoneNumberValidator.convertToMinimizedPhoneNumber(phoneNumber,
                            PhoneNumberValidator.PhoneNumberRegion.NORTH_AMERICA)));
            params.add(new BasicNameValuePair("From", mmsPhoneNumber));
            params.add(new BasicNameValuePair("Body", messageBody));
            mediaUrls.forEach((mediaUrl) -> params.add(new BasicNameValuePair("MediaUrl", mediaUrl)));
            MessageFactory messageFactory = client.getAccount().getMessageFactory();
            Message message = messageFactory.create(params);
        } catch (TwilioRestException e) {
            LOGGER.error("Could not send MMS Text Message to " + phoneNumber, e);
            throw new SmsMessagingException("Could not send MMS Text Message to " + phoneNumber);
        } catch (PhoneNumberException e) {
            LOGGER.error("Could not send MMS Text Message to " + phoneNumber, e);
            throw new SmsMessagingException(e.getMessage(), e);
        }
    }
public void sendMmsMessage ( String phoneNumber , String messageBody , List < String > mediaUrls ) throws SmsMessagingException { if ( messageBody . length ( ) > 140 || messageBody . length ( ) == 0 ) { throw new SmsMessagingException ( new IllegalArgumentException ( "The provided messageBody needs to be between 1-140 characters." ) ) ; } if ( mediaUrls . size ( ) > 10 ) { throw new SmsMessagingException ( "You can only have 1-10 media URLs included on a MMS message" ) ; } try { List < NameValuePair > params = new ArrayList < > ( ) ; params . add ( new BasicNameValuePair ( "To" , PhoneNumberValidator . convertToMinimizedPhoneNumber ( phoneNumber , PhoneNumberValidator . PhoneNumberRegion . NORTH_AMERICA ) ) ) ; params . add ( new BasicNameValuePair ( "From" , mmsPhoneNumber ) ) ; params . add ( new BasicNameValuePair ( "Body" , messageBody ) ) ; mediaUrls . forEach ( ( mediaUrl ) -> params . add ( new BasicNameValuePair ( "MediaUrl" , mediaUrl ) ) ) ; MessageFactory messageFactory = client . getAccount ( ) . getMessageFactory ( ) ; Message message = messageFactory . create ( params ) ; } catch ( TwilioRestException e ) { LOGGER . error ( "Could not send MMS Text Message to " + phoneNumber , e ) ; throw new SmsMessagingException ( "Could not send MMS Text Message to " + phoneNumber ) ; } catch ( PhoneNumberException e ) { LOGGER . error ( "Could not send MMS Text Message to " + phoneNumber , e ) ; throw new SmsMessagingException ( e . getMessage ( ) , e ) ; } }
Sends a MMS message with Media URLs to the provided phoneNumber via Twilio.
Sends a MMS message with Media URLs to the provided phoneNumber via Twilio .
// Build the parameters