Search in sources :

Example 11 with Session

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

the class PeriodicTransactionService method onIntent.

@Override
public SpeechletResponse onIntent(SpeechletRequestEnvelope<IntentRequest> requestEnvelope) throws SpeechletException {
    Intent intent = requestEnvelope.getRequest().getIntent();
    String intentName = intent.getName();
    Session session = requestEnvelope.getSession();
    LOGGER.info("Intent Name: " + intentName);
    String context = (String) session.getAttribute(DIALOG_CONTEXT);
    if (PERIODIC_TRANSACTION_LIST_INTENT.equals(intentName)) {
        session.setAttribute(DIALOG_CONTEXT, intentName);
        markPeriodicTransactions();
        return listPeriodicTransactions(session);
    } else if (PERIODIC_TRANSACTION_ADD_INTENT.equals(intentName)) {
        session.setAttribute(DIALOG_CONTEXT, intentName);
        return savePeriodicTransaction(intent, session, false);
    } else if (context != null && context.equals(PERIODIC_TRANSACTION_LIST_INTENT) && YES_INTENT.equals(intentName)) {
        return listNextTransactions(session);
    } else if (context != null && context.equals(PERIODIC_TRANSACTION_LIST_INTENT) && NO_INTENT.equals(intentName)) {
        return getResponse(PERIODIC_TRANSACTION, "Okay, tschuess!");
    } else if (context != null && context.equals(PERIODIC_TRANSACTION_ADD_INTENT) && YES_INTENT.equals(intentName)) {
        return savePeriodicTransaction(intent, session, true);
    } else if (context != null && context.equals(PERIODIC_TRANSACTION_ADD_INTENT) && NO_INTENT.equals(intentName)) {
        return getResponse(PERIODIC_TRANSACTION, "Okay, tschuess!");
    } else if (PERIODIC_TRANSACTION_DELETE_INTENT.equals(intentName)) {
        session.setAttribute(DIALOG_CONTEXT, intentName);
        return deletePeriodicTransaction(intent, session, false);
    } else if (context != null && context.equals(PERIODIC_TRANSACTION_DELETE_INTENT) && YES_INTENT.equals(intentName)) {
        return deletePeriodicTransaction(intent, session, true);
    } else if (context != null && context.equals(PERIODIC_TRANSACTION_DELETE_INTENT) && NO_INTENT.equals(intentName)) {
        return getResponse(PERIODIC_TRANSACTION, "Okay, tschuess!");
    } else {
        throw new SpeechletException("Unhandled intent: " + intentName);
    }
}
Also used : SpeechletException(com.amazon.speech.speechlet.SpeechletException) Intent(com.amazon.speech.slu.Intent) Session(com.amazon.speech.speechlet.Session)

Example 12 with Session

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

the class SecuritiesAccountInformationService method onIntent.

@Override
public SpeechletResponse onIntent(SpeechletRequestEnvelope<IntentRequest> requestEnvelope) throws SpeechletException {
    IntentRequest request = requestEnvelope.getRequest();
    Session session = requestEnvelope.getSession();
    String intentName = request.getIntent().getName();
    LOGGER.info("Intent Name: " + intentName);
    String context = (String) session.getAttribute(DIALOG_CONTEXT);
    if (SECURITIES_ACCOUNT_INFORMATION_INTENT.equals(intentName)) {
        LOGGER.info(getClass().toString() + " Intent started: " + intentName);
        session.setAttribute(DIALOG_CONTEXT, intentName);
        return getSecuritiesAccountInformation(session);
    }
    if (YES_INTENT.equals(intentName) && context != null && context.equals(SECURITIES_ACCOUNT_INFORMATION_INTENT)) {
        return getNextSecuritiesAccountInformation(request.getIntent(), session);
    } else if (NO_INTENT.equals(intentName) && context != null && context.equals(SECURITIES_ACCOUNT_INFORMATION_INTENT)) {
        return getResponse(SECURITIES_ACCOUNT_INFORMATION, "Okay, tschuess!");
    } else {
        throw new SpeechletException("Unhandled intent: " + intentName);
    }
}
Also used : IntentRequest(com.amazon.speech.speechlet.IntentRequest) SpeechletException(com.amazon.speech.speechlet.SpeechletException) Session(com.amazon.speech.speechlet.Session)

Example 13 with Session

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

the class TransferTemplateService method onIntent.

@Override
public SpeechletResponse onIntent(SpeechletRequestEnvelope<IntentRequest> requestEnvelope) {
    IntentRequest request = requestEnvelope.getRequest();
    Session session = requestEnvelope.getSession();
    String intentName = request.getIntent().getName();
    if (YES_INTENT.equals(intentName)) {
        Integer offset = (Integer) session.getAttribute("TransferTemplateService.offset");
        Integer templateId = (Integer) session.getAttribute("TransferTemplateService.delete");
        Integer editTemplateId = (Integer) session.getAttribute("TransferTemplateService.editTemplateId");
        if (offset != null) {
            return tellTemplates(session, offset, 3);
        }
        if (templateId != null) {
            TransferTemplate transferTemplate = new TransferTemplate(templateId);
            DynamoDbClient.instance.deleteItem(TransferTemplate.TABLE_NAME, transferTemplate);
            return getResponse(TRANSFER_TEMPLATES, "Vorlage wurde gelöscht.");
        }
        if (editTemplateId != null) {
            Double newAmount = Double.parseDouble(session.getAttribute("TransferTemplateService.newAmount").toString());
            TransferTemplate transferTemplate = (TransferTemplate) DynamoDbClient.instance.getItem(TransferTemplate.TABLE_NAME, editTemplateId, TransferTemplate::new);
            transferTemplate.setAmount(newAmount);
            DynamoDbClient.instance.putItem(TransferTemplate.TABLE_NAME, transferTemplate);
            return getResponse(TRANSFER_TEMPLATES, "Vorlage wurde erfolgreich gespeichert.");
        }
    } else if (NO_INTENT.equals(intentName)) {
        if (session.getAttribute("TransferTemplateService.offset") != null || session.getAttribute("TransferTemplateService.delete") != null || session.getAttribute("TransferTemplateService.editTemplateId") != null || session.getAttribute("TransferTemplateService.newAmount") != null) {
            return getResponse(TRANSFER_TEMPLATES, "Okay, dann halt nicht. Tschüss!");
        }
    } else if (LIST_TRANSFER_TEMPLATES_INTENT.equals(intentName)) {
        return tellTemplates(session, 0, 3);
    } else if (DELETE_TRANSFER_TEMPLATES_INTENT.equals(intentName)) {
        String templateIdStr = request.getIntent().getSlot("TemplateID").getValue();
        if (templateIdStr == null || templateIdStr.equals("")) {
            return null;
        } else {
            int templateId = Integer.parseInt(templateIdStr);
            session.setAttribute("TransferTemplateService.delete", templateId);
            return getAskResponse(TRANSFER_TEMPLATES, "Möchtest du Vorlage Nummer " + templateId + " wirklich löschen?");
        }
    } else if (EDIT_TRANSFER_TEMPLATE_INTENT.equals(intentName)) {
        String templateIdStr = request.getIntent().getSlot("TemplateID").getValue();
        String newAmountStr = request.getIntent().getSlot("NewAmount").getValue();
        if (templateIdStr == null || templateIdStr.equals("") || newAmountStr == null || newAmountStr.equals("")) {
            return null;
        } else {
            int templateId = Integer.parseInt(templateIdStr);
            TransferTemplate template = (TransferTemplate) DynamoDbClient.instance.getItem(TransferTemplate.TABLE_NAME, templateId, TransferTemplate::new);
            if (template == null) {
                return getResponse(TRANSFER_TEMPLATES, "Ich kann Vorlage " + templateId + " nicht finden.");
            }
            double newAmount = 0;
            try {
                newAmount = Double.parseDouble(newAmountStr);
            } catch (NumberFormatException ignored) {
            // TODO: Maybe do some error handling here
            }
            session.setAttribute("TransferTemplateService.editTemplateId", templateId);
            session.setAttribute("TransferTemplateService.newAmount", newAmount);
            return getAskResponse(TRANSFER_TEMPLATES, "Möchtest du den Betrag von Vorlage " + templateId + " von " + template.getAmount() + " auf " + newAmount + " ändern?");
        }
    }
    return null;
}
Also used : IntentRequest(com.amazon.speech.speechlet.IntentRequest) TransferTemplate(model.banking.TransferTemplate) Session(com.amazon.speech.speechlet.Session)

Aggregations

Session (com.amazon.speech.speechlet.Session)13 Intent (com.amazon.speech.slu.Intent)9 SpeechletException (com.amazon.speech.speechlet.SpeechletException)6 IntentRequest (com.amazon.speech.speechlet.IntentRequest)4 SessionStorage (amosalexa.SessionStorage)1 Slot (com.amazon.speech.slu.Slot)1 Map (java.util.Map)1 Account (model.banking.Account)1 TransferTemplate (model.banking.TransferTemplate)1 Account (model.banking.account.Account)1 Category (model.db.Category)1 User (model.db.User)1