Problem:- I have pincode.txt file and I want to serach in this file that user give input pincode. Means I can’t hard code all pincodes in entity or slots.
Possible solutions I have tried or think for this :
1> Use lookup table for that but Don’t know how to do it , means how to utter message when pincode not in my lookup table
2> Use custom action for that but not able to extract entity. So, anybody can help me out from this . here are releated flies that I have made
Path41
unableupdate_pincode
utter_unableupdate_pincode
share_pincode
action_pincode
slot{“pincode”:“123456”}
entities:
pincode
slots:
pincode:
type: text
class Actionpincode(Action):
def name(self):
return “action_pincode”
def run(self, dispatcher, tracker, domain):
path = '/home/saurbh/Desktop/intern/my_project/rasa/pincode.txt'
pincode_file = open(path,'r')
pin = tracker.get_slot('pincode')
global flag
flag=0
for i in pincode_file:
print(i)
if i==pin:
flag=1
pincode_file.close()
if flag==1:
dispatcher.utter_message("yes")
return []
else :
dispatcher.utter_message("no")
return []
intent:unableupdate_pincode
Payme India, your app is not accepting my pincode?
@varunsapre10 thanks, But in pincode.txt file i have only pincodes means one pincode in one linepincode.txt (131.3 KB) . I think slots are not properly tracked in variable pin
In that case, try removing the ‘for line in line’ loop and keep ‘word’ loop as the main one. Maybe change
“if pin==word” TO “if pin in word”. It is upto you.
pin = str(tracker.get_slot('pincode'))
global flag
flag=0
with open('pincode.txt') as file:
for line in file:
for word in line.split():
if pin in word:
flag=1
file.close()
if flag==1:
dispatcher.utter_message("yes")
return []
else :
dispatcher.utter_message("no")
return []
Also the ‘run’ function needs the above mentioned parameters according to the format by rasa.
The type of get_slot is NONE, so we convert it to str.