Hi , I have a Intent “leave_balance” , withen which i have different types of leave like paid leave , sick leave etc , hence I have created a entity “leave_type” type : list . the Nlu is able to categorize different types of leaves . Not When the slot is set to sick leave i want to get only the sick leave balance from web service . please check my actions.py file below
class GetLeaveBalance(Action):
def name(self):
return 'get_leave_balance'
def run(self, dispatcher, tracker, domain):
#importing librires to connect with wsdl
from suds.client import Client
from suds.sax.element import Element
#specfying the wsdl url and setting the client
url = "http://devmobileapi.xxxxxxxxxxxxxxxxxxxx.in/API/xxxxxxxxxxxxxxxx.svc?wsdl"
client = Client(url)
#creating the headers for auth in service xml and setting the values for both API-key and API-Code
Namespace = ('ns2', 'http://xxxxxxxxxxxxxxxxxxxxxx.com/v1')
name_space = Element('APICode', ns=Namespace).setText('xxxxxxxxxxxxxxxxxxx')
Apikey =('ns2',"http://beehivehronline.com/v1")
api_key = Element('APIKey',ns= Apikey).setText('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
client.set_options(soapheaders=(name_space,api_key))
# getting the leave data from GetLeaveBalance for specific user
leave=client.service.GetLeaveBalance('1')
leave_data= Client.dict(leave)
##################### Creating list of leave types
leave_type=["short_leave", "casual_leave", "sick_leave","earned_leave", "leave_without_pay",
"paid_leave","paternity_leave","leave"]
# saving the leave type
leave_t= tracker.get_slot("leave_type")
#leave_t=latest_message.get("leave_type")
# specifing conditions for different leave types
if leave_t =="leave":
short_l=leave_data['LeaveBalance']["LeaveBalanceData"][0]["Balance"]
casual_l=leave_data['LeaveBalance']["LeaveBalanceData"][1]["Balance"]
sick_l=leave_data['LeaveBalance']["LeaveBalanceData"][2]["Balance"]
earned_l=leave_data['LeaveBalance']["LeaveBalanceData"][3]["Balance"]
without_pay_l=leave_data['LeaveBalance']["LeaveBalanceData"][4]["Balance"]
privilege_l=leave_data['LeaveBalance']["LeaveBalanceData"][5]["Balance"]
Paternity_l=leave_data['LeaveBalance']["LeaveBalanceData"][6]["Balance"]
text_leave=(""" Your Leave balance summary is as follows:
Short Leave :{}
Casual Leave : {}
Sick Leave: {}
Earned Leave : {}
Leave Without Pay : {}
Privilege Leave : {}
Paternity Leave : {}""".format(short_l,casual_l,sick_l,earned_l,without_pay_l,privilege_l,privilege_l,Paternity_l))
dispatcher.utter_message(text_leave)
return []
Domain file
intents:
- greet
- goodbye
- affirm
- deny
- leave_balance
entities: - leave_type
slots: leave_type: type: list
actions: - utter_greet - get_leave_balance - utter_goodbye
templates:
utter_greet:
- text: "Hey! How are you?"
utter_goodbye:
- text: "Thank you"