Search in sources :

Example 16 with Reprompt

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

the class StandingOrderService method smartUpdateStandingOrderConfirmation.

/**
 * Creates a {@code SpeechletResponse} for the standing orders intent.
 *
 * @return SpeechletResponse spoken and visual response for the given intent
 */
private SpeechletResponse smartUpdateStandingOrderConfirmation(Intent intent, Session session) {
    LOGGER.info("SmartStandingOrders called.");
    Map<String, Slot> slots = intent.getSlots();
    Collection<StandingOrder> standingOrdersCollection = AccountAPI.getStandingOrdersForAccount(ACCOUNT_NUMBER);
    standingOrders = new ArrayList<>(standingOrdersCollection);
    SimpleCard card = new SimpleCard();
    card.setTitle("Daueraufträge");
    Slot payeeSlot = slots.get("Payee");
    String payee = (payeeSlot == null ? null : payeeSlot.getValue());
    Slot payeeSecondNameSlot = slots.get("PayeeSecondName");
    String payeeSecondName = (payeeSecondNameSlot == null ? null : payeeSecondNameSlot.getValue());
    Slot amountSlot = slots.get("orderAmount");
    String amount = (amountSlot == null ? null : amountSlot.getValue());
    String payeeFullName;
    if (payee == null) {
        payeeFullName = payeeSecondName.toLowerCase();
    } else if (payeeSecondName == null) {
        payeeFullName = payee.toLowerCase();
    } else {
        payeeFullName = (payee + " " + payeeSecondName).toLowerCase();
    }
    LOGGER.info("full name: " + payeeFullName);
    session.setAttribute("NewAmount", amount);
    session.setAttribute("Payee", payee);
    session.setAttribute("PayeeSecondName", payeeSecondName);
    for (StandingOrder standingOrder : standingOrders) {
        String amountString = Integer.toString(standingOrder.getAmount().intValue());
        LOGGER.info(standingOrder.getPayee().toLowerCase() + ": " + payeeFullName);
        if (standingOrder.getPayee().toLowerCase().equals(payeeFullName)) {
            // getting data object
            DateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd");
            Date executionDate;
            try {
                executionDate = dateFormat.parse(standingOrder.getFirstExecution());
            } catch (java.text.ParseException e) {
                e.printStackTrace();
            }
            // Create the plain text output
            PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
            speech.setText("Der Dauerauftrag für " + payeeFullName + " über " + standingOrder.getAmount() + " Euro existiert schon. Möchtest du diesen aktualisieren");
            session.setAttribute("StandingOrderToModify", standingOrder.getStandingOrderId());
            // Create reprompt
            Reprompt reprompt = new Reprompt();
            reprompt.setOutputSpeech(speech);
            return SpeechletResponse.newAskResponse(speech, reprompt);
        }
    }
    // creating a new stating order if its in contact list
    List<Contact> contactList = DynamoDbMapper.getInstance().loadAll(Contact.class);
    List<Contact> contacts = new ArrayList<>(contactList);
    for (int i = 0; i < contacts.size(); i++) {
        LOGGER.info(contacts.get(i).getName().toString().toLowerCase());
        if (contacts.get(i).getName().toString().toLowerCase().equals(payeeFullName)) {
            StandingOrder standingOrder = new StandingOrder();
            standingOrder.setPayee(payeeFullName);
            standingOrder.setAmount(Integer.parseInt(amount));
            standingOrder.setDestinationAccount(contacts.get(i).getIban());
            standingOrder.setFirstExecution("09-09-2017");
            standingOrder.setDestinationAccount("DE39100000007777777777");
            AccountAPI.createStandingOrderForAccount(ACCOUNT_NUMBER, standingOrder);
            PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
            speech.setText("Ich habe den neuen Dauerauftrag für" + payeeFullName + " über " + amount + " Euro erfolgreich eingerichtet");
            // deleting attributes
            session.removeAttribute("NewAmount");
            session.removeAttribute("Payee");
            session.removeAttribute("PayeeSecondName");
            return SpeechletResponse.newTellResponse(speech, card);
        }
    }
    // Contact not found
    PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
    speech.setText("Ich habe " + payeeFullName + " in deiner Kontaktliste nicht gefunden. " + "Du musst ihm erst in der Kontaktliste hinzufügen");
    // deleting attributes
    session.removeAttribute("NewAmount");
    session.removeAttribute("Payee");
    session.removeAttribute("PayeeSecondName");
    return SpeechletResponse.newTellResponse(speech, card);
}
Also used : StandingOrder(model.banking.StandingOrder) Contact(model.db.Contact) SimpleCard(com.amazon.speech.ui.SimpleCard) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) Reprompt(com.amazon.speech.ui.Reprompt) Slot(com.amazon.speech.slu.Slot) PlainTextOutputSpeech(com.amazon.speech.ui.PlainTextOutputSpeech) SimpleDateFormat(java.text.SimpleDateFormat)

Example 17 with Reprompt

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

the class StandingOrderService method askForDDeletionConfirmation.

private SpeechletResponse askForDDeletionConfirmation(Intent intent, Session session) {
    Map<String, Slot> slots = intent.getSlots();
    Slot numberSlot = slots.get("Number");
    LOGGER.info("NumberSlot: " + numberSlot.getValue());
    session.setAttribute("StandingOrderToDelete", numberSlot.getValue());
    // Create the plain text output
    PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
    speech.setText("Moechtest du den Dauerauftrag mit der Nummer " + numberSlot.getValue() + " wirklich loeschen?");
    // 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 18 with Reprompt

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

the class SavingsPlanDialog method getSpeechletResponse.

private SpeechletResponse getSpeechletResponse(String speechText, String repromptText, boolean isAskResponse) {
    // Create the Simple card content.
    SimpleCard card = new SimpleCard();
    card.setTitle("Session");
    card.setContent(speechText);
    // Create the plain text output.
    PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
    speech.setText(speechText);
    if (isAskResponse) {
        // Create reprompt
        PlainTextOutputSpeech repromptSpeech = new PlainTextOutputSpeech();
        repromptSpeech.setText(repromptText);
        Reprompt reprompt = new Reprompt();
        reprompt.setOutputSpeech(repromptSpeech);
        return SpeechletResponse.newAskResponse(speech, reprompt, card);
    } else {
        return SpeechletResponse.newTellResponse(speech, card);
    }
}
Also used : SimpleCard(com.amazon.speech.ui.SimpleCard) Reprompt(com.amazon.speech.ui.Reprompt) PlainTextOutputSpeech(com.amazon.speech.ui.PlainTextOutputSpeech)

Example 19 with Reprompt

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

the class ReplacementCardDialog method askForCardNumber.

private SpeechletResponse askForCardNumber(SessionStorage.Storage storage, boolean errored) {
    // TODO: Load account from session
    Collection<CardResponse> cards = AccountFactory.getInstance().getCardsForAccount("0000000000");
    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<String> userCards = new ArrayList<>();
        for (CardResponse card : cards) {
            // Check if this card is active
            if (card.status != CardResponse.Status.ACTIVE) {
                continue;
            }
            userCards.add(card.cardNumber);
            String prefix = (card.cardType == CardResponse.CardType.CREDIT ? "Kredit" : "EC-");
            stringBuilder.append(prefix + "karte mit den Endziffern <say-as interpret-as=\"digits\">" + card.cardNumber.substring(card.cardNumber.length() - 4) + "</say-as>. ");
        }
        // Store all card numbers in the session
        storage.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 : CardResponse(model.banking.account.CardResponse) ArrayList(java.util.ArrayList) Reprompt(com.amazon.speech.ui.Reprompt) PlainTextOutputSpeech(com.amazon.speech.ui.PlainTextOutputSpeech) SsmlOutputSpeech(com.amazon.speech.ui.SsmlOutputSpeech)

Example 20 with Reprompt

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

the class ReplacementCardDialog method askForConfirmation.

private SpeechletResponse askForConfirmation(Intent intent, SessionStorage.Storage storage) {
    if (!storage.containsKey(STORAGE_SELECTED_CARD)) {
        return askForCardNumber(storage, true);
    }
    String replacementReason = intent.getSlot("ReplacementReason").getValue();
    logger.info("Replacement reason: " + replacementReason);
    if (replacementReason.equals("beschaedigt")) {
        logger.info("Beschädigt");
        storage.put(STORAGE_REASON, ReplacementReason.DAMAGED);
    } else if (replacementReason.equals("gesperrt")) {
        logger.info("Gesperrt");
        storage.put(STORAGE_REASON, ReplacementReason.BLOCKED);
    } else {
        return askIfBlockedOrDamaged(intent, storage);
    }
    SsmlOutputSpeech speech = new SsmlOutputSpeech();
    String reason = storage.get(STORAGE_REASON) == ReplacementReason.DAMAGED ? "beschädigte" : "gesperrte";
    String lastDigits = (String) storage.get(STORAGE_SELECTED_CARD);
    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