Search in sources :

Example 21 with PlainTextOutputSpeech

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

the class StandingOrderService method askForDDeletionConfirmation.

private SpeechletResponse askForDDeletionConfirmation(Intent intent, Session session) {
    Map<String, Slot> slots = intent.getSlots();
    Slot numberSlot = slots.get("Number");
    LOGGER.info("NumberSlot: " + numberSlot.getValue());
    session.setAttribute("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 22 with PlainTextOutputSpeech

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

Example 23 with PlainTextOutputSpeech

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

the class AmosAlexaSpeechlet method onIntent.

@Override
public SpeechletResponse onIntent(SpeechletRequestEnvelope<IntentRequest> requestEnvelope) {
    IntentRequest request = requestEnvelope.getRequest();
    Session session = requestEnvelope.getSession();
    LOGGER.info("onIntent requestId={}, sessionId={}", request.getRequestId(), session.getSessionId());
    Intent intent = request.getIntent();
    String intentName = (intent != null) ? intent.getName() : "";
    SessionStorage.Storage sessionStorage = SessionStorage.getInstance().getStorage(session.getSessionId());
    String currentDialogContext = (String) sessionStorage.get(SessionStorage.CURRENTDIALOG);
    LOGGER.info("Intent: " + intentName);
    LOGGER.info("DialogContext: " + currentDialogContext);
    if (intentName.equals(STOP_INTENT)) {
        return getResponse("Stop", "");
    }
    SpeechletResponse response = notifyOnIntent(requestEnvelope);
    if (response == null) {
        SessionStorage.getInstance().removeStorage(session.getSessionId());
        PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
        // speech.setText("Ein Fehler ist aufgetreten.");
        speech.setText("");
        return SpeechletResponse.newTellResponse(speech);
    }
    return response;
}
Also used : Intent(com.amazon.speech.slu.Intent) PlainTextOutputSpeech(com.amazon.speech.ui.PlainTextOutputSpeech)

Example 24 with PlainTextOutputSpeech

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

the class BankContactService method getPermissionsResponse.

/**
 * Creates a {@code SpeechletResponse} for permission requests.
 *
 * @return SpeechletResponse spoken and visual response for the given intent
 */
private SpeechletResponse getPermissionsResponse() {
    String speechText = "Dieser Skill hat keine Berechtigung auf deine Adresse " + "Gib bitte diesem Skill die Berechtigung auf deine Adresse zu zugreifen";
    AskForPermissionsConsentCard card = new AskForPermissionsConsentCard();
    card.setTitle(BANK_CONTACT_CARD);
    Set<String> permissions = new HashSet<>();
    permissions.add(ALL_ADDRESS_PERMISSION);
    card.setPermissions(permissions);
    PlainTextOutputSpeech speech = getPlainTextOutputSpeech(speechText);
    return SpeechletResponse.newTellResponse(speech, card);
}
Also used : PlainTextOutputSpeech(com.amazon.speech.ui.PlainTextOutputSpeech) AskForPermissionsConsentCard(com.amazon.speech.ui.AskForPermissionsConsentCard)

Example 25 with PlainTextOutputSpeech

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

the class ReplacementCardService method cancelDialog.

private SpeechletResponse cancelDialog() {
    PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
    speech.setText("");
    return SpeechletResponse.newTellResponse(speech);
}
Also used : PlainTextOutputSpeech(com.amazon.speech.ui.PlainTextOutputSpeech)

Aggregations

PlainTextOutputSpeech (com.amazon.speech.ui.PlainTextOutputSpeech)44 Reprompt (com.amazon.speech.ui.Reprompt)22 SimpleCard (com.amazon.speech.ui.SimpleCard)18 Slot (com.amazon.speech.slu.Slot)8 ArrayList (java.util.ArrayList)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 SsmlOutputSpeech (com.amazon.speech.ui.SsmlOutputSpeech)2 IOException (java.io.IOException)2 List (java.util.List)2 Card (model.banking.Card)2 StandingOrder (model.banking.account.StandingOrder)2 BankingRESTClient (api.BankingRESTClient)1 Intent (com.amazon.speech.slu.Intent)1 AskForPermissionsConsentCard (com.amazon.speech.ui.AskForPermissionsConsentCard)1 JSONObject (com.amazonaws.util.json.JSONObject)1 DateFormat (java.text.DateFormat)1