Search in sources :

Example 1 with SimpleCard

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

the class BankAccountService method getSpeechletResponse.

private SpeechletResponse getSpeechletResponse(String speechText) {
    SimpleCard card = new SimpleCard();
    card.setTitle(CARD_NAME);
    card.setContent(speechText);
    PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
    speech.setText(speechText);
    return SpeechletResponse.newTellResponse(speech, card);
}
Also used : SimpleCard(com.amazon.speech.ui.SimpleCard) PlainTextOutputSpeech(com.amazon.speech.ui.PlainTextOutputSpeech)

Example 2 with SimpleCard

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

the class StandingOrderDialog method getStandingOrdersDeleteResponse.

private SpeechletResponse getStandingOrdersDeleteResponse(Intent intent, SessionStorage.Storage storage) {
    LOGGER.info("StandingOrdersDeleteResponse called.");
    String standingOrderToDelete = (String) storage.get("StandingOrderToDelete");
    // Create the Simple card content.
    SimpleCard card = new SimpleCard();
    card.setTitle("Lösche Dauerauftrag");
    // Create the plain text output.
    PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
    ApiHelper helper = new ApiHelper();
    try {
        helper.sendDelete("http://amos-bank-lb-723794096.eu-central-1.elb.amazonaws.com/api/v1_0/accounts/9999999999/standingorders/" + standingOrderToDelete);
    } catch (Exception e) {
        LOGGER.error(e.getMessage());
        card.setContent("Dauerauftrag Nummer " + standingOrderToDelete + " wurde nicht gefunden.");
        speech.setText("Dauerauftrag Nummer " + standingOrderToDelete + " wurde nicht gefunden.");
        return SpeechletResponse.newTellResponse(speech, card);
    }
    card.setContent("Dauerauftrag Nummer " + standingOrderToDelete + " wurde gelöscht.");
    speech.setText("Dauerauftrag Nummer " + standingOrderToDelete + " wurde geloescht.");
    return SpeechletResponse.newTellResponse(speech, card);
}
Also used : SimpleCard(com.amazon.speech.ui.SimpleCard) ApiHelper(amosalexa.ApiHelper) PlainTextOutputSpeech(com.amazon.speech.ui.PlainTextOutputSpeech) JSONException(com.amazonaws.util.json.JSONException) IOException(java.io.IOException) SpeechletException(com.amazon.speech.speechlet.SpeechletException)

Example 3 with SimpleCard

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

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

the class PriceQueryService method getSpeechletResponse.

private SpeechletResponse getSpeechletResponse(String speechText, String repromptText) {
    // Create the Simple card content.
    SimpleCard card = new SimpleCard();
    card.setTitle("Price Query");
    card.setContent(speechText);
    // Create the plain text output.
    PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
    speech.setText(speechText);
    return SpeechletResponse.newTellResponse(speech, card);
}
Also used : SimpleCard(com.amazon.speech.ui.SimpleCard) PlainTextOutputSpeech(com.amazon.speech.ui.PlainTextOutputSpeech)

Example 5 with SimpleCard

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

SimpleCard (com.amazon.speech.ui.SimpleCard)20 PlainTextOutputSpeech (com.amazon.speech.ui.PlainTextOutputSpeech)18 Reprompt (com.amazon.speech.ui.Reprompt)10 Slot (com.amazon.speech.slu.Slot)4 StandingOrder (model.banking.StandingOrder)4 JSONException (com.amazonaws.util.json.JSONException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 ApiHelper (amosalexa.ApiHelper)2 SpeechletException (com.amazon.speech.speechlet.SpeechletException)2 IOException (java.io.IOException)2 BankingRESTClient (api.BankingRESTClient)1 Intent (com.amazon.speech.slu.Intent)1 Directive (com.amazon.speech.speechlet.Directive)1 IntentRequest (com.amazon.speech.speechlet.IntentRequest)1 SpeechletResponse (com.amazon.speech.speechlet.SpeechletResponse)1 AudioItem (com.amazon.speech.speechlet.interfaces.audioplayer.AudioItem)1 Stream (com.amazon.speech.speechlet.interfaces.audioplayer.Stream)1 PlayDirective (com.amazon.speech.speechlet.interfaces.audioplayer.directive.PlayDirective)1 JSONObject (com.amazonaws.util.json.JSONObject)1 DateFormat (java.text.DateFormat)1