use of com.amazon.speech.slu.Slot in project amos-ss17-alexa by c-i-ber.
the class StandingOrderService method getStandingOrdersInfoForKeyword.
private SpeechletResponse getStandingOrdersInfoForKeyword(Intent intent, Session session) {
Map<String, Slot> slots = intent.getSlots();
Slot standingOrderKeywordSlot = slots.get("StandingOrderKeyword");
Slot transactionKeywordSlot = slots.get("TransactionKeyword");
if ((standingOrderKeywordSlot == null || standingOrderKeywordSlot.getValue() == null) && (transactionKeywordSlot == null || transactionKeywordSlot.getValue() == null)) {
// TODO
return null;
}
String keyword = standingOrderKeywordSlot.getValue() != null ? standingOrderKeywordSlot.getValue() : transactionKeywordSlot.getValue();
LOGGER.info("Keyword: " + keyword);
if (keyword.equals("ersparnisse")) {
keyword = "sparplan regelm. einzahlung";
}
Collection<StandingOrder> standingOrdersCollection = AccountAPI.getStandingOrdersForAccount(ACCOUNT_NUMBER);
standingOrders = new ArrayList<>();
for (StandingOrder so : standingOrdersCollection) {
String description = so.getDescription().toLowerCase();
// LOGGER.info("Description: " + description);
if (!description.equals(keyword)) {
String[] singleWords = description.split("\\s+");
for (String s : singleWords) {
if (keyword.equals(s)) {
standingOrders.add(so);
continue;
}
double similarity = getStringSimilarity(s, keyword);
// 0.9 seems to be a good value for similarity
if (similarity >= 0.9) {
standingOrders.add(so);
}
}
} else {
standingOrders.add(so);
continue;
}
}
if (standingOrders.size() == 0) {
String answer = "Ich konnte keine Dauerauftraege finden, die zu diesem Stichwort passen.";
return getResponse(STANDING_ORDERS, answer);
}
double total = 0;
for (StandingOrder so : standingOrders) {
if (so.getExecutionRate().equals(StandingOrder.ExecutionRate.MONTHLY)) {
total += so.getAmount().doubleValue();
} else if (so.getExecutionRate().equals(StandingOrder.ExecutionRate.QUARTERLY)) {
total += so.getAmount().doubleValue() / 3;
} else if (so.getExecutionRate().equals(StandingOrder.ExecutionRate.HALF_YEARLY)) {
total += so.getAmount().doubleValue() / 6;
} else if (so.getExecutionRate().equals(StandingOrder.ExecutionRate.YEARLY)) {
total += so.getAmount().doubleValue() / 12;
}
}
StringBuilder builder = new StringBuilder();
builder.append("<speak>");
builder.append("Aus ").append(standingOrders.size() == 1 ? "<phoneme alphabet=\"ipa\" ph=\"ˈaɪ̯nəm\">einem</phoneme>" + " gefundenen Dauerauftrag " : standingOrders.size() + " gefundenen Dauerauftraegen ").append("konnte ich berechnen, dass du monatlich " + total + " Euro ").append(keyword.equals("sparplan regelm. einzahlung") ? "zum Sparen zuruecklegst. " : "fuer " + keyword + " bezahlst. ");
builder.append("Soll ich die gefundenen Dauerauftraege aufzaehlen? ");
builder.append("</speak>");
SsmlOutputSpeech speech = new SsmlOutputSpeech();
speech.setSsml(builder.toString());
// Create reprompt
Reprompt reprompt = new Reprompt();
reprompt.setOutputSpeech(speech);
return SpeechletResponse.newAskResponse(speech, reprompt);
}
use of com.amazon.speech.slu.Slot in project amos-ss17-alexa by c-i-ber.
the class StandingOrderService method askForModificationConfirmation.
private SpeechletResponse askForModificationConfirmation(Intent intent, Session session) {
Map<String, Slot> slots = intent.getSlots();
Slot numberSlot = slots.get("Number");
Slot amountSlot = slots.get("Amount");
Slot executionRateSlot = slots.get("ExecutionRate");
Slot firstExecutionSlot = slots.get("FirstExecution");
if (numberSlot.getValue() == null || (amountSlot.getValue() == null && executionRateSlot.getValue() == null && firstExecutionSlot.getValue() == null)) {
String text = "Das habe ich nicht ganz verstanden. Bitte wiederhole deine Eingabe.";
return getAskResponse(STANDING_ORDERS, text);
}
session.setAttribute("StandingOrderToModify", numberSlot.getValue());
session.setAttribute("NewAmount", amountSlot.getValue());
session.setAttribute("NewExecutionRate", executionRateSlot.getValue());
session.setAttribute("NewFirstExecution", firstExecutionSlot.getValue());
// Create the plain text output
PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
speech.setText("Soll ich den Betrag von Dauerauftrag Nummer " + numberSlot.getValue() + " wirklich auf " + amountSlot.getValue() + " Euro aendern?");
// Create reprompt
Reprompt reprompt = new Reprompt();
reprompt.setOutputSpeech(speech);
return SpeechletResponse.newAskResponse(speech, reprompt);
}
use of com.amazon.speech.slu.Slot in project amos-ss17-alexa by c-i-ber.
the class ContactService method askForNewContactConfirmation.
private SpeechletResponse askForNewContactConfirmation(Intent intent, Session session) {
Map<String, Slot> slots = intent.getSlots();
Slot transactionNumberSlot = slots.get("TransactionNumber");
if (transactionNumberSlot.getValue() == null || StringUtils.isBlank(transactionNumberSlot.getValue())) {
String speechText = "Das habe ich nicht ganz verstanden. Bitte wiederhole deine Eingabe.";
session.getAttributes().clear();
return getAskResponse(CONTACTS, speechText);
}
LOGGER.info("TransactionNumber: " + transactionNumberSlot.getValue());
String speechText = "";
List<Transaction> allTransactions = TransactionAPI.getTransactionsForAccount(AmosAlexaSpeechlet.ACCOUNT_ID);
Number transactionNumber = Integer.valueOf(transactionNumberSlot.getValue());
Transaction transaction = null;
for (Transaction t : allTransactions) {
if (transactionNumber.equals(t.getTransactionId())) {
transaction = t;
}
}
LOGGER.info("Found transaction: " + transaction);
if (transaction == null) {
speechText = "Ich habe keine Transaktion mit dieser Nummer gefunden. Bitte wiederhole deine Eingabe.";
session.getAttributes().clear();
return getAskResponse(CONTACTS, speechText);
}
LOGGER.info("Payee: " + transaction.getPayee());
LOGGER.info("Remitter: " + transaction.getRemitter());
String payee = transaction.getPayee();
String remitter = transaction.getRemitter();
String ibanRegex = ".*\\d+.*";
if ((payee == null && remitter == null) || (transaction.isOutgoing() && payee.matches(ibanRegex)) || (!transaction.isOutgoing() && remitter.matches(ibanRegex))) {
speechText = "Ich kann fuer diese Transaktion keine Kontaktdaten speichern, weil der Name des";
speechText = speechText.concat(transaction.isOutgoing() ? " Zahlungsempfaengers" : " Auftraggebers");
speechText = speechText.concat(" nicht bekannt ist. Bitte wiederhole deine Eingabe oder breche ab, indem du \"Alexa, Stop!\" sagst.");
session.getAttributes().clear();
return getAskResponse(CONTACTS, speechText);
} else {
// TODO improve
// Actually asking for confirmation
session.setAttribute("ContactName", transaction.isOutgoing() ? payee : remitter);
speechText = "Moechtest du ";
speechText = speechText.concat(transaction.isOutgoing() ? payee : remitter);
speechText = speechText.concat(" als Kontakt speichern?");
}
return getAskResponse(CONTACTS, speechText);
}
use of com.amazon.speech.slu.Slot in project amos-ss17-alexa by c-i-ber.
the class HelpService method getFunctionGroup.
private SpeechletResponse getFunctionGroup(Intent intent, Session session) {
Slot functionGroupSlot = intent.getSlot("FunctionGroup");
if (functionGroupSlot == null) {
return getResponse(INTRODUCTION, "Das sollte nicht passieren: ein interner Fehler ist aufgetreten.");
}
String functionGroup = functionGroupSlot.getValue();
if (functionGroup == null) {
return getResponse(INTRODUCTION, "Das habe ich nicht verstanden. Sprich deutlicher.");
}
FunctionGroup closestFunctionGroup = null;
int closestDist = Integer.MAX_VALUE;
for (FunctionGroup category : EnumSet.allOf(FunctionGroup.class)) {
String name = category.name.toLowerCase();
int dist = StringUtils.getLevenshteinDistance(name, functionGroup);
if (dist < closestDist) {
closestFunctionGroup = category;
closestDist = dist;
}
}
return getSSMLResponse(INTRODUCTION, getFunctionGroupInfo(closestFunctionGroup));
}
use of com.amazon.speech.slu.Slot 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);
}
Aggregations