本文整理汇总了Java中com.twilio.sdk.resource.factory.MessageFactory类的典型用法代码示例。如果您正苦于以下问题:Java MessageFactory类的具体用法?Java MessageFactory怎么用?Java MessageFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MessageFactory类属于com.twilio.sdk.resource.factory包,在下文中一共展示了MessageFactory类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: service
import com.twilio.sdk.resource.factory.MessageFactory; //导入依赖的package包/类
@Override
public void service(HttpServletRequest req, HttpServletResponse resp) throws IOException,
ServletException {
final String twilioAccountSid = System.getenv("TWILIO_ACCOUNT_SID");
final String twilioAuthToken = System.getenv("TWILIO_AUTH_TOKEN");
final String twilioNumber = System.getenv("TWILIO_NUMBER");
final String toNumber = (String) req.getParameter("to");
if (toNumber == null) {
resp.getWriter()
.print("Please provide the number to message in the \"to\" query string parameter.");
return;
}
TwilioRestClient client = new TwilioRestClient(twilioAccountSid, twilioAuthToken);
Account account = client.getAccount();
MessageFactory messageFactory = account.getMessageFactory();
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("To", toNumber));
params.add(new BasicNameValuePair("From", twilioNumber));
params.add(new BasicNameValuePair("Body", "Hello from Twilio!"));
try {
Message sms = messageFactory.create(params);
resp.getWriter().print(sms.getBody());
} catch (TwilioRestException e) {
throw new ServletException("Twilio error", e);
}
}
示例2: sendClientText
import com.twilio.sdk.resource.factory.MessageFactory; //导入依赖的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;
}
示例3: sendSMS
import com.twilio.sdk.resource.factory.MessageFactory; //导入依赖的package包/类
/**
* Sends a twilio SMS
* @param toPhone
* @param text
* @return
* @throws TwilioRestException
*/
public Message sendSMS(final Phone toPhone,
final String text) throws TwilioRestException {
Preconditions.checkArgument(toPhone != null,"The destination phone must NOT be null!");
Preconditions.checkArgument(text != null,"A text is needed for the sms message!");
Preconditions.checkState(_apiData.existsAccountData() && _apiData.canSendMessages(),"The API is NOT configured properly to send messages");
TwilioRestClient client = new TwilioRestClient(_apiData.getAccountSID().asString(),
_apiData.getAccountToken().asString());
// Build a filter for the MessageList
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("Body",text));
params.add(new BasicNameValuePair("To",toPhone.asString()));
params.add(new BasicNameValuePair("From",_apiData.getMessagingPhone().asString()));
MessageFactory messageFactory = client.getAccount().getMessageFactory();
Message message = messageFactory.create(params);
log.info("SMS Message sent with id={}",message.getSid());
return message;
}
示例4: service
import com.twilio.sdk.resource.factory.MessageFactory; //导入依赖的package包/类
@Override
public void service(HttpServletRequest req, HttpServletResponse resp)
throws IOException, ServletException {
final String twilioAccountSid = System.getenv("TWILIO_ACCOUNT_SID");
final String twilioAuthToken = System.getenv("TWILIO_AUTH_TOKEN");
final String twilioNumber = System.getenv("TWILIO_NUMBER");
final String toNumber = (String) req.getParameter("to");
if (toNumber == null) {
resp.getWriter()
.print("Please provide the number to message in the \"to\" query string parameter.");
return;
}
TwilioRestClient client = new TwilioRestClient(twilioAccountSid, twilioAuthToken);
Account account = client.getAccount();
MessageFactory messageFactory = account.getMessageFactory();
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("To", toNumber));
params.add(new BasicNameValuePair("From", twilioNumber));
params.add(new BasicNameValuePair("Body", "Hello from Twilio!"));
try {
Message sms = messageFactory.create(params);
resp.getWriter().print(sms.getBody());
} catch (TwilioRestException e) {
throw new ServletException("Twilio error", e);
}
}
示例5: sendText
import com.twilio.sdk.resource.factory.MessageFactory; //导入依赖的package包/类
public static boolean sendText(String toPhone, String fromPhone, String body)
{
boolean sentText = true;
String twilio_acct_id = System.getenv("TWILIO_ACCOUNT_SID");
String twilio_auth_token = System.getenv("TWILIO_AUTH_TOKEN");
try {
TwilioRestClient client = new TwilioRestClient(twilio_acct_id, twilio_auth_token);
// Build a filter for the MessageList
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("Body", body));
params.add(new BasicNameValuePair("To", "+1" + toPhone));
params.add(new BasicNameValuePair("From", "+1" + fromPhone));
MessageFactory messageFactory = client.getAccount().getMessageFactory();
Message message = messageFactory.create(params);
sentText = true;
} catch (TwilioRestException e) {
System.out.println(e.getMessage());
}
return sentText;
}
示例6: sendMessage
import com.twilio.sdk.resource.factory.MessageFactory; //导入依赖的package包/类
public void sendMessage(String toNumber, String messageText){
TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);
// Build a filter for the MessageList
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("Body", messageText));
params.add(new BasicNameValuePair("To", toNumber));
params.add(new BasicNameValuePair("From", FROMNUMBER));
MessageFactory messageFactory = client.getAccount().getMessageFactory();
Message message;
try {
message = messageFactory.create(params);
System.out.println(message.getSid());
} catch (TwilioRestException e) {
e.printStackTrace();
}
}
示例7: sendSMS
import com.twilio.sdk.resource.factory.MessageFactory; //导入依赖的package包/类
public SMSLogVO sendSMS(String countryCallingCode, String mobileNumber,
String msg) throws SMSSendException {
String msisdn = countryCallingCode + mobileNumber;
if (!msisdn.startsWith("+")) {
msisdn = "+" + msisdn;
}
myLog.debug("Sending SMS via Twilio from: " + twilioNumber +" to: " + msisdn + ", msg:" + msg);
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("Body", msg));
params.add(new BasicNameValuePair("To", msisdn));
params.add(new BasicNameValuePair("From", twilioNumber));
SMSLogVO smsLogVO = new SMSLogVO();
smsLogVO.setGwName(TWILIO_GATEWAY_NAME);
smsLogVO.setMobileNo(msisdn);
smsLogVO.setMessage(msg);
smsLogVO.setSendTime(new Date());
try {
MessageFactory messageFactory = client.getAccount().getMessageFactory();
Message message = messageFactory.create(params);
smsLogVO.setTransactionId(message.getSid());
smsLogVO.setStatus(message.getStatus());
smsLogVO.setSendOut(true);
} catch (TwilioRestException ex) {
myLog.error("Problem on sending SMS via Twilio to: " + countryCallingCode + "-" + mobileNumber +
" error: " + ex.getMessage() + ", code: " + ex.getErrorCode() + ", additional info: " + ex.getMoreInfo(), ex);
smsLogVO.setErrorMessage(ex.getErrorMessage());
smsLogVO.setStatus("failed");
smsLogVO.setSendOut(false);
}
return smsLogVO;
}
示例8: main
import com.twilio.sdk.resource.factory.MessageFactory; //导入依赖的package包/类
public static void main(String[] args) throws TwilioRestException {
TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);
// Build a filter for the MessageList
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("Body", "Let's grab lunch at Milliways tomorrow!"));
params.add(new BasicNameValuePair("To", "+15558675310"));
params.add(new BasicNameValuePair("From", "+14158141829"));
params.add(new BasicNameValuePair("MediaUrl", "http://www.example.com/cheeseburger.png"));
MessageFactory messageFactory = client.getAccount().getMessageFactory();
Message message = messageFactory.create(params);
System.out.println(message.getSid());
}
示例9: main
import com.twilio.sdk.resource.factory.MessageFactory; //导入依赖的package包/类
public static void main(String[] args) throws TwilioRestException {
TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);
// Build a filter for the SmsList
List<NameValuePair> params = new ArrayList<>();
params.add(new BasicNameValuePair("Body", "Hey Mr Nugget, you the bomb!"));
params.add(new BasicNameValuePair("To", "+15005550009"));
params.add(new BasicNameValuePair("From", "+15005550006"));
MessageFactory messageFactory = client.getAccount().getMessageFactory();
Message message = messageFactory.create(params);
System.out.println(message.getSid());
}
示例10: main
import com.twilio.sdk.resource.factory.MessageFactory; //导入依赖的package包/类
public static void main(String[] args) throws TwilioRestException {
TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);
// Build a filter for search
List<NameValuePair> params = new ArrayList<>();
params.add(new BasicNameValuePair("Body", "All in the game, yo"));
params.add(new BasicNameValuePair("To", "+14108675310"));
params.add(new BasicNameValuePair("From", "+15005550006"));
MessageFactory messageFactory = client.getAccount().getMessageFactory();
Message message = messageFactory.create(params);
System.out.println(message.getSid());
}
示例11: main
import com.twilio.sdk.resource.factory.MessageFactory; //导入依赖的package包/类
public static void main(String[] args) throws TwilioRestException {
TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);
// Build a filter for the SmsList
List<NameValuePair> params = new ArrayList<>();
params.add(new BasicNameValuePair("To", "+14108675310"));
params.add(new BasicNameValuePair("From", "+15005550006"));
MessageFactory messageFactory = client.getAccount().getMessageFactory();
Message message = messageFactory.create(params);
System.out.println(message.getSid());
}
示例12: sendSms
import com.twilio.sdk.resource.factory.MessageFactory; //导入依赖的package包/类
public static Message sendSms(final String phoneNumber, final String smsMessage)
throws NumberParseException, IllegalArgumentException, TwilioRestException {
checkPhoneNumber(phoneNumber);
checkSmsMessage(smsMessage);
final String accountSid = ApiKeysUtils.getApiKey("twilioAccountSid");
final String authToken = ApiKeysUtils.getApiKey("twilioAuthToken");
final String twilioPhoneNumber = ApiKeysUtils.getApiKey("twilioPhoneNumber");
// Twilio.init(accountSid, authToken);
// Message message = Message.creator(
// new PhoneNumber(phoneNumber), // To number
// new PhoneNumber(twilioPhoneNumber), // From number
// smsMessage // SMS body
// ).create();
// LOG.warning(message.toString());
TwilioRestClient client = new TwilioRestClient(accountSid, authToken);
Account account = client.getAccount();
MessageFactory messageFactory = account.getMessageFactory();
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("To", phoneNumber));
params.add(new BasicNameValuePair("From", twilioPhoneNumber));
params.add(new BasicNameValuePair("Body", smsMessage));
Message sms = messageFactory.create(params);
LOG.warning(sms.toString());
return sms;
}
示例13: sendMessage
import com.twilio.sdk.resource.factory.MessageFactory; //导入依赖的package包/类
public static void sendMessage(String toNumber, String body) throws TwilioRestException {
List<org.apache.http.NameValuePair> params = new ArrayList<org.apache.http.NameValuePair>();
params.add(new BasicNameValuePair("Body", body));
params.add(new BasicNameValuePair("To", toNumber));
params.add(new BasicNameValuePair("From", SMS_CENTER));
MessageFactory messageFactory = client.getAccount().getMessageFactory();
Message message = messageFactory.create(params);
System.out.println(message.getSid());
}
示例14: sendText
import com.twilio.sdk.resource.factory.MessageFactory; //导入依赖的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;
}