Ejemplo n.º 1
0
  /**
   * Method that starts conversation with the caller
   *
   * @return {@link TwiMLResponse} sent over the call
   */
  public static TwiMLResponse getCallStarter(Caller caller) {
    Logger.info("Preparing Greeting message and url.");
    TwiMLResponse twiml = new TwiMLResponse();
    Say say = new Say(TwilioConstants.GREETING);
    say.setVoice(TwilioConstants.FEMALE_USER);

    Gather gather = new Gather();
    gather.setAction(
        "/handle-key/"
            + caller.getDays()
            + "/"
            + caller.getHours()
            + "/"
            + caller.getMinutes()
            + "/"
            + caller.getSeconds()
            + "/");
    gather.setMethod("GET");
    gather.setFinishOnKey("#");
    Say sayInGather = new Say("Please Press a Number.");
    try {
      gather.append(sayInGather);
      twiml.append(say);
      twiml.append(gather);
    } catch (TwiMLException e) {
      Logger.error("Error occured during the Fizz-Buzz generator call: " + e);
    }

    return twiml;
  }
Ejemplo n.º 2
0
  private static boolean callTo(Caller caller) {
    String callFrom = caller.callFrom;
    String callTo = caller.callTo;

    try {

      // Get the account and call factory class
      Account acct = client.getAccount();
      CallFactory callFactory = acct.getCallFactory();

      // build map of post parameters
      Map<String, String> params = new HashMap<String, String>();
      String url =
          "http://e4fa2e.ngrok.com/v1/twilio/delay/"
              + caller.getDays()
              + "/"
              + caller.getHours()
              + "/"
              + caller.getMinutes()
              + "/"
              + caller.getSeconds();
      Logger.info("Calling API " + url);
      params.put("From", callFrom);
      params.put("To", callTo);
      params.put("Url", url);
      params.put("Method", "GET");

      // Make a phone call ( This makes a POST request to the Calls
      // resource)
      callFactory.create(params);
    } catch (TwilioRestException e) {
      Logger.error(e.getErrorMessage());
      return false;
    }
    Logger.info("Calling...");
    return true;
  }