Search in sources :

Example 1 with Card

use of model.banking.Card in project amos-ss17-alexa by c-i-ber.

the class ReplacementCardService method askForCardNumber.

private SpeechletResponse askForCardNumber(Session session, boolean errored) {
    // TODO: Load account from session
    Collection<Card> cards = AccountAPI.getCardsForAccount(ACCOUNT_NUMBER);
    if (cards.size() == 0) {
        // This user does not have any cards, ordering a replacement card is impossible.
        PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
        speech.setText("Es wurden keine Kredit- oder EC-Karten gefunden.");
        return SpeechletResponse.newTellResponse(speech);
    } else {
        SsmlOutputSpeech speech = new SsmlOutputSpeech();
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("<speak>");
        if (errored) {
            stringBuilder.append("Entschuldigung, das habe ich nicht verstanden. ");
        }
        stringBuilder.append("Bestellung einer Ersatzkarte. Es wurden folgende Karten gefunden: ");
        List<Card> userCards = new ArrayList<>();
        for (Card card : cards) {
            // Check if this card is active
            if (card.getStatus() != Card.Status.ACTIVE) {
                continue;
            }
            userCards.add(card);
            String prefix = (card.getCardType() == Card.CardType.CREDIT ? "Kredit" : "EC-");
            stringBuilder.append(prefix + "karte mit den Endziffern <say-as interpret-as=\"digits\">" + card.getCardNumber().substring(card.getCardNumber().length() - 4) + "</say-as>. ");
        }
        // Store all card numbers in the session
        SessionStorage.getInstance().getStorage(session.getSessionId()).put(STORAGE_VALID_CARDS, userCards);
        stringBuilder.append("Bitte gib die Endziffern der Karte an, für die du Ersatz benötigst.");
        stringBuilder.append("</speak>");
        speech.setSsml(stringBuilder.toString());
        // Create reprompt
        Reprompt reprompt = new Reprompt();
        reprompt.setOutputSpeech(speech);
        return SpeechletResponse.newAskResponse(speech, reprompt);
    }
}
Also used : ArrayList(java.util.ArrayList) Reprompt(com.amazon.speech.ui.Reprompt) PlainTextOutputSpeech(com.amazon.speech.ui.PlainTextOutputSpeech) SsmlOutputSpeech(com.amazon.speech.ui.SsmlOutputSpeech) Card(model.banking.Card)

Example 2 with Card

use of model.banking.Card in project amos-ss17-alexa by c-i-ber.

the class ReplacementCardService method askIfBlockedOrDamaged.

private SpeechletResponse askIfBlockedOrDamaged(Intent intent, Session session) {
    String fourDigits = intent.getSlot("Number").getValue();
    LOGGER.info("Digits: " + fourDigits);
    boolean validDigits = false;
    // Check if these digits are valid
    List<Card> userCards = (List<Card>) SessionStorage.getInstance().getStorage(session.getSessionId()).get(STORAGE_VALID_CARDS);
    for (Card card : userCards) {
        String cardNumber = card.getCardNumber();
        if (cardNumber.substring(cardNumber.length() - 4).equals(fourDigits)) {
            // Digits are valid
            session.setAttribute(STORAGE_SELECTED_CARD_NUMBER, cardNumber);
            session.setAttribute(STORAGE_SELECTED_CARD_ID, card.getCardId());
            validDigits = true;
            break;
        }
    }
    // If these are invalid digits, ask again
    if (!validDigits) {
        return askForCardNumber(session, true);
    }
    PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
    speech.setText("Wurde die Karte gesperrt oder wurde sie beschädigt?");
    // Create reprompt
    Reprompt reprompt = new Reprompt();
    reprompt.setOutputSpeech(speech);
    return SpeechletResponse.newAskResponse(speech, reprompt);
}
Also used : Reprompt(com.amazon.speech.ui.Reprompt) ArrayList(java.util.ArrayList) List(java.util.List) PlainTextOutputSpeech(com.amazon.speech.ui.PlainTextOutputSpeech) Card(model.banking.Card)

Example 3 with Card

use of model.banking.Card in project amos-ss17-alexa by c-i-ber.

the class AccountAPI method getCardsForAccount.

/**
 * Get all cards (credit / debit) for the given account.
 *
 * @param accountNumber Account number
 * @return Collection of Cards
 * @throws HttpClientErrorException
 */
public static Collection<Card> getCardsForAccount(String accountNumber) throws HttpClientErrorException {
    // TODO: Create a generic method for getting embedded JSON-HAL collections (in BankingRESTClient)
    Traverson traverson = null;
    try {
        traverson = new Traverson(new URI(BankingRESTClient.BANKING_API_ENDPOINT + BankingRESTClient.BANKING_API_BASEURL_V2 + "/accounts/" + accountNumber + "/cards"), MediaTypes.HAL_JSON);
    } catch (URISyntaxException e) {
        log.error("getCardsForAccount failed", e);
        return null;
    }
    ParameterizedTypeReference<Resources<Card>> typeRefDevices = new ParameterizedTypeReference<Resources<Card>>() {
    };
    Resources<Card> resResponses = traverson.follow(rel("$._links.self.href")).withHeaders(bankingRESTClient.generateHttpHeaders()).toObject(typeRefDevices);
    return resResponses.getContent();
}
Also used : Traverson(org.springframework.hateoas.client.Traverson) ParameterizedTypeReference(org.springframework.core.ParameterizedTypeReference) URISyntaxException(java.net.URISyntaxException) Resources(org.springframework.hateoas.Resources) URI(java.net.URI) Card(model.banking.Card)

Example 4 with Card

use of model.banking.Card in project amos-ss17-alexa by c-i-ber.

the class AccountAPI method createCardForAccount.

/**
 * Create card.
 *
 * @param accountNumber  the account number
 * @param cardType       the card type
 * @param cardNumber     the card number
 * @param status         the status
 * @param expirationDate the expiration date
 * @return the card
 */
public static Card createCardForAccount(String accountNumber, Card.CardType cardType, String cardNumber, Card.Status status, String expirationDate) {
    Card newCard = new Card();
    newCard.setCardType(cardType);
    newCard.setCardNumber(cardNumber);
    newCard.setStatus(status);
    newCard.setExpirationDate(expirationDate);
    return createCardForAccount(accountNumber, newCard);
}
Also used : Card(model.banking.Card)

Example 5 with Card

use of model.banking.Card in project amos-ss17-alexa by c-i-ber.

the class AmosAlexaSimpleTestImpl method replacementCardDialogTest.

@Test
public void replacementCardDialogTest() throws Exception {
    newSession();
    final String accountNumber = AmosAlexaSpeechlet.ACCOUNT_ID;
    Collection<Card> cards = AccountAPI.getCardsForAccount(accountNumber);
    for (Card card : cards) {
        AccountAPI.deleteCard(accountNumber, card.getCardId());
    }
    AccountAPI.createCardForAccount(accountNumber, Card.CardType.DEBIT, accountNumber, Card.Status.ACTIVE, new DateTime(2018, 5, 1, 12, 0).toLocalDate().toString());
    ArrayList<String> possibleAnswers = new ArrayList<String>() {

        {
            add("Bestellung einer Ersatzkarte. Es wurden folgende Karten gefunden: (.*)");
            add("Es wurden keine Kredit- oder EC-Karten gefunden.");
        }
    };
    String response = testIntentMatches("ReplacementCardIntent", StringUtils.join(possibleAnswers, "|"));
    Pattern p = Pattern.compile("karte mit den Endziffern ([0-9]+)\\.");
    Matcher m = p.matcher(response);
    if (m.find()) {
        String endDigits = m.group(1);
        testIntent("PlainNumberIntent", "Number:" + endDigits, "Wurde die Karte gesperrt oder wurde sie beschädigt?");
        testIntent("ReplacementCardReasonIntent", "ReplacementReason:beschaedigt", "Soll ein Ersatz für die beschädigte Karte mit den Endziffern " + endDigits + " bestellt werden?");
        testIntent("AMAZON.YesIntent", "Okay, eine Ersatzkarte wurde bestellt.");
    } else {
        fail("Cannot find credit card.");
    }
    newSession();
    response = testIntentMatches("ReplacementCardIntent", StringUtils.join(possibleAnswers, "|"));
    p = Pattern.compile("karte mit den Endziffern ([0-9]+)\\.");
    m = p.matcher(response);
    if (m.find()) {
        String endDigits = m.group(1);
        testIntent("PlainNumberIntent", "Number:" + endDigits, "Wurde die Karte gesperrt oder wurde sie beschädigt?");
        testIntent("ReplacementCardReasonIntent", "ReplacementReason:gesperrt", "Soll ein Ersatz für die gesperrte Karte mit den Endziffern " + endDigits + " bestellt werden?");
        testIntent("AMAZON.NoIntent", "");
    } else {
        fail("Cannot find credit card.");
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) DateTime(org.joda.time.DateTime) Card(model.banking.Card) Test(org.junit.Test)

Aggregations

Card (model.banking.Card)6 PlainTextOutputSpeech (com.amazon.speech.ui.PlainTextOutputSpeech)2 Reprompt (com.amazon.speech.ui.Reprompt)2 ArrayList (java.util.ArrayList)2 DateTime (org.joda.time.DateTime)2 Test (org.junit.Test)2 SsmlOutputSpeech (com.amazon.speech.ui.SsmlOutputSpeech)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 List (java.util.List)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 ParameterizedTypeReference (org.springframework.core.ParameterizedTypeReference)1 Resources (org.springframework.hateoas.Resources)1 Traverson (org.springframework.hateoas.client.Traverson)1