Bonjour,
J’ai ma fonction detect_response une partie de mon chatboot. Son rôle est de vérifié le suivi de sa commande et ma fonction vérifie si dans le contenu du mail du client grâce order_info sinon elle me renvoi "not found".
Ma fonction ne réagit pas comme je le veux.
J’aimerai que ma fonction me renvoi toutes les valeurs order_info trouvées ou si elle ne trouve rien qu’elle me renvoi "not found".
J’ai besoin d’aide svp !
def detect_response(shop,questions,order_info,message,history):
response = ["/ALERT No cases detected, I don't know what to answer"] #Default
answer_id = "s0"
last_answer = False
global messages_dic_1, messages_dic_2
for l in history:
if l[0] == message["email"]:
if "s" in l[4]:
last_answer = False
else:
last_answer = True
answer_ids = list(eval(l[4].replace("$",",")))
last_answer_id = answer_ids[-1]
break
if last_answer:
lst = messages_dic_2[shop]
for l in lst:
if l[2] == [""]:
c1 = (questions[0] in l[1]) or (questions[1] in l[1])
else:
c1 = ((questions[0] in l[1]) or (questions[0] in l[2])) and ((questions[1] in l[1]) or (questions[1] in l[2]) or (questions[1] == "none"))
c2 = order_info["status"] in l[3]
if l[4] == ['']:
c3 = True
else:
c3 = (int(l[4][0]) <= order_info["time"]) and (int(l[4][1]) >= order_info["time"])
if l[5] == ['']:
c4 = True
else:
c4 = (int(l[5][0]) <= order_info["order_time"]) and (int(l[5][1]) >= order_info["order_time"])
c5 = last_answer_id in l[0] or l[0] == ""
if c1 and c2 and c3 and c4 and c5:
response = l[6]
answer_id = l[8][0]
break
if response == ["/ALERT No cases detected, I don't know what to answer"]:
last_answer = False
if not last_answer:
lst = messages_dic_1[shop]
for l in lst:
if l[1] == [""]:
c1 = (questions[0] in l[0]) or (questions[1] in l[0])
else:
c1 = ((questions[0] in l[0]) or (questions[0] in l[1])) and ((questions[1] in l[0]) or (questions[1] in l[1]) or (questions[1] == "none"))
c2 = order_info["status"] in l[2]
if l[3] == ['']:
c3 = True
else:
c3 = (int(l[3][0]) <= order_info["time"]) and (int(l[3][1]) >= order_info["time"])
if l[4] == ['']:
c4 = True
else:
c4 = (int(l[4][0]) <= order_info["order_time"]) and (int(l[4][1]) >= order_info["order_time"])
if c1 and c2 and c3 and c4:
response = l[6]
answer_id = l[9][0]
break
return response[0], answer_id.replace("\r","")
+0
-0