Search in sources :

Example 11 with Reprompt

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

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

the class ReplacementCardService method askIfBlockedOrDamaged.

private SpeechletResponse askIfBlockedOrDamaged(Intent intent, Session session) {
    String fourDigits = intent.getSlot("Number").getValue();
    LOGGER.info("Digits: " + fourDigits);
    boolean validDigits = false;
    // Check if these digits are valid
    List<Card> userCards = (List<Card>) SessionStorage.getInstance().getStorage(session.getSessionId()).get(STORAGE_VALID_CARDS);
    for (Card card : userCards) {
        String cardNumber = card.getCardNumber();
        if (cardNumber.substring(cardNumber.length() - 4).equals(fourDigits)) {
            // Digits are valid
            session.setAttribute(STORAGE_SELECTED_CARD_NUMBER, cardNumber);
            session.setAttribute(STORAGE_SELECTED_CARD_ID, card.getCardId());
            validDigits = true;
            break;
        }
    }
    // If these are invalid digits, ask again
    if (!validDigits) {
        return askForCardNumber(session, true);
    }
    PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
    speech.setText("Wurde die Karte gesperrt oder wurde sie beschädigt?");
    // Create reprompt
    Reprompt reprompt = new Reprompt();
    reprompt.setOutputSpeech(speech);
    return SpeechletResponse.newAskResponse(speech, reprompt);
}
Also used : Reprompt(com.amazon.speech.ui.Reprompt) ArrayList(java.util.ArrayList) List(java.util.List) PlainTextOutputSpeech(com.amazon.speech.ui.PlainTextOutputSpeech) Card(model.banking.Card)

Example 13 with Reprompt

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

Example 14 with Reprompt

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

the class SavingsPlanService method getCalculatedSavingsPlanInfo.

private SpeechletResponse getCalculatedSavingsPlanInfo(Session session) {
    // Assume we have all parameters now. Get them from the session attributes.
    String grundbetragString = (String) session.getAttribute(BASIC_AMOUNT_KEY);
    String einzahlungMonatString = (String) session.getAttribute(MONTHLY_PAYMENT_KEY);
    String anzahlJahreString = (String) session.getAttribute(DURATION_KEY);
    String calculationString = calculateSavings(grundbetragString, einzahlungMonatString, anzahlJahreString);
    // TODO Get interest rate from account info by API (new field)
    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);
    return SpeechletResponse.newAskResponse(speech, reprompt);
}
Also used : Reprompt(com.amazon.speech.ui.Reprompt) SsmlOutputSpeech(com.amazon.speech.ui.SsmlOutputSpeech)

Example 15 with Reprompt

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

the class SecuritiesAccountInformationService method getNextSecuritiesAccountInformation.

private SpeechletResponse getNextSecuritiesAccountInformation(Intent intent, Session session) {
    int nextEntry = (int) session.getAttribute("NextSecurity");
    Security nextSecurity;
    StringBuilder textBuilder = new StringBuilder();
    if (nextEntry < securities.size()) {
        String stockPrice = FinanceApi.getStockPrice(securities.get(nextEntry));
        nextSecurity = securities.get(nextEntry);
        textBuilder.append("Wertpapier Nummer ").append(nextSecurity.getSecurityId()).append(": ").append(nextSecurity.getDescription()).append(", " + nextSecurity.getQuantity() + " Stueck, ").append("mit einem momentanen Wert von ").append(stockPrice).append(" Euro. ");
        if (nextEntry == (securities.size() - 1)) {
            textBuilder.append("Das waren alle Wertpapiere in deinem Depot.");
            PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
            speech.setText(textBuilder.toString());
            return SpeechletResponse.newTellResponse(speech);
        } else {
            textBuilder.append("Moechtest du einen weiteren Eintrag hoeren?");
        }
        // Save current list offset in this session
        session.setAttribute("NextSecurity", nextEntry + 1);
        String text = textBuilder.toString();
        // Create the plain text output
        PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
        speech.setText(text);
        // Create reprompt
        Reprompt reprompt = new Reprompt();
        reprompt.setOutputSpeech(speech);
        return SpeechletResponse.newAskResponse(speech, reprompt);
    } else {
        // Create the plain text output
        PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
        speech.setText("Das waren alle Wertpapiere in deinem Depot.");
        return SpeechletResponse.newTellResponse(speech);
    }
}
Also used : Reprompt(com.amazon.speech.ui.Reprompt) PlainTextOutputSpeech(com.amazon.speech.ui.PlainTextOutputSpeech) Security(model.banking.Security)

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