Search in sources :

Example 1 with ApiHelper

use of amosalexa.ApiHelper in project amos-ss17-alexa by c-i-ber.

the class StandingOrderDialog method getStandingOrdersDeleteResponse.

private SpeechletResponse getStandingOrdersDeleteResponse(Intent intent, SessionStorage.Storage storage) {
    LOGGER.info("StandingOrdersDeleteResponse called.");
    String standingOrderToDelete = (String) storage.get("StandingOrderToDelete");
    // Create the Simple card content.
    SimpleCard card = new SimpleCard();
    card.setTitle("Lösche Dauerauftrag");
    // Create the plain text output.
    PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
    ApiHelper helper = new ApiHelper();
    try {
        helper.sendDelete("http://amos-bank-lb-723794096.eu-central-1.elb.amazonaws.com/api/v1_0/accounts/9999999999/standingorders/" + standingOrderToDelete);
    } catch (Exception e) {
        LOGGER.error(e.getMessage());
        card.setContent("Dauerauftrag Nummer " + standingOrderToDelete + " wurde nicht gefunden.");
        speech.setText("Dauerauftrag Nummer " + standingOrderToDelete + " wurde nicht gefunden.");
        return SpeechletResponse.newTellResponse(speech, card);
    }
    card.setContent("Dauerauftrag Nummer " + standingOrderToDelete + " wurde gelöscht.");
    speech.setText("Dauerauftrag Nummer " + standingOrderToDelete + " wurde geloescht.");
    return SpeechletResponse.newTellResponse(speech, card);
}
Also used : SimpleCard(com.amazon.speech.ui.SimpleCard) ApiHelper(amosalexa.ApiHelper) PlainTextOutputSpeech(com.amazon.speech.ui.PlainTextOutputSpeech) JSONException(com.amazonaws.util.json.JSONException) IOException(java.io.IOException) SpeechletException(com.amazon.speech.speechlet.SpeechletException)

Example 2 with ApiHelper

use of amosalexa.ApiHelper in project amos-ss17-alexa by c-i-ber.

the class StandingOrderDialog method getStandingOrdersInfoResponse.

/**
     * Creates a {@code SpeechletResponse} for the standing orders intent.
     *
     * @return SpeechletResponse spoken and visual response for the given intent
     */
private SpeechletResponse getStandingOrdersInfoResponse(Intent intent, SessionStorage.Storage storage) {
    LOGGER.info("StandingOrdersResponse called.");
    Map<String, Slot> slots = intent.getSlots();
    ObjectMapper mapper = new ObjectMapper();
    ApiHelper helper = new ApiHelper();
    String test = null;
    try {
        test = helper.sendGet("http://amos-bank-lb-723794096.eu-central-1.elb.amazonaws.com/api/v1_0/accounts/9999999999/standingorders");
    } catch (Exception e) {
    //TODO
    }
    StandingOrderResponse standingOrderResponse = null;
    try {
        standingOrderResponse = mapper.readValue(test, StandingOrderResponse.class);
    } catch (IOException e) {
        LOGGER.error(e.getMessage());
    }
    // Create the Simple card content.
    SimpleCard card = new SimpleCard();
    card.setTitle("Daueraufträge");
    // Create the plain text output.
    PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
    if (standingOrderResponse == null || standingOrderResponse.get_embedded() == null) {
        card.setContent("Keine Daueraufträge vorhanden.");
        speech.setText("Keine Dauerauftraege vorhanden.");
        return SpeechletResponse.newTellResponse(speech, card);
    }
    standingOrders = standingOrderResponse.get_embedded().getStandingOrders();
    // Check if user requested to have their stranding orders sent to their email address
    Slot channelSlot = slots.get("Channel");
    boolean sendPerEmail = channelSlot != null && channelSlot.getValue() != null && channelSlot.getValue().equals("email");
    StringBuilder textBuilder = new StringBuilder();
    if (sendPerEmail) {
        // TODO: Send standing orders to user's email address
        textBuilder.append("Ich habe").append(standingOrders.length).append(" an deine E-Mail-Adresse gesendet.");
    } else {
        // We want to directly return standing orders here
        Slot payeeSlot = slots.get("Payee");
        String payee = payeeSlot.getValue();
        if (payee != null) {
            // User specified a recipient
            List<StandingOrder> orders = new LinkedList<>();
            // Find closest standing orders that could match the request.
            for (int i = 0; i < standingOrders.length; i++) {
                if (StringUtils.getLevenshteinDistance(payee, standingOrders[i].getPayee()) <= standingOrders[i].getPayee().length() / 3) {
                    orders.add(standingOrders[i]);
                }
            }
            textBuilder.append(orders.size() == 1 ? "Es wurde ein Dauerauftrag gefunden." : "Es wurden " + orders.size() + " Dauerauftraege gefunden.");
            int i = 1;
            for (StandingOrder order : orders) {
                textBuilder.append(' ');
                textBuilder.append("Dauerauftrag ").append(order.getStandingOrderId()).append(": ");
                textBuilder.append("Ueberweise ").append(order.getExecutionRateString()).append(order.getAmount()).append(" Euro an ").append(order.getPayee()).append(".");
                i++;
            }
        } else {
            // Just return all standing orders
            textBuilder.append("Du hast momentan ").append(standingOrders.length == 1 ? "einen Dauerauftrag. " : standingOrders.length + " Dauerauftraege. ");
            for (int i = 0; i <= 1; i++) {
                textBuilder.append(' ');
                textBuilder.append("Dauerauftrag ").append(standingOrders[i].getStandingOrderId()).append(": ");
                textBuilder.append("Ueberweise ").append(standingOrders[i].getExecutionRateString()).append(standingOrders[i].getAmount()).append(" Euro an ").append(standingOrders[i].getPayee()).append(".");
            }
            if (standingOrders.length > 2) {
                textBuilder.append(" Moechtest du einen weiteren Eintrag hoeren?");
                String text = textBuilder.toString();
                card.setContent(text);
                speech.setText(text);
                // Create reprompt
                Reprompt reprompt = new Reprompt();
                reprompt.setOutputSpeech(speech);
                // Save current list offset in this session
                storage.put("NextStandingOrder", 2);
                return SpeechletResponse.newAskResponse(speech, reprompt);
            }
        }
    }
    String text = textBuilder.toString();
    card.setContent(text);
    speech.setText(text);
    return SpeechletResponse.newTellResponse(speech, card);
}
Also used : StandingOrderResponse(model.banking.account.StandingOrderResponse) StandingOrder(model.banking.account.StandingOrder) IOException(java.io.IOException) JSONException(com.amazonaws.util.json.JSONException) IOException(java.io.IOException) SpeechletException(com.amazon.speech.speechlet.SpeechletException) LinkedList(java.util.LinkedList) SimpleCard(com.amazon.speech.ui.SimpleCard) Reprompt(com.amazon.speech.ui.Reprompt) Slot(com.amazon.speech.slu.Slot) ApiHelper(amosalexa.ApiHelper) PlainTextOutputSpeech(com.amazon.speech.ui.PlainTextOutputSpeech) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

ApiHelper (amosalexa.ApiHelper)2 SpeechletException (com.amazon.speech.speechlet.SpeechletException)2 PlainTextOutputSpeech (com.amazon.speech.ui.PlainTextOutputSpeech)2 SimpleCard (com.amazon.speech.ui.SimpleCard)2 JSONException (com.amazonaws.util.json.JSONException)2 IOException (java.io.IOException)2 Slot (com.amazon.speech.slu.Slot)1 Reprompt (com.amazon.speech.ui.Reprompt)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 LinkedList (java.util.LinkedList)1 StandingOrder (model.banking.account.StandingOrder)1 StandingOrderResponse (model.banking.account.StandingOrderResponse)1