Search in sources :

Example 1 with SsmlOutputSpeech

use of com.amazon.speech.ui.SsmlOutputSpeech 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 2 with SsmlOutputSpeech

use of com.amazon.speech.ui.SsmlOutputSpeech 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 3 with SsmlOutputSpeech

use of com.amazon.speech.ui.SsmlOutputSpeech 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)

Example 4 with SsmlOutputSpeech

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

the class ReplacementCardService method askForCardNumber.

private SpeechletResponse askForCardNumber(Session session, boolean errored) {
    // TODO: Load account from session
    Collection<Card> cards = AccountAPI.getCardsForAccount(ACCOUNT_NUMBER);
    if (cards.size() == 0) {
        // This user does not have any cards, ordering a replacement card is impossible.
        PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
        speech.setText("Es wurden keine Kredit- oder EC-Karten gefunden.");
        return SpeechletResponse.newTellResponse(speech);
    } else {
        SsmlOutputSpeech speech = new SsmlOutputSpeech();
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("<speak>");
        if (errored) {
            stringBuilder.append("Entschuldigung, das habe ich nicht verstanden. ");
        }
        stringBuilder.append("Bestellung einer Ersatzkarte. Es wurden folgende Karten gefunden: ");
        List<Card> userCards = new ArrayList<>();
        for (Card card : cards) {
            // Check if this card is active
            if (card.getStatus() != Card.Status.ACTIVE) {
                continue;
            }
            userCards.add(card);
            String prefix = (card.getCardType() == Card.CardType.CREDIT ? "Kredit" : "EC-");
            stringBuilder.append(prefix + "karte mit den Endziffern <say-as interpret-as=\"digits\">" + card.getCardNumber().substring(card.getCardNumber().length() - 4) + "</say-as>. ");
        }
        // Store all card numbers in the session
        SessionStorage.getInstance().getStorage(session.getSessionId()).put(STORAGE_VALID_CARDS, userCards);
        stringBuilder.append("Bitte gib die Endziffern der Karte an, für die du Ersatz benötigst.");
        stringBuilder.append("</speak>");
        speech.setSsml(stringBuilder.toString());
        // Create reprompt
        Reprompt reprompt = new Reprompt();
        reprompt.setOutputSpeech(speech);
        return SpeechletResponse.newAskResponse(speech, reprompt);
    }
}
Also used : ArrayList(java.util.ArrayList) Reprompt(com.amazon.speech.ui.Reprompt) PlainTextOutputSpeech(com.amazon.speech.ui.PlainTextOutputSpeech) SsmlOutputSpeech(com.amazon.speech.ui.SsmlOutputSpeech) Card(model.banking.Card)

Example 5 with SsmlOutputSpeech

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

the class ContactService method readContacts.

private SpeechletResponse readContacts(Session session, int offset, int limit) {
    List<Contact> contactList = DynamoDbMapper.getInstance().loadAll(Contact.class);
    List<Contact> contacts = new ArrayList<>(contactList);
    LOGGER.info("Contacts: " + contacts);
    if (contacts.size() == 0) {
        return getResponse(CONTACTS, "Du hast keine Kontakte in deiner Kontaktliste.");
    }
    if (offset >= contacts.size()) {
        session.setAttribute(CONTACTS + ".offset", null);
        return getResponse(CONTACTS, "Keine weiteren Kontakte.");
    }
    if (offset + limit >= contacts.size()) {
        limit = contacts.size() - offset;
    }
    Collections.sort(contacts);
    StringBuilder response = new StringBuilder();
    response.append("<speak>");
    for (int i = offset; i < offset + limit; i++) {
        Contact contact = contacts.get(i);
        response.append("Kontakt ").append(contact.getId()).append(": ");
        response.append("Name: ").append(contact.getName()).append(", IBAN: ").append(DialogUtil.getIbanSsmlOutput(contact.getIban())).append(". ");
    }
    boolean isAskResponse = contacts.size() > offset + limit;
    if (isAskResponse) {
        response.append("Weitere Kontakte vorlesen?");
        response.append("</speak>");
        session.setAttribute(CONTACTS + ".offset", offset + limit);
        SsmlOutputSpeech speech = new SsmlOutputSpeech();
        speech.setSsml(response.toString());
        Reprompt reprompt = new Reprompt();
        reprompt.setOutputSpeech(speech);
        return SpeechletResponse.newAskResponse(speech, reprompt);
    } else {
        response.append("Keine weiteren Kontakte.");
        response.append("</speak>");
        session.setAttribute(CONTACTS + ".offset", null);
        SsmlOutputSpeech speech = new SsmlOutputSpeech();
        speech.setSsml(response.toString());
        return SpeechletResponse.newTellResponse(speech);
    }
}
Also used : Reprompt(com.amazon.speech.ui.Reprompt) SsmlOutputSpeech(com.amazon.speech.ui.SsmlOutputSpeech) Contact(model.db.Contact)

Aggregations

Reprompt (com.amazon.speech.ui.Reprompt)9 SsmlOutputSpeech (com.amazon.speech.ui.SsmlOutputSpeech)9 Slot (com.amazon.speech.slu.Slot)3 PlainTextOutputSpeech (com.amazon.speech.ui.PlainTextOutputSpeech)2 ArrayList (java.util.ArrayList)2 Card (model.banking.Card)1 StandingOrder (model.banking.StandingOrder)1 CardResponse (model.banking.account.CardResponse)1 Contact (model.db.Contact)1