Search in sources :

Example 6 with SimpleCard

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

the class AbstractSpeechService method getSimpleCard.

/**
     * Helper method that creates a card object.
     *
     * @param title   title of the card
     * @param content body of the card
     * @return SimpleCard the display card to be sent along with the voice response.
     */
protected SimpleCard getSimpleCard(String title, String content) {
    SimpleCard card = new SimpleCard();
    card.setTitle(title);
    card.setContent(content);
    return card;
}
Also used : SimpleCard(com.amazon.speech.ui.SimpleCard)

Example 7 with SimpleCard

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

the class StandingOrderService method getStandingOrdersModifyResponse.

private SpeechletResponse getStandingOrdersModifyResponse(Intent intent, Session session) {
    String standingOrderToModify = (String) session.getAttribute("StandingOrderToModify");
    String newAmount = (String) session.getAttribute("NewAmount");
    // TODO never used
    String newExecutionRate = (String) session.getAttribute("NewExecutionRate");
    String newFirstExecution = (String) session.getAttribute("NewFirstExecution");
    ObjectMapper mapper = new ObjectMapper();
    // Create the Simple card content.
    SimpleCard card = new SimpleCard();
    card.setTitle("Ändere Dauerauftrag");
    // Create the plain text output.
    PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
    Number standingOrderNum = Integer.parseInt(standingOrderToModify);
    StandingOrder standingOrder = AccountAPI.getStandingOrder(ACCOUNT_NUMBER, standingOrderNum);
    // TODO: Actually update the StandingOrder
    standingOrder.setAmount(Integer.parseInt(newAmount));
    AccountAPI.updateStandingOrder(ACCOUNT_NUMBER, standingOrder);
    card.setContent("Dauerauftrag Nummer " + standingOrderToModify + " wurde geändert.");
    speech.setText("Dauerauftrag Nummer " + standingOrderToModify + " wurde geaendert.");
    return SpeechletResponse.newTellResponse(speech, card);
}
Also used : StandingOrder(model.banking.StandingOrder) SimpleCard(com.amazon.speech.ui.SimpleCard) PlainTextOutputSpeech(com.amazon.speech.ui.PlainTextOutputSpeech) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 8 with SimpleCard

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

the class StandingOrderService method getStandingOrdersDeleteResponse.

private SpeechletResponse getStandingOrdersDeleteResponse(Intent intent, Session session) {
    LOGGER.info("StandingOrdersDeleteResponse called.");
    String standingOrderToDelete = (String) session.getAttribute("StandingOrderToDelete");
    // Create the Simple card content.
    SimpleCard card = new SimpleCard();
    card.setTitle("Lösche Dauerauftrag");
    // Create the plain text output.
    PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
    Number standingOrderNum = Integer.parseInt(standingOrderToDelete);
    if (!AccountAPI.deleteStandingOrder(ACCOUNT_NUMBER, standingOrderNum)) {
        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) PlainTextOutputSpeech(com.amazon.speech.ui.PlainTextOutputSpeech)

Example 9 with SimpleCard

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

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

the class StandingOrderService 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, Session session) {
    LOGGER.info("StandingOrdersResponse called.");
    Map<String, Slot> slots = intent.getSlots();
    Collection<StandingOrder> standingOrdersCollection = AccountAPI.getStandingOrdersForAccount(ACCOUNT_NUMBER);
    // Create the Simple card content.
    SimpleCard card = new SimpleCard();
    card.setTitle("Daueraufträge");
    // Create the plain text output.
    PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
    if (standingOrdersCollection == null || standingOrdersCollection.isEmpty()) {
        card.setContent("Keine Daueraufträge vorhanden.");
        speech.setText("Keine Dauerauftraege vorhanden.");
        return SpeechletResponse.newTellResponse(speech, card);
    }
    standingOrders = new ArrayList<>(standingOrdersCollection);
    // 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().toLowerCase().replace(" ", "").equals("email");
    StringBuilder builder = new StringBuilder();
    if (sendPerEmail) {
        StringBuilder standingOrderMailBody = new StringBuilder();
        for (StandingOrder so : standingOrders) {
            standingOrderMailBody.append(so.getSpeechOutput() + "\n");
        }
        EMailClient.SendEMail("Daueraufträge", standingOrderMailBody.toString());
        builder.append("Ich habe eine Übersicht deiner ").append(standingOrders.size()).append(" Daueraufträge an deine E-Mail-Adresse gesendet.");
    } else {
        // We want to directly return standing orders here
        Slot payeeSlot = slots.get("Payee");
        String payee = (payeeSlot == null ? null : payeeSlot.getValue());
        if (payee != null) {
            // User specified a recipient
            standingOrders.clear();
            // Find closest standing orders that could match the request.
            for (int i = 0; i < standingOrders.size(); i++) {
                if (StringUtils.getLevenshteinDistance(payee, standingOrders.get(i).getPayee()) <= standingOrders.get(i).getPayee().length() / 3) {
                    standingOrders.add(standingOrders.get(i));
                }
            }
            builder.append(standingOrders.size() == 1 ? "Es wurde ein Dauerauftrag gefunden. " : "Es wurden " + standingOrders.size() + " Dauerauftraege gefunden. ");
            for (int i = 0; i <= 1; i++) {
                builder.append(standingOrders.get(i).getSpeechOutput());
            }
            if (standingOrders.size() > 2) {
                return askForFurtherStandingOrderEntry(session, builder, 2);
            }
        } else {
            // Just return all standing orders
            builder.append("Du hast momentan ").append(standingOrders.size() == 1 ? "einen Dauerauftrag. " : standingOrders.size() + " Dauerauftraege. ");
            for (int i = 0; i <= 1; i++) {
                builder.append(standingOrders.get(i).getSpeechOutput());
            }
            if (standingOrders.size() > 2) {
                return askForFurtherStandingOrderEntry(session, builder, 2);
            }
        }
    }
    String text = builder.toString();
    card.setContent(text);
    speech.setText(text);
    return SpeechletResponse.newTellResponse(speech, card);
}
Also used : StandingOrder(model.banking.StandingOrder) SimpleCard(com.amazon.speech.ui.SimpleCard) Slot(com.amazon.speech.slu.Slot) 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