We would like to implement an intent in our bot that should do the following:
- User ask things like “Please say that again?”
- The bot respond saying “Did you want me to repeat what I just said a moment ago?”
- The user respond yes
- I repeat the last utter before “Please say that again?”
I’d like to implement that in a way that we don’t have to create all the different casuistics in the stories. Maybe a rule but rules are not allowing several intents. Also, I’d like this implementation to be solid enougth to keep bot memory and state healty once I repeat.
Any ideas?
You can do it using rasa action:
class ActionRepeat(Action):
def name(self) -> Text:
return "action_repeat"
def run(self, dispatcher, tracker, domain):
if len(tracker.events) >= 3:
i = 0
while(tracker.events[i].get('event')!='bot' ):
i = i-1
last = tracker.events[i].get('data').get('custom') #I have custom response
dispatcher.utter_message(json_message={
#do what you want with your last message
#i.e I had a field named text so:
"text": last.get('text')
})
return [UserUtteranceReverted()]
1 Like
Hello TalissaDreossi thanks for the quick response! This is quite helpfull.
Ok, I think I understand what you suggest
Also, where do you suggest to add the following steps? Is it possible to add this as a Rule (because I want this to be a generic behaviour)? I didn’t found rules with two intents… but maybe is possible?
- User ask things like “Please say that again?”
(intent: repeat)
- The bot respond saying “Did you want me to repeat what I just said a moment ago?”
(utter_repeat)
- The user respond yes
(intent:affirm)
- I repeat the last utter before “Please say that again?”
(action_repeat)
I think you can do that by searching recursively in tracker the previous of previous message:
if len(tracker.events) >= 5: #not sure if 5 but it must be greater than 3 cause now you have another question in between
i = 0
keepSearching=True
while(tracker.events[i].get('event')!='bot' or keepSearching):
i = i-1
if(tracker.events[i].get('event')=='bot'):
keepSearching = False
#so next time it find tracker.events[i].get('event')=='bot' it will exit while loop
#giving you the first response and not “Did you want me to repeat what I just said a moment ago?”
I think this can be done in a smarter way but just to get you the idea this should work