Exemplo n.º 1
0
 private Notification notification(final int log, final int error, final String message) {
   final Notification.Builder builder = Notification.builder();
   final Sid sid = Sid.generate(Sid.Type.NOTIFICATION);
   builder.setSid(sid);
   builder.setAccountSid(accountId);
   builder.setCallSid(callInfo.sid());
   builder.setApiVersion(version);
   builder.setLog(log);
   builder.setErrorCode(error);
   final String base = configuration.subset("runtime-settings").getString("error-dictionary-uri");
   StringBuilder buffer = new StringBuilder();
   buffer.append(base);
   if (!base.endsWith("/")) {
     buffer.append("/");
   }
   buffer.append(error).append(".html");
   final URI info = URI.create(buffer.toString());
   builder.setMoreInfo(info);
   builder.setMessageText(message);
   final DateTime now = DateTime.now();
   builder.setMessageDate(now);
   if (request != null) {
     builder.setRequestUrl(request.getUri());
     builder.setRequestMethod(request.getMethod());
     builder.setRequestVariables(request.getParametersAsString());
   }
   if (response != null) {
     builder.setResponseHeaders(response.getHeadersAsString());
     final String type = response.getContentType();
     if (type.contains("text/xml")
         || type.contains("application/xml")
         || type.contains("text/html")) {
       try {
         builder.setResponseBody(response.getContentAsString());
       } catch (final IOException exception) {
         logger.error(
             "There was an error while reading the contents of the resource "
                 + "located @ "
                 + url.toString(),
             exception);
       }
     }
   }
   buffer = new StringBuilder();
   buffer.append("/").append(version).append("/Accounts/");
   buffer.append(accountId.toString()).append("/Notifications/");
   buffer.append(sid.toString());
   final URI uri = URI.create(buffer.toString());
   builder.setUri(uri);
   return builder.build();
 }
 private void removeTranscriptions(final String selector, final Sid sid) {
   final SqlSession session = sessions.openSession();
   try {
     session.delete(selector, sid.toString());
     session.commit();
   } finally {
     session.close();
   }
 }
 private Transcription getTranscription(final String selector, final Sid sid) {
   final SqlSession session = sessions.openSession();
   try {
     final Map<String, Object> result = session.selectOne(selector, sid.toString());
     if (result != null) {
       return toTranscription(result);
     } else {
       return null;
     }
   } finally {
     session.close();
   }
 }
Exemplo n.º 4
0
 List<NameValuePair> parameters() {
   final List<NameValuePair> parameters = new ArrayList<NameValuePair>();
   final String callSid = callInfo.sid().toString();
   parameters.add(new BasicNameValuePair("CallSid", callSid));
   final String accountSid = accountId.toString();
   parameters.add(new BasicNameValuePair("AccountSid", accountSid));
   final String from = (callInfo.from());
   parameters.add(new BasicNameValuePair("From", from));
   final String to = (callInfo.to());
   parameters.add(new BasicNameValuePair("To", to));
   final String state = callState.toString();
   parameters.add(new BasicNameValuePair("CallStatus", state));
   parameters.add(new BasicNameValuePair("ApiVersion", version));
   final String direction = callInfo.direction();
   parameters.add(new BasicNameValuePair("Direction", direction));
   final String callerName = callInfo.fromName();
   parameters.add(new BasicNameValuePair("CallerName", callerName));
   final String forwardedFrom = callInfo.forwardedFrom();
   parameters.add(new BasicNameValuePair("ForwardedFrom", forwardedFrom));
   // logger.info("Type " + callInfo.type());
   if (CreateCall.Type.SIP == callInfo.type()) {
     // Adding SIP OUT Headers and SipCallId for
     // https://bitbucket.org/telestax/telscale-restcomm/issue/132/implement-twilio-sip-out
     SipServletResponse lastResponse = callInfo.lastResponse();
     // logger.info("lastResponse " + lastResponse);
     if (lastResponse != null) {
       final int statusCode = lastResponse.getStatus();
       final String method = lastResponse.getMethod();
       // See https://www.twilio.com/docs/sip/receiving-sip-headers
       // Headers on the final SIP response message (any 4xx or 5xx message or the final BYE/200)
       // are posted to the
       // Dial action URL.
       if ((statusCode >= 400 && "INVITE".equalsIgnoreCase(method))
           || (statusCode >= 200 && statusCode < 300 && "BYE".equalsIgnoreCase(method))) {
         final String sipCallId = lastResponse.getCallId();
         parameters.add(new BasicNameValuePair("DialSipCallId", sipCallId));
         parameters.add(new BasicNameValuePair("DialSipResponseCode", "" + statusCode));
         Iterator<String> headerIt = lastResponse.getHeaderNames();
         while (headerIt.hasNext()) {
           String headerName = headerIt.next();
           if (headerName.startsWith("X-")) {
             parameters.add(
                 new BasicNameValuePair(
                     "DialSipHeader_" + headerName, lastResponse.getHeader(headerName)));
           }
         }
       }
     }
   }
   return parameters;
 }
 @Override
 public List<Transcription> getTranscriptions(final Sid accountSid) {
   final SqlSession session = sessions.openSession();
   try {
     final List<Map<String, Object>> results =
         session.selectList(namespace + "getTranscriptions", accountSid.toString());
     final List<Transcription> transcriptions = new ArrayList<Transcription>();
     if (results != null && !results.isEmpty()) {
       for (final Map<String, Object> result : results) {
         transcriptions.add(toTranscription(result));
       }
     }
     return transcriptions;
   } finally {
     session.close();
   }
 }
Exemplo n.º 6
0
  public UssdInterpreter(
      final Configuration configuration,
      final Sid account,
      final Sid phone,
      final String version,
      final URI url,
      final String method,
      final URI fallbackUrl,
      final String fallbackMethod,
      final URI statusCallback,
      final String statusCallbackMethod,
      final String emailAddress,
      final ActorRef callManager,
      final ActorRef conferenceManager,
      final ActorRef sms,
      final DaoManager storage) {
    super();
    final ActorRef source = self();

    uninitialized = new State("uninitialized", null, null);
    observeCall = new State("observe call", new ObserveCall(source), null);
    acquiringCallInfo = new State("acquiring call info", new AcquiringCallInfo(source), null);
    downloadingRcml = new State("downloading rcml", new DownloadingRcml(source), null);
    downloadingFallbackRcml =
        new State("downloading fallback rcml", new DownloadingFallbackRcml(source), null);
    preparingMessage = new State("Preparing message", new PreparingMessage(source), null);
    processingInfoRequest =
        new State("Processing info request from client", new ProcessingInfoRequest(source), null);

    ready = new State("ready", new Ready(source), null);
    notFound = new State("notFound", new NotFound(source), null);

    cancelling = new State("Cancelling", new Cancelling(source), null);
    disconnecting = new State("Disconnecting", new Disconnecting(source), null);

    finished = new State("finished", new Finished(source), null);

    transitions.add(new Transition(uninitialized, acquiringCallInfo));
    transitions.add(new Transition(uninitialized, cancelling));
    transitions.add(new Transition(acquiringCallInfo, downloadingRcml));
    transitions.add(new Transition(acquiringCallInfo, cancelling));
    transitions.add(new Transition(downloadingRcml, ready));
    transitions.add(new Transition(downloadingRcml, cancelling));
    transitions.add(new Transition(downloadingRcml, notFound));
    transitions.add(new Transition(downloadingRcml, downloadingFallbackRcml));
    transitions.add(new Transition(downloadingRcml, finished));
    transitions.add(new Transition(downloadingRcml, ready));
    transitions.add(new Transition(ready, preparingMessage));
    transitions.add(new Transition(preparingMessage, downloadingRcml));
    transitions.add(new Transition(preparingMessage, processingInfoRequest));
    transitions.add(new Transition(preparingMessage, disconnecting));
    transitions.add(new Transition(preparingMessage, finished));
    transitions.add(new Transition(processingInfoRequest, preparingMessage));
    transitions.add(new Transition(processingInfoRequest, ready));
    transitions.add(new Transition(processingInfoRequest, finished));
    transitions.add(new Transition(disconnecting, finished));

    // Initialize the FSM.
    this.fsm = new FiniteStateMachine(uninitialized, transitions);
    // Initialize the runtime stuff.
    this.accountId = account;
    this.phoneId = phone;
    this.version = version;
    this.url = url;
    this.method = method;
    this.fallbackUrl = fallbackUrl;
    this.fallbackMethod = fallbackMethod;
    this.statusCallback = statusCallback;
    this.statusCallbackMethod = statusCallbackMethod;
    this.emailAddress = emailAddress;
    this.configuration = configuration;

    this.storage = storage;
    final Configuration runtime = configuration.subset("runtime-settings");
    String path = runtime.getString("cache-path");
    if (!path.endsWith("/")) {
      path = path + "/";
    }
    path = path + accountId.toString();
    this.downloader = downloader();
  }