Search in sources :

Example 16 with Slot

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

the class BudgetTrackerService method getCategoryStatusInfo.

private SpeechletResponse getCategoryStatusInfo(Intent intent) {
    Map<String, Slot> slots = intent.getSlots();
    Slot categorySlot = slots.get(CATEGORY);
    LOGGER.info("Category: " + categorySlot.getValue());
    // DynamoDbClient.instance.getItems(Category.TABLE_NAME, Category::new);
    List<Category> categories = DynamoDbMapper.getInstance().loadAll(Category.class);
    LOGGER.info("All categories: " + categories);
    Category category = null;
    for (Category cat : categories) {
        if (cat.getName().equals(categorySlot.getValue())) {
            category = cat;
        }
    }
    if (category != null) {
        double spending = category.getSpending();
        long percentage = Math.round(spending / category.getLimit() * 100);
        double remaining = category.getLimit() - spending > 0 ? category.getLimit() - spending : 0;
        String response = "Du hast bereits " + percentage + "% des Limits von " + category.getLimit() + " Euro fuer" + " die Kategorie " + category.getName() + " ausgegeben. " + "Du kannst noch " + remaining + " Euro für diese Kategorie ausgeben.";
        return getResponse(BUDGET_TRACKER, response);
    } else
        return getAskResponse(BUDGET_TRACKER, "Es gibt keine Kategorie mit diesem Namen. Waehle eine andere Kategorie oder" + " erhalte eine Info zu den verfuegbaren Kategorien.");
}
Also used : Category(model.db.Category) Slot(com.amazon.speech.slu.Slot)

Example 17 with Slot

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

the class BudgetTrackerService method getCategoryLimitInfo.

private SpeechletResponse getCategoryLimitInfo(Intent intent) {
    Map<String, Slot> slots = intent.getSlots();
    Slot categorySlot = slots.get(CATEGORY);
    LOGGER.info("Category: " + categorySlot.getValue());
    // DynamoDbClient.instance.getItems(Category.TABLE_NAME, Category::new);
    List<Category> categories = DynamoDbMapper.getInstance().loadAll(Category.class);
    LOGGER.info("All categories: " + categories);
    Category category = null;
    for (Category cat : categories) {
        if (cat.getName().equals(categorySlot.getValue())) {
            category = cat;
        }
    }
    if (category != null) {
        return getResponse(BUDGET_TRACKER, "Das Limit fuer die Kategorie " + categorySlot.getValue() + " liegt bei " + Double.valueOf(category.getLimit()) + " Euro.");
    } else {
        return getAskResponse(BUDGET_TRACKER, "Es gibt keine Kategorie mit diesem Namen. Waehle eine andere Kategorie oder" + " erhalte eine Info zu den verfuegbaren Kategorien.");
    }
}
Also used : Category(model.db.Category) Slot(com.amazon.speech.slu.Slot)

Example 18 with Slot

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

the class BudgetTrackerService method saveSpendingAmountForCategory.

private SpeechletResponse saveSpendingAmountForCategory(Intent intent, Session session, boolean isConfirmation) {
    Map<String, Slot> slots = intent.getSlots();
    Slot spendingSlot = slots.get(AMOUNT);
    Slot categorySlot = slots.get(CATEGORY);
    if (!isConfirmation) {
        if (spendingSlot == null) {
            return getAskResponse(BUDGET_TRACKER, "Das habe ich nicht ganz verstanden. Bitte wiederhole deine Eingabe");
        }
        if (categorySlot == null) {
            return getAskResponse(BUDGET_TRACKER, "Fuer welche Kategorie soll ich diesen Betrag notieren?");
        }
        session.setAttribute(AMOUNT, spendingSlot.getValue());
        session.setAttribute(CATEGORY, categorySlot.getValue());
    }
    String spendingAmount = isConfirmation ? (String) session.getAttribute(AMOUNT) : spendingSlot.getValue();
    String categoryName = isConfirmation ? (String) session.getAttribute(CATEGORY) : categorySlot.getValue();
    // DynamoDbClient.instance.getItems(Category.TABLE_NAME, Category::new);
    List<Category> categories = DynamoDbMapper.getInstance().loadAll(Category.class);
    Category category = null;
    for (Category cat : categories) {
        // TODO duplicate. write find and update category method
        if (cat.getName().equals(categoryName)) {
            category = cat;
        }
    }
    if (category != null) {
        // LOGGER.info("Category spending before: " + category.getSpending());
        // LOGGER.info("Add spending for category " + spendingAmount);
        double newSpending = category.getSpending() + Double.valueOf(spendingAmount);
        if (!isConfirmation && newSpending > category.getLimit()) {
            // Fallback if the user is about to exceed the limit
            return getAskResponse(BUDGET_TRACKER, "Warnung! Durch diese Aktion wirst du das Limit von " + Math.round(category.getLimit()) + " fuer die Kategorie " + categoryName + " ueberschreiten. Soll ich den" + " Betrag trotzdem notieren?");
        }
        // Create new spending in DB
        BudgetManager.instance.createSpending(AccountData.ACCOUNT_DEFAULT, category.getId(), Double.valueOf(spendingAmount));
    // DynamoDbClient.instance.putItem(Category.TABLE_NAME, category);
    // LOGGER.info("Category spending afterwards: " + category.getSpending());
    } else {
        // Ask for category creation
        session.setAttribute("categoryAmount", spendingAmount);
        session.setAttribute("categoryName", categoryName);
        session.setAttribute(WITHIN_DIALOG_CONTEXT, "createCategory");
        return getAskResponse(BUDGET_TRACKER, "Ich konnte diese Kategorie nicht finden. Soll ich eine Kategorie" + " mit dem Namen " + categoryName + " anlegen und den Betrag hinzufuegen?");
    }
    String speechResponse = "";
    Long spendingPercentage = category.getSpendingPercentage();
    LOGGER.info("SpendingPercentage: " + spendingPercentage);
    if (spendingPercentage >= 90) {
        // TODO SSML
        speechResponse = speechResponse + " Warnung! Du hast in diesem Monat bereits " + Math.round(category.getSpending()) + " Euro fuer " + category.getName() + " ausgegeben. Das sind " + spendingPercentage + "% des Limits fuer diese Kategorie.";
    }
    speechResponse = "Okay. Ich habe " + spendingAmount + " Euro fuer " + categoryName + " notiert." + speechResponse;
    return getResponse(BUDGET_TRACKER, speechResponse);
}
Also used : Category(model.db.Category) Slot(com.amazon.speech.slu.Slot)

Example 19 with Slot

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

the class BudgetTrackerService method saveSlotValuesAndAskForConfirmation.

private SpeechletResponse saveSlotValuesAndAskForConfirmation(Intent intent, Session session) {
    Map<String, Slot> slots = intent.getSlots();
    Slot categorySlot = slots.get(CATEGORY);
    Slot categoryLimitSlot = slots.get(CATEGORY_LIMIT);
    if (categorySlot == null || categoryLimitSlot == null || StringUtils.isBlank(categorySlot.getValue()) || StringUtils.isBlank(categoryLimitSlot.getValue())) {
        return getAskResponse(BUDGET_TRACKER, "Das habe ich nicht ganz verstanden, bitte wiederhole deine Eingabe.");
    } else {
        session.setAttribute(CATEGORY, categorySlot.getValue());
        session.setAttribute(CATEGORY_LIMIT, categoryLimitSlot.getValue());
        return askForConfirmation(categorySlot.getValue(), categoryLimitSlot.getValue());
    }
}
Also used : Slot(com.amazon.speech.slu.Slot)

Example 20 with Slot

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

the class EditCategoriesService method addNewCategory.

/**
 * @param intent
 * @param session
 * @return
 */
private SpeechletResponse addNewCategory(Intent intent, Session session, boolean confirmed) {
    String intentName = intent.getName();
    LOGGER.info("Intent Name: " + intentName);
    if (!confirmed) {
        Slot categoryNameSlot = intent.getSlot("CategoryName");
        if (contains(categoryNameSlot.getValue()) == true) {
            return getResponse(SERVICE_CARD_TITLE, "Diese Kategorie existiert bereits.");
        }
        session.setAttribute(DIALOG_CONTEXT, ADD_CATEGORY_INTENT);
        SessionStorage.getInstance().putObject(session.getSessionId(), SERVICE_CARD_TITLE + ".categoryName", categoryNameSlot.getValue());
        return getAskResponse(SERVICE_CARD_TITLE, "Moechtest du die Kategorie " + categoryNameSlot.getValue() + " wirklich erstellen?");
    } else {
        String slotName = (String) SessionStorage.getInstance().getObject(session.getSessionId(), SERVICE_CARD_TITLE + ".categoryName");
        Category item = new Category(slotName);
        DynamoDbMapper.getInstance().save(item);
        return getResponse(SERVICE_CARD_TITLE, "Verstanden. Die Kategorie " + slotName + " wurde erstellt.");
    }
}
Also used : Category(model.db.Category) Slot(com.amazon.speech.slu.Slot)

Aggregations

Slot (com.amazon.speech.slu.Slot)22 Reprompt (com.amazon.speech.ui.Reprompt)10 PlainTextOutputSpeech (com.amazon.speech.ui.PlainTextOutputSpeech)8 SimpleCard (com.amazon.speech.ui.SimpleCard)4 Category (model.db.Category)4 SsmlOutputSpeech (com.amazon.speech.ui.SsmlOutputSpeech)3 StandingOrder (model.banking.StandingOrder)3 ApiHelper (amosalexa.ApiHelper)1 SessionStorage (amosalexa.SessionStorage)1 Item (amosalexa.services.pricequery.aws.model.Item)1 Offer (amosalexa.services.pricequery.aws.model.Offer)1 Intent (com.amazon.speech.slu.Intent)1 Session (com.amazon.speech.speechlet.Session)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