本文整理汇总了Java中com.twilio.sdk.resource.instance.Message.getErrorCode方法的典型用法代码示例。如果您正苦于以下问题:Java Message.getErrorCode方法的具体用法?Java Message.getErrorCode怎么用?Java Message.getErrorCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.twilio.sdk.resource.instance.Message
的用法示例。
在下文中一共展示了Message.getErrorCode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendClientText
import com.twilio.sdk.resource.instance.Message; //导入方法依赖的package包/类
public static boolean sendClientText(String recipient, String from, String message) throws TwilioRestException, InterruptedException {
if (recipient != null && message != null && from != null && !from.isEmpty() && !recipient.isEmpty() && !message.isEmpty()) {
TwilioRestClient client = new TwilioRestClient(accountSID, authToken);
recipient = recipient.contains("+1") ? recipient : "+1" + recipient;
from = from.contains("+1") ? from : "+1" + from;
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("Body", message));
params.add(new BasicNameValuePair("To", recipient));
params.add(new BasicNameValuePair("From", from));
MessageFactory messageFactory = client.getAccount().getMessageFactory();
Message text = messageFactory.create(params);
if (text.getErrorCode() != null) {
return false;
}
return true;
}
return false;
}
示例2: sendText
import com.twilio.sdk.resource.instance.Message; //导入方法依赖的package包/类
public static boolean sendText(String number, String email, String password, String name, String type) throws TwilioRestException, InterruptedException {
if (number != null && number.length() == 10) {
TwilioRestClient client = new TwilioRestClient(accountSID, authToken);
if (email.length() < 6) {
email = number;
}
String welcomeBody = "Hi " + name
+ ", it's Laura from WorkAmerica. Your job seeker profile has been created, employers can now contact you with available job opportunities! "
+ "Your login is " + email + " and password is " + password + ". Log in to update your profile at www.workamerica.co/login or contact us at [email protected] with any issues";
String forgotBody = "Hi " + name
+ ", Your new password is " + password + " . Login at www.workamerica.co/login to update your profile!";
// Build a filter for the MessageList
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("To", number));
params.add(new BasicNameValuePair("From", "+1NUMBER_HERE"));
params.add(new BasicNameValuePair("MessagingServiceSid", welcomeMessageSid));
if (type != null && type.equalsIgnoreCase("forgot")) {
params.add(new BasicNameValuePair("Body", forgotBody));
} else {
params.add(new BasicNameValuePair("Body", welcomeBody));
}
MessageFactory messageFactory = client.getAccount().getMessageFactory();
try {
Message response = messageFactory.create(params);
if (response.getErrorCode() == null) {
return true;
}
} catch (TwilioRestException e) {
e.printStackTrace();
try {
String simpleNumber = CustomUtilities.cleanNumber(number.substring(2));
Candidates candidate = CandidatePersistence.getCandidateByPhone(simpleNumber);
if (candidate != null) {
TwilioWelcomeEvents event = new TwilioWelcomeEvents();
TwilioWelcome twilioWelcome = new TwilioWelcome();
APILogs apiLogs = candidate.getApiLogs();
if (apiLogs != null) {
twilioWelcome.setPhone(simpleNumber);
twilioWelcome.setBody(welcomeBody);
twilioWelcome.setMessageID("");
twilioWelcome.setSuccess("False");
event.setTime(Clock.getCurrentTime());
event.setDate(Clock.getCurrentDate());
event.setStatus("Failed");
event.setError("Exception");
twilioWelcome.addToTwilioWelcomeEvents(event);
apiLogs.addToTwilioWelcome(twilioWelcome);
candidate.setApiLogs(apiLogs);
CandidatePersistence.merge(candidate);
}
}
} catch (Exception f) {
e.printStackTrace();
}
}
}
return false;
}