Esempio n. 1
0
    public static void main(String[] args) {

        port(Integer.valueOf(System.getenv("PORT")));

        get("/", (request, response) -> {

            // Create a rest client
            TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

            // Get the main account (The one we used to authenticate the client)
            Account mainAccount = client.getAccount();

            // Get all accounts including sub accounts
            AccountList accountList = client.getAccounts();

            // All lists implement an iterable interface, you can use the foreach
            // syntax on them
            for (Account a : accountList) {
                System.out.println(a.getFriendlyName());
            }

            // Send an sms (using the new messages endpoint)
            MessageFactory messageFactory = mainAccount.getMessageFactory();
            List<NameValuePair> messageParams = new ArrayList<NameValuePair>();
            messageParams.add(new BasicNameValuePair("To", "+19172164313; // Replace with a valid phone number
            messageParams.add(new BasicNameValuePair("From", "+19142054512")); // Replace with a valid phone
            // number in your account
            messageParams.add(new BasicNameValuePair("Body", "Hello from Fabian Patino"));
            messageFactory.create(messageParams);

            return "Hello From Fabian Patino";
        });
  public String execute(Map<String, String> map) throws TwilioRestException {
    List<NameValuePair> params = new ArrayList<NameValuePair>(map.keySet().size());

    Set<String> keys = map.keySet();
    for (String key : keys) {
      params.add(new BasicNameValuePair(key, map.get(key)));
    }

    MessageFactory messageFactory = getAccount().getMessageFactory();
    Message message = messageFactory.create(params);
    return message.getSid();
  }
Esempio n. 3
0
  private void sendVerNumber(String phone, String verNumber) throws TwilioRestException {
    TwilioRestClient client =
        new TwilioRestClient(Constants.TWILLIO_ACCOUNT_SID, Constants.TWILLIO_AUTH_TOKEN);

    // Build the parameters
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("To", phone));
    params.add(new BasicNameValuePair("From", "+16147636291"));
    params.add(new BasicNameValuePair("Body", "달샵 가입자 확인번호 : " + verNumber));

    MessageFactory messageFactory = client.getAccount().getMessageFactory();
    Message message = messageFactory.create(params);
    log.warning("sent phone verification number, sid: " + message.getSid());
  }
Esempio n. 4
0
  public static void send(String phone, String text) {

    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", text));
    boolean to = params.add(new BasicNameValuePair("To", "+" + phone));
    params.add(new BasicNameValuePair("From", "+17075496112"));

    MessageFactory messageFactory = client.getAccount().getMessageFactory();
    Message message = null;
    try {
      message = messageFactory.create(params);
    } catch (TwilioRestException e) {
      e.printStackTrace();
    }
    System.out.println(message.getSid());
  }
  /**
   * This method can send SMS.
   *
   * @param msg The message to be sent via sms
   * @param listPhonenum The destinations phone number
   * @return the boolean indicating whether the operation is successful or not.
   */
  public boolean SendSMS(String msg, List<String> ListPhonenum) {
    try {
      TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

      for (int i = 0; i < ListPhonenum.size(); i++) {
        String PhoneNumber = ListPhonenum.get(i);
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("Body", msg));
        params.add(new BasicNameValuePair("To", "+" + PhoneNumber));
        params.add(new BasicNameValuePair("From", "+14842407107"));
        MessageFactory messageFactory = client.getAccount().getMessageFactory();
        Message message = messageFactory.create(params);
        // System.out.println(message.getSid());
      }
      return true;
    } catch (Exception e) {
      return false;
    }
  }
  @PUT
  @Path("{title}/{body}/{isDone}")
  @Produces(value = "text/plain")
  @Consumes(MediaType.TEXT_PLAIN)
  public Response toggleStatusListItem(
      @PathParam("title") String title,
      @PathParam("body") String body,
      @PathParam("isDone") boolean isDone) {
    // Find your Account Sid and Token at twilio.com/user/account
    ListItem item = new ListItem(title, body, isDone);
    boolean done = isDone ? false : true;
    int index = list.indexOf(item);
    item.setDone(done);
    list.remove(index);
    list.add(index, item);

    if (isDone == Boolean.FALSE) {

      String ACCOUNT_SID = "AC96d0a9024203de2a4177624c789fad17";
      String AUTH_TOKEN = "919a89967cc484a35a1a0cfd0555dd57";

      TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);
      try {
        // Build a filter for the MessageList
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("Body", "Task : " + body + "is complete."));
        params.add(new BasicNameValuePair("To", "+14086270378"));
        params.add(new BasicNameValuePair("From", "+18316847487"));

        MessageFactory messageFactory = client.getAccount().getMessageFactory();
        Message message = messageFactory.create(params);
        System.out.println(message.getSid());
        return Response.status(200).entity(body.toString()).build();
      } catch (TwilioRestException e) {
        System.out.println(e.getErrorMessage());
      }
    }
    return Response.status(500).entity(body.toString()).build();
  }
Esempio n. 7
0
  @Override
  public void sendSms(SmsDto smsDto) {

    try {

      TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

      Account account = client.getAccount();

      MessageFactory messageFactory = account.getMessageFactory();
      List<NameValuePair> params = new ArrayList<NameValuePair>();
      params.add(new BasicNameValuePair("To", smsDto.getTo()));
      params.add(new BasicNameValuePair("From", FROM_PHONE));
      params.add(new BasicNameValuePair("Body", SMS_BODY));
      Message sms = messageFactory.create(params);

      log.debug("Sent SMS: " + sms.getBody() + "to: " + sms.getTo());

    } catch (TwilioRestException ex) {
      log.debug(ex.toString());
    }
  }