File size: 844 Bytes
9a79634
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import random
from typing import Any, Text, Dict, List
from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher


class ActionCheckBalance(Action):
    def name(self) -> Text:
        return "action_check_balance"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
        
        balance = round(random.uniform(100, 10000), 2)
        formatted_balance = f"${balance:,.2f}"
        account_type = tracker.get_slot("account_type")
        
        if account_type:
            message = f"Your {account_type} account balance is {formatted_balance}."
        else:
            message = f"Your current balance is {formatted_balance}."
        
        dispatcher.utter_message(text=message)
        
        return []