public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { String ACCOUNT_SID = request.getParameter("twilioAccSID"); String AUTH_TOKEN = request.getParameter("twilioAuthToken"); String smsTo = request.getParameter("smsTo"); String smsFrom = request.getParameter("smsFrom"); String smsText = request.getParameter("smsText"); try { TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN); Account account = client.getAccount(); SmsFactory smsFactory = account.getSmsFactory(); Map<String, String> smsParams = new HashMap<String, String>(); smsParams.put("To", smsTo); smsParams.put("From", smsFrom); smsParams.put("Body", smsText); Sms sms = smsFactory.create(smsParams); response.getWriter().print("<h2>SMS sent successfully!</h2>\n\nStatus: " + sms.getStatus()); } catch (Exception e) { response .getWriter() .print("<h2>Error occurred while sending SMS!</h2>\n\nError: " + e.getMessage()); } }
public void sendCoins() { Sms sms = null; String messageBody = "Hi " + getRecipient() + "!! You have received " + getAmount() + " coins.. http://bluecoin-poc.mybluemix.net"; LOGGER.info("Sending " + messageBody); TwilioRestClient client = new TwilioRestClient(accountSID, authToken); // Build a filter for the SmsList Map<String, String> params = new HashMap<String, String>(); // Update with your Twilio number params.put("From", "+61439767507"); params.put("Body", messageBody); params.put("To", "+61430321919"); SmsFactory messageFactory = client.getAccount().getSmsFactory(); try { sms = messageFactory.create(params); AppUser user = getUserSvc().getById(getRecipient()); AppUser sender = getUserSvc().getById(getLoginForm().getUserName()); Team team = getTeamSvc().getById("EnergyAustralia"); user.setTeam(team); UserReward reward = new UserReward(); reward.setRewardDate(new Date()); reward.setRecepient(user); reward.setSender(sender); reward.setRewardAmount(Integer.parseInt(getAmount())); reward.setRewardMessage(getMessage()); reward.setTeam(team); getUserRewardSvc().create(reward); } catch (Exception e) { e.printStackTrace(); LOGGER.error(e.getMessage()); } LOGGER.info("Sent message id: " + sms.getSid()); }
private void send( final TwilioRestClient client, final Stream stream, final AlertCondition.CheckResult result) throws TwilioRestException { final Account mainAccount = client.getAccount(); final SmsFactory smsFactory = mainAccount.getSmsFactory(); final Map<String, String> smsParams = ImmutableMap.of( "To", configuration.getString(CK_TO_NUMBER), "From", configuration.getString(CK_FROM_NUMBER), "Body", buildMessage(result, stream)); final Sms sms = smsFactory.create(smsParams); LOG.debug("Sent SMS with status {}: {}", sms.getStatus(), sms.getBody()); }