Hi I am using javascript and i am sending the sender id as well. The problem i am facing is when multiple user try to update the same form at same time it is giving response to the first user who provide information.
For example:
User 1: What is my device status
Bot : Please provide device name
User2: What is my device status
Bot : Please provide device name
User 1: XYZ
Bot: Device updated
User2: XYZ
Bot: Sorry i could not understand
Somehow i am not able to achieve parallel processing with formaction. I hope i am able to make things little simple.
Below is the code which i am using.
class DynamicForm(FormAction):
form_slot_names=""
def name(self) -> Text:
return "dynamic_form"
@staticmethod
def required_slots(tracker: Tracker) -> List[Text]:
intent_name = tracker.latest_message['intent'].get('name')
global url
global req_type
global form_user_ques
global param_bool
##For storing conversation in database
conversation_data = {}
print("intent name: ",str(intent_name))
if not DynamicForm.form_slot_names:
print("Line 147: ", str(param_bool)," : ",str(DynamicForm.form_slot_names))
# form_slot_names = df_intent_mapping['DynamicResponseUserInputs'][df_intent_mapping['Intent'] == intent_name].values
param_bool = df_intent_mapping['DynamicResponseUserInputs'][df_intent_mapping['Intent'] == intent_name].fillna("").values
url = df_intent_mapping['DynamicResponseRestURL'][df_intent_mapping['Intent']==intent_name].values[0]
req_type = df_intent_mapping['DynamicResponseRestAction'][df_intent_mapping['Intent']==intent_name].values[0]
if not param_bool:
pass
else:
DynamicForm.form_slot_names = df_intent_mapping['DynamicResponseUserInputs'][df_intent_mapping['Intent'] == intent_name].values
DynamicForm.form_slot_names = [x.strip() for x in DynamicForm.form_slot_names[0].split(',')]
print("Line 152 Hello ", str(url)," ",str(req_type))
##For storing conversation in database
if form_user_ques is False:
print("Line 161: ",tracker.latest_message['text'])
sender_id = tracker.sender_id
conversation_data["user"] = tracker.latest_message['text']
conversation_data["bot"] = "Provide information"
conversation_storage(sender_id, conversation_data)
form_user_ques= True
return DynamicForm.form_slot_names
def slot_mappings(self): # type: # () -> Dict[Text: Union[Dict, List[Dict]]]
slot_with_value = {}
# global form_slot_names
for itms in DynamicForm.form_slot_names:
slot_with_value[itms]=self.from_text()
# res = ', '.join('{}: {}'.format(key, value) for key, value in slot_with_value.items())
print("Line 175 called",str(slot_with_value))
return slot_with_value
def submit(self,dispatcher: CollectingDispatcher,tracker: Tracker,domain: Dict[Text, Any],) -> List[Dict]:
# global form_slot_names
global url
global req_type
global form_user_ques
global param_bool
print("line 184 ",str(DynamicForm.form_slot_names))
slot_with_value = {}
headers={"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2; Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"}
##For storing conversation in database
conversation_data = {}
for itms in DynamicForm.form_slot_names:
slot_with_value[itms]=tracker.get_slot(itms)
res = ', '.join('{}: {}'.format(key, value) for key, value in slot_with_value.items())
slot_values = {key: None for key in DynamicForm.form_slot_names}
conversation_data["user"] = slot_with_value
DynamicForm.form_slot_names=""
form_user_ques = False
print("Line 203 ",str(DynamicForm.form_slot_names))
print("Line 206: ",str(req_type))
if req_type == "POST":
try:
request = requests.post(url.rstrip(), json=slot_with_value,headers=headers)
print("Line 210: ", str(request))
# response = request.json()
result = request.text
dispatcher.utter_message(request.text)
print("Line 214: ",str(request.text))
except:
result = "Some error happened please re try"
dispatcher.utter_message("Some error happened please re try")
elif req_type == "GET":
try:
request = requests.get(url.rstrip(), slot_with_value,headers=headers)
print("Line 230:", str(slot_with_value))
print("Line 221: ", str(url))
print("Line 232: ", str(request))
result = request.text
dispatcher.utter_message(request.text)
print("Line 227: ",str(request.text))
except:
result = "Some error happened please re try"
dispatcher.utter_message("Some error happened please re try")
sender_id = tracker.sender_id
conversation_data["bot"]=result
conversation_storage(sender_id,conversation_data)
return [SlotSet(slot, value) for slot, value in slot_values.items()]
So i have an excel sheet where i maintain the intent and the slots i want to be filled by user. So in required slots method i am using form_slot_names
variable which has the slot names from excel sheet. I made scope of form_slot_names
to the class specific assuming when multiple user activate the dynamic_form
multiple instance of dynamic_form
will get created and the slot names will not affect.
@Juste can you please help me with this