Search in sources :

Example 1 with PhoneNumber

use of com.twilio.type.PhoneNumber in project api-snippets by TwilioDevEd.

the class MmsSender method main.

public static void main(String[] args) throws URISyntaxException {
    Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
    String uri = "https://static0.twilio.com/recources/logos/twilio-loco-circle-50x50.png";
    Message message = Message.creator(// to
    new PhoneNumber("+14159352345"), // from
    new PhoneNumber("+14158141829"), "Where's Wallace?").setMediaUrl(new URI(uri)).create();
}
Also used : Message(com.twilio.rest.api.v2010.account.Message) PhoneNumber(com.twilio.type.PhoneNumber) URI(java.net.URI)

Example 2 with PhoneNumber

use of com.twilio.type.PhoneNumber in project api-snippets by TwilioDevEd.

the class SmsSender method main.

public static void main(String[] args) {
    Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
    Message message = Message.creator(// to
    new PhoneNumber("+14159352345"), // from
    new PhoneNumber("+14158141829"), "Where's Wallace?").create();
    System.out.println(message.getSid());
}
Also used : Message(com.twilio.rest.api.v2010.account.Message) PhoneNumber(com.twilio.type.PhoneNumber)

Example 3 with PhoneNumber

use of com.twilio.type.PhoneNumber in project mxisd by kamax-io.

the class PhoneSmsTwilioConnector method send.

@Override
public void send(String recipient, String content) {
    if (StringUtils.isBlank(cfg.getAccountSid()) || StringUtils.isBlank(cfg.getAuthToken()) || StringUtils.isBlank(cfg.getNumber())) {
        log.error("Twilio connector in not fully configured and is missing mandatory configuration values.");
        throw new NotImplementedException("Phone numbers cannot be validated at this time. Contact your administrator.");
    }
    recipient = "+" + recipient;
    log.info("Sending SMS notification from {} to {} with {} characters", cfg.getNumber(), recipient, content.length());
    try {
        Message.creator(new PhoneNumber("+" + recipient), new PhoneNumber(cfg.getNumber()), content).create();
    } catch (ApiException e) {
        throw new InternalServerError(e);
    }
}
Also used : NotImplementedException(io.kamax.mxisd.exception.NotImplementedException) PhoneNumber(com.twilio.type.PhoneNumber) InternalServerError(io.kamax.mxisd.exception.InternalServerError) ApiException(com.twilio.exception.ApiException)

Example 4 with PhoneNumber

use of com.twilio.type.PhoneNumber in project api-snippets by TwilioDevEd.

the class MakePhoneCall method main.

public static void main(String[] args) throws URISyntaxException {
    Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
    String from = "+15017122661";
    String to = "+14155551212";
    Call call = Call.creator(new PhoneNumber(to), new PhoneNumber(from), new URI("http://demo.twilio.com/docs/voice.xml")).create();
    System.out.println(call.getSid());
}
Also used : Call(com.twilio.rest.api.v2010.account.Call) PhoneNumber(com.twilio.type.PhoneNumber) URI(java.net.URI)

Example 5 with PhoneNumber

use of com.twilio.type.PhoneNumber in project thingsboard by thingsboard.

the class TwilioSmsSender method sendSms.

@Override
public int sendSms(String numberTo, String message) throws SmsException {
    numberTo = this.validatePhoneNumber(numberTo);
    message = this.prepareMessage(message);
    try {
        String numSegments = Message.creator(new PhoneNumber(numberTo), new PhoneNumber(this.numberFrom), message).create(this.twilioRestClient).getNumSegments();
        return Integer.valueOf(numSegments);
    } catch (Exception e) {
        throw new SmsSendException("Failed to send SMS message - " + e.getMessage(), e);
    }
}
Also used : PhoneNumber(com.twilio.type.PhoneNumber) SmsParseException(org.thingsboard.rule.engine.api.sms.exception.SmsParseException) SmsSendException(org.thingsboard.rule.engine.api.sms.exception.SmsSendException) SmsException(org.thingsboard.rule.engine.api.sms.exception.SmsException) SmsSendException(org.thingsboard.rule.engine.api.sms.exception.SmsSendException)

Aggregations

PhoneNumber (com.twilio.type.PhoneNumber)5 Message (com.twilio.rest.api.v2010.account.Message)2 URI (java.net.URI)2 ApiException (com.twilio.exception.ApiException)1 Call (com.twilio.rest.api.v2010.account.Call)1 InternalServerError (io.kamax.mxisd.exception.InternalServerError)1 NotImplementedException (io.kamax.mxisd.exception.NotImplementedException)1 SmsException (org.thingsboard.rule.engine.api.sms.exception.SmsException)1 SmsParseException (org.thingsboard.rule.engine.api.sms.exception.SmsParseException)1 SmsSendException (org.thingsboard.rule.engine.api.sms.exception.SmsSendException)1