示例#1
0
    def validate_payment_amount(
        self,
        value: Text,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: Dict[Text, Any],
    ) -> Dict[Text, Any]:
        """Validate payment amount value."""

        try:
            entity = get_entity_details(
                tracker, "amount-of-money"
            ) or get_entity_details(tracker, "number")
            amount_currency = parse_duckling_currency(entity)
            if not amount_currency:
                raise (TypeError)
            return amount_currency
        except (TypeError, AttributeError):
            pass
        if value and value.lower() in self.payment_amount_db():
            key = value.lower()
            amount = self.payment_amount_db().get(key)
            amount_type = f" (your {key})"
            return {
                "payment_amount": f"{amount:.2f}",
                "payment_amount_type": amount_type,
                "currency": "$",
            }

        else:
            dispatcher.utter_message(template="utter_no_payment_amount")
            return {"payment_amount": None}
示例#2
0
    async def validate_amount_of_money(
        self,
        value: Text,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: Dict[Text, Any],
    ) -> Dict[Text, Any]:
        """Validates value of 'amount-of-money' slot"""
        if not value:
            return {"amount-of-money": None}

        account_balance = profile_db.get_account_balance(tracker.sender_id)
        # check if user asked to pay the full or the minimum balance
        if type(value) is str:
            credit_card_name = tracker.get_slot("credit_card")
            if credit_card_name:
                credit_card = profile_db.get_credit_card(
                    tracker.sender_id, credit_card_name)
            else:
                credit_card = None
            balance_types = profile_db.list_balance_types()
            if value and value.lower() in balance_types:
                balance_type = value.lower()
                if not credit_card:
                    dispatcher.utter_message(
                        f"I see you'd like to pay the {balance_type}.")
                    return {"amount-of-money": balance_type}
                slots_to_set = self.amount_from_balance(
                    dispatcher, tracker, credit_card_name, balance_type)
                if float(slots_to_set.get("amount-of-money")) == 0:
                    dispatcher.utter_message(template="utter_nothing_due",
                                             **slots_to_set)
                    return {
                        "amount-of-money": None,
                        "credit_card": None,
                        "payment_amount_type": None,
                    }
                return slots_to_set

        try:
            entity = get_entity_details(
                tracker, "amount-of-money") or get_entity_details(
                    tracker, "number")
            amount_currency = parse_duckling_currency(entity)
            if not amount_currency:
                raise TypeError
            if account_balance < float(amount_currency.get("amount-of-money")):
                dispatcher.utter_message(template="utter_insufficient_funds")
                return {"amount-of-money": None}
            return amount_currency
        except (TypeError, AttributeError):
            pass

        dispatcher.utter_message(template="utter_no_payment_amount")
        return {"amount-of-money": None}
示例#3
0
 def validate_amount_of_money(
     self,
     value: Text,
     dispatcher: CollectingDispatcher,
     tracker: Tracker,
     domain: Dict[Text, Any],
 ) -> Dict[Text, Any]:
     try:
         entity = get_entity_details(
             tracker, "amount-of-money"
         ) or get_entity_details(tracker, "number")
         amount_currency = parse_duckling_currency(entity)
         if not amount_currency:
             raise (TypeError)
         return amount_currency
     except (TypeError, AttributeError):
         dispatcher.utter_message(template="utter_no_payment_amount")
         return {"amount_of_money": None}
示例#4
0
    def validate_payment_amount(
        self,
        value: Text,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: Dict[Text, Any],
    ) -> Dict[Text, Any]:
        """Validate payment amount value."""

        credit_card = tracker.get_slot("credit_card")
        cc_balance = tracker.get_slot("credit_card_balance")
        account_balance = float(tracker.get_slot("account_balance"))
        try:
            entity = get_entity_details(
                tracker, "amount-of-money"
            ) or get_entity_details(tracker, "number")
            amount_currency = parse_duckling_currency(entity)
            if not amount_currency:
                raise (TypeError)
            if account_balance < float(amount_currency.get("amount_of_money")):
                dispatcher.utter_message(template="utter_insufficient_funds")
                return {"payment_amount": None}
            return amount_currency
        except (TypeError, AttributeError):
            pass
        if value and value.lower() in cc_balance.get(credit_card.lower()):
            key = value.lower()
            amount = cc_balance.get(credit_card.lower()).get(key)
            amount_type = f" (your {key})"

            if account_balance < float(amount):
                dispatcher.utter_message(template="utter_insufficient_funds")
                return {"payment_amount": None}
            return {
                "payment_amount": f"{amount:.2f}",
                "payment_amount_type": amount_type,
                "currency": "$",
            }

        else:
            dispatcher.utter_message(template="utter_no_payment_amount")
            return {"payment_amount": None}
示例#5
0
 def validate_time(
     self,
     value: Text,
     dispatcher: CollectingDispatcher,
     tracker: Tracker,
     domain: Dict[Text, Any],
 ) -> Dict[Text, Any]:
     """Validate time value."""
     timeentity = get_entity_details(tracker, "time")
     parsedinterval = parse_duckling_time_as_interval(timeentity)
     if not parsedinterval:
         dispatcher.utter_message(template="utter_no_transactdate")
         return {"time": None}
     return parsedinterval
示例#6
0
 async def validate_amount_of_money(
     self,
     value: Text,
     dispatcher: CollectingDispatcher,
     tracker: Tracker,
     domain: Dict[Text, Any],
 ) -> Dict[Text, Any]:
     """Validates value of 'amount-of-money' slot"""
     account_balance = profile_db.get_account_balance(tracker.sender_id)
     try:
         entity = get_entity_details(
             tracker, "amount-of-money") or get_entity_details(
                 tracker, "number")
         amount_currency = parse_duckling_currency(entity)
         if not amount_currency:
             raise TypeError
         if account_balance < float(amount_currency.get("amount-of-money")):
             dispatcher.utter_message(template="utter_insufficient_funds")
             return {"amount-of-money": None}
         return amount_currency
     except (TypeError, AttributeError):
         dispatcher.utter_message(template="utter_no_payment_amount")
         return {"amount-of-money": None}
示例#7
0
 async def validate_time(
     self,
     value: Text,
     dispatcher: CollectingDispatcher,
     tracker: Tracker,
     domain: Dict[Text, Any],
 ) -> Dict[Text, Any]:
     """Validates value of 'time' slot"""
     timeentity = get_entity_details(tracker, "time")
     parsedtime = timeentity and parse_duckling_time(timeentity)
     if not parsedtime:
         dispatcher.utter_message(template="utter_no_transactdate")
         return {"time": None}
     return parsedtime
示例#8
0
 def validate_time_period(
     self,
     value: Text,
     dispatcher: CollectingDispatcher,
     tracker: Tracker,
     domain: Dict[Text, Any],
 ) -> Dict[Text, Any]:
     """Validate time value."""
     time_entity = get_entity_details(tracker, EntitySlotEnum.TIME)
     parsed_interval = parse_duckling_time_as_interval(time_entity)
     if not parsed_interval:
         dispatcher.utter_message(template=UtteranceEnum.INVALID)
         return {EntitySlotEnum.TIME_PERIOD: None}
     # Returns { EntitySlotEnum.START_TIME, EntitySlotEnum.END_TIME, EntitySlotEnum.GRAIN }
     return parsed_interval
    def validate_time(
        self,
        value: Text,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: Dict[Text, Any],
    ) -> Dict[Text, Any]:
        """Validate time value."""

        timeentity = get_entity_details(tracker, "time")
        parsedtime = parse_duckling_time(timeentity)
        # print(timeentity,parsedtime)
        if not parsedtime:
            dispatcher.utter_message(text="No time man!")
            return {"time": None}
        return parsedtime