Search in sources :

Example 1 with Reprompt

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

the class ReplacementCardDialog method askIfBlockedOrDamaged.

private SpeechletResponse askIfBlockedOrDamaged(Intent intent, SessionStorage.Storage storage) {
    String fourDigits = intent.getSlot("FourDigits").getValue();
    logger.info("Digits: " + fourDigits);
    boolean validDigits = false;
    // Check if these digits are valid
    List<String> userCards = (List<String>) storage.get(STORAGE_VALID_CARDS);
    for (String cardNumber : userCards) {
        if (cardNumber.substring(cardNumber.length() - 4).equals(fourDigits)) {
            // Digits are valid
            storage.put(STORAGE_SELECTED_CARD, cardNumber);
            validDigits = true;
            break;
        }
    }
    // If these are invalid digits, ask again
    if (!validDigits) {
        return askForCardNumber(storage, 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)

Example 2 with Reprompt

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

the class StandingOrderDialog method askForDDeletionConfirmation.

private SpeechletResponse askForDDeletionConfirmation(Intent intent, SessionStorage.Storage storage) {
    Map<String, Slot> slots = intent.getSlots();
    Slot numberSlot = slots.get("Number");
    LOGGER.info("NumberSlot: " + numberSlot.getValue());
    storage.put("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 3 with Reprompt

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

the class StandingOrderDialog method askForModificationConfirmation.

private SpeechletResponse askForModificationConfirmation(Intent intent, SessionStorage.Storage storage) {
    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");
    storage.put("StandingOrderToModify", numberSlot.getValue());
    storage.put("NewAmount", amountSlot.getValue());
    storage.put("NewExecutionRate", executionRateSlot.getValue());
    storage.put("NewFirstExecution", firstExecutionSlot.getValue());
    // Create the plain text output
    PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
    speech.setText("Moechtest du den Dauerauftrag mit der Nummer " + numberSlot.getValue() + " wirklich 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 4 with Reprompt

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

Example 5 with Reprompt

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

the class AmosAlexaSpeechlet method getAccountBalanceResponse.

/**
     * Creates and returns a {@code SpeechletResponse} with the current account balance.
     *
     * @return SpeechletResponse spoken and visual response for the given intent
     */
private SpeechletResponse getAccountBalanceResponse() {
    // This is just a dummy account balance. Will be replaced by an API.
    // TODO: Implement GetAccountBalance with real data.
    double accountBalance = 47.11;
    String speechText = "Your account balance is " + Double.toString(accountBalance);
    // Create the Simple card content.
    SimpleCard card = new SimpleCard();
    card.setTitle("AccountBalance");
    card.setContent(speechText);
    // Create the plain text output.
    PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
    speech.setText(speechText);
    // Create reprompt
    Reprompt reprompt = new Reprompt();
    reprompt.setOutputSpeech(speech);
    return SpeechletResponse.newAskResponse(speech, reprompt, card);
}
Also used : SimpleCard(com.amazon.speech.ui.SimpleCard) Reprompt(com.amazon.speech.ui.Reprompt) PlainTextOutputSpeech(com.amazon.speech.ui.PlainTextOutputSpeech)

Aggregations

Reprompt (com.amazon.speech.ui.Reprompt)19 PlainTextOutputSpeech (com.amazon.speech.ui.PlainTextOutputSpeech)16 SimpleCard (com.amazon.speech.ui.SimpleCard)9 Slot (com.amazon.speech.slu.Slot)5 SsmlOutputSpeech (com.amazon.speech.ui.SsmlOutputSpeech)3 ArrayList (java.util.ArrayList)2 StandingOrder (model.banking.account.StandingOrder)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 LinkedList (java.util.LinkedList)1 List (java.util.List)1 CardResponse (model.banking.account.CardResponse)1 StandingOrderResponse (model.banking.account.StandingOrderResponse)1