Search in sources :

Example 6 with Reprompt

use of com.amazon.speech.ui.Reprompt in project amos-ss17-alexa by c-i-ber.

the class SavingsPlanDialog method askForSavingsParameter.

private SpeechletResponse askForSavingsParameter(Intent intent, SessionStorage.Storage storage) {
    Map<String, Slot> slots = intent.getSlots();
    String grundbetrag = slots.get(GRUNDBETRAG_KEY).getValue();
    String anzahlJahre = slots.get(ANZAHL_JAHRE_KEY).getValue();
    String monatlicheEinzahlung = slots.get(EINZAHLUNG_MONAT_KEY).getValue();
    String speechText, repromptText;
    LOGGER.info("Grundbetrag: " + grundbetrag);
    LOGGER.info("Jahre: " + anzahlJahre);
    LOGGER.info("monatliche Einzahlung: " + monatlicheEinzahlung);
    LOGGER.info("Storage Before: " + storage);
    if (grundbetrag != null && storage.containsKey(GRUNDBETRAG_KEY)) {
        monatlicheEinzahlung = grundbetrag;
        grundbetrag = null;
    }
    if (grundbetrag != null) {
        storage.put(GRUNDBETRAG_KEY, grundbetrag);
    }
    if (anzahlJahre != null) {
        storage.put(ANZAHL_JAHRE_KEY, anzahlJahre);
    }
    if (monatlicheEinzahlung != null) {
        storage.put(EINZAHLUNG_MONAT_KEY, monatlicheEinzahlung);
    }
    if (grundbetrag == null && !storage.containsKey(GRUNDBETRAG_KEY)) {
        speechText = "Was moechtest du als Grundbetrag anlegen?";
        repromptText = speechText;
        return getSpeechletResponse(speechText, repromptText, true);
    }
    if (anzahlJahre == null && !storage.containsKey(ANZAHL_JAHRE_KEY)) {
        speechText = "Wie viele Jahre moechtest du das Geld anlegen?";
        //TODO better use duration?
        repromptText = speechText;
        return getSpeechletResponse(speechText, repromptText, true);
    }
    if (monatlicheEinzahlung == null && !storage.containsKey(EINZAHLUNG_MONAT_KEY)) {
        if (grundbetrag == null && !storage.containsKey(GRUNDBETRAG_KEY)) {
            speechText = "Du musst zuerst einen Grundbetrag angeben.";
            repromptText = speechText;
            return getSpeechletResponse(speechText, repromptText, true);
        }
        speechText = "Wie viel Geld moechtest du monatlich investieren?";
        repromptText = speechText;
        return getSpeechletResponse(speechText, repromptText, true);
    }
    String grundbetragString = (String) storage.get(GRUNDBETRAG_KEY);
    String einzahlungMonatString = (String) storage.get(EINZAHLUNG_MONAT_KEY);
    String anzahlJahreString = (String) storage.get(ANZAHL_JAHRE_KEY);
    String calculationString = calculateSavings(grundbetragString, einzahlungMonatString, anzahlJahreString);
    SsmlOutputSpeech speech = new SsmlOutputSpeech();
    speech.setSsml("<speak>Bei einem Zinssatz von zwei Prozent waere der Gesamtsparbetrag am Ende " + "des Zeitraums insgesamt <say-as interpret-as=\"number\">" + calculationString + "</say-as> Euro. Soll ich diesen Sparplan fuer dich anlegen?</speak>");
    // Create reprompt
    Reprompt reprompt = new Reprompt();
    reprompt.setOutputSpeech(speech);
    //LOGGER.info("Session Afterwards: " + session.getAttributes());
    LOGGER.info("Storage afterwards: " + storage);
    return SpeechletResponse.newAskResponse(speech, reprompt);
}
Also used : Reprompt(com.amazon.speech.ui.Reprompt) Slot(com.amazon.speech.slu.Slot) SsmlOutputSpeech(com.amazon.speech.ui.SsmlOutputSpeech)

Example 7 with Reprompt

use of com.amazon.speech.ui.Reprompt in project amos-ss17-alexa by c-i-ber.

the class AbstractSpeechService method getReprompt.

/**
     * Helper method that returns a reprompt object. This is used in Ask responses where you want
     * the user to be able to respond to your speech.
     *
     * @param outputSpeech The OutputSpeech object that will be said once and repeated if necessary.
     * @return Reprompt instance.
     */
protected Reprompt getReprompt(OutputSpeech outputSpeech) {
    Reprompt reprompt = new Reprompt();
    reprompt.setOutputSpeech(outputSpeech);
    return reprompt;
}
Also used : Reprompt(com.amazon.speech.ui.Reprompt)

Example 8 with Reprompt

use of com.amazon.speech.ui.Reprompt in project amos-ss17-alexa by c-i-ber.

the class StandingOrderService method getStandingOrdersInfoForKeyword.

private SpeechletResponse getStandingOrdersInfoForKeyword(Intent intent, Session session) {
    Map<String, Slot> slots = intent.getSlots();
    Slot standingOrderKeywordSlot = slots.get("StandingOrderKeyword");
    Slot transactionKeywordSlot = slots.get("TransactionKeyword");
    if ((standingOrderKeywordSlot == null || standingOrderKeywordSlot.getValue() == null) && (transactionKeywordSlot == null || transactionKeywordSlot.getValue() == null)) {
        // TODO
        return null;
    }
    String keyword = standingOrderKeywordSlot.getValue() != null ? standingOrderKeywordSlot.getValue() : transactionKeywordSlot.getValue();
    LOGGER.info("Keyword: " + keyword);
    if (keyword.equals("ersparnisse")) {
        keyword = "sparplan regelm. einzahlung";
    }
    Collection<StandingOrder> standingOrdersCollection = AccountAPI.getStandingOrdersForAccount(ACCOUNT_NUMBER);
    standingOrders = new ArrayList<>();
    for (StandingOrder so : standingOrdersCollection) {
        String description = so.getDescription().toLowerCase();
        // LOGGER.info("Description: " + description);
        if (!description.equals(keyword)) {
            String[] singleWords = description.split("\\s+");
            for (String s : singleWords) {
                if (keyword.equals(s)) {
                    standingOrders.add(so);
                    continue;
                }
                double similarity = getStringSimilarity(s, keyword);
                // 0.9 seems to be a good value for similarity
                if (similarity >= 0.9) {
                    standingOrders.add(so);
                }
            }
        } else {
            standingOrders.add(so);
            continue;
        }
    }
    if (standingOrders.size() == 0) {
        String answer = "Ich konnte keine Dauerauftraege finden, die zu diesem Stichwort passen.";
        return getResponse(STANDING_ORDERS, answer);
    }
    double total = 0;
    for (StandingOrder so : standingOrders) {
        if (so.getExecutionRate().equals(StandingOrder.ExecutionRate.MONTHLY)) {
            total += so.getAmount().doubleValue();
        } else if (so.getExecutionRate().equals(StandingOrder.ExecutionRate.QUARTERLY)) {
            total += so.getAmount().doubleValue() / 3;
        } else if (so.getExecutionRate().equals(StandingOrder.ExecutionRate.HALF_YEARLY)) {
            total += so.getAmount().doubleValue() / 6;
        } else if (so.getExecutionRate().equals(StandingOrder.ExecutionRate.YEARLY)) {
            total += so.getAmount().doubleValue() / 12;
        }
    }
    StringBuilder builder = new StringBuilder();
    builder.append("<speak>");
    builder.append("Aus ").append(standingOrders.size() == 1 ? "<phoneme alphabet=\"ipa\" ph=\"ˈaɪ̯nəm\">einem</phoneme>" + " gefundenen Dauerauftrag " : standingOrders.size() + " gefundenen Dauerauftraegen ").append("konnte ich berechnen, dass du monatlich " + total + " Euro ").append(keyword.equals("sparplan regelm. einzahlung") ? "zum Sparen zuruecklegst. " : "fuer " + keyword + " bezahlst. ");
    builder.append("Soll ich die gefundenen Dauerauftraege aufzaehlen? ");
    builder.append("</speak>");
    SsmlOutputSpeech speech = new SsmlOutputSpeech();
    speech.setSsml(builder.toString());
    // Create reprompt
    Reprompt reprompt = new Reprompt();
    reprompt.setOutputSpeech(speech);
    return SpeechletResponse.newAskResponse(speech, reprompt);
}
Also used : StandingOrder(model.banking.StandingOrder) Reprompt(com.amazon.speech.ui.Reprompt) Slot(com.amazon.speech.slu.Slot) SsmlOutputSpeech(com.amazon.speech.ui.SsmlOutputSpeech)

Example 9 with Reprompt

use of com.amazon.speech.ui.Reprompt in project amos-ss17-alexa by c-i-ber.

the class StandingOrderService method askForModificationConfirmation.

private SpeechletResponse askForModificationConfirmation(Intent intent, Session session) {
    Map<String, Slot> slots = intent.getSlots();
    Slot numberSlot = slots.get("Number");
    Slot amountSlot = slots.get("Amount");
    Slot executionRateSlot = slots.get("ExecutionRate");
    Slot firstExecutionSlot = slots.get("FirstExecution");
    if (numberSlot.getValue() == null || (amountSlot.getValue() == null && executionRateSlot.getValue() == null && firstExecutionSlot.getValue() == null)) {
        String text = "Das habe ich nicht ganz verstanden. Bitte wiederhole deine Eingabe.";
        return getAskResponse(STANDING_ORDERS, text);
    }
    session.setAttribute("StandingOrderToModify", numberSlot.getValue());
    session.setAttribute("NewAmount", amountSlot.getValue());
    session.setAttribute("NewExecutionRate", executionRateSlot.getValue());
    session.setAttribute("NewFirstExecution", firstExecutionSlot.getValue());
    // Create the plain text output
    PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
    speech.setText("Soll ich den Betrag von Dauerauftrag Nummer " + numberSlot.getValue() + " wirklich auf " + amountSlot.getValue() + " Euro aendern?");
    // Create reprompt
    Reprompt reprompt = new Reprompt();
    reprompt.setOutputSpeech(speech);
    return SpeechletResponse.newAskResponse(speech, reprompt);
}
Also used : Reprompt(com.amazon.speech.ui.Reprompt) Slot(com.amazon.speech.slu.Slot) PlainTextOutputSpeech(com.amazon.speech.ui.PlainTextOutputSpeech)

Example 10 with Reprompt

use of com.amazon.speech.ui.Reprompt in project amos-ss17-alexa by c-i-ber.

the class ReplacementCardService method askForConfirmation.

private SpeechletResponse askForConfirmation(Intent intent, Session session) {
    if (!session.getAttributes().containsKey(STORAGE_SELECTED_CARD_NUMBER)) {
        return askForCardNumber(session, true);
    }
    String replacementReason = intent.getSlot("ReplacementReason").getValue();
    LOGGER.info("Replacement reason: " + replacementReason);
    if (replacementReason.equals("beschaedigt")) {
        LOGGER.info("Beschädigt");
        session.setAttribute(STORAGE_REASON, ReplacementReason.DAMAGED);
    } else if (replacementReason.equals("gesperrt")) {
        LOGGER.info("Gesperrt");
        session.setAttribute(STORAGE_REASON, ReplacementReason.BLOCKED);
    } else {
        return askIfBlockedOrDamaged(intent, session);
    }
    SsmlOutputSpeech speech = new SsmlOutputSpeech();
    String reason = session.getAttribute(STORAGE_REASON) == ReplacementReason.DAMAGED ? "beschädigte" : "gesperrte";
    String lastDigits = (String) session.getAttribute(STORAGE_SELECTED_CARD_NUMBER);
    lastDigits = lastDigits.substring(lastDigits.length() - 4);
    speech.setSsml("<speak>Soll ein Ersatz für die " + reason + " Karte mit den Endziffern <say-as interpret-as=\"digits\">" + lastDigits + "</say-as> bestellt werden?</speak>");
    // Create reprompt
    Reprompt reprompt = new Reprompt();
    reprompt.setOutputSpeech(speech);
    return SpeechletResponse.newAskResponse(speech, reprompt);
}
Also used : Reprompt(com.amazon.speech.ui.Reprompt) SsmlOutputSpeech(com.amazon.speech.ui.SsmlOutputSpeech)

Aggregations

Reprompt (com.amazon.speech.ui.Reprompt)30 PlainTextOutputSpeech (com.amazon.speech.ui.PlainTextOutputSpeech)22 Slot (com.amazon.speech.slu.Slot)10 SimpleCard (com.amazon.speech.ui.SimpleCard)10 SsmlOutputSpeech (com.amazon.speech.ui.SsmlOutputSpeech)9 ArrayList (java.util.ArrayList)4 StandingOrder (model.banking.StandingOrder)3 List (java.util.List)2 Card (model.banking.Card)2 StandingOrder (model.banking.account.StandingOrder)2 Contact (model.db.Contact)2 ApiHelper (amosalexa.ApiHelper)1 SpeechletException (com.amazon.speech.speechlet.SpeechletException)1 JSONException (com.amazonaws.util.json.JSONException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 LinkedList (java.util.LinkedList)1 Security (model.banking.Security)1