How to repeat the way say the last bot

You can have a majority of the voices. For example:

Bot: I have found the ABC contact with the phone number User 123456: Can you fix it? Bot: I found ABC contact with phone number 123456

I have no talent and make friends (looking for talent and talent), again.

I think I can create a “last_message” position and always fill in that position in all my custom actions. However, we can be very boring. There are no results, solutions and their work

Hey @shadowgun1102. I am not exactly sure what is your question? Can you provide more specifics for what you are trying to achieve?

You could make an action like this:

class ActionRepeat(Action):
def name(self) -> Text:
    return "action_repeat"

def run(self, dispatcher, tracker, domain):
    if len(tracker.events) >= 3:
        dispatcher.utter_message(tracker.events[-3].get('text'))
    return [UserUtteranceReverted()]

Regards,

1 Like

@custodio can you share the pipeline ? it does not work.

policies:
- name: EmbeddingPolicy
  epochs: 120
- name: MemoizationPolicy
  max_history: 5
- name: MappingPolicy
- name: "FallbackPolicy"
  nlu_threshold: 0.2
  core_threshold: 0.2
  fallback_action_name: 'action_default'
- name: FormPolicy

@Juste @Tobias_Wochinger any idea how to implement this action_repeat?

Can you please elaborate a bit what your problem is and what you’re trying to achieve @azizullah2017?

@Tobias_Wochinger I want to repeat what has bot last said. how to achieve that in custom action.

I want to continue the active form, if small talks came in between the flow of active form.

Example:
i  looking for a resutrant.
bot: may i know the cusine?
user: are you a chat bot?
bot: Yes, that is me.
bot: May I know the cusine? ## i want to get this.
User: Spanish.
stories.md.

# stories 1
* resturant 
  - resturan_form

# stories 2
* bot 
  -  utter_bot
  - action_repeat_question

Hi @azizullah2017,

the code which was shared by custodio in this post How to repeat the way say the last bot should help you out. I’d improve it a bit by not using hard-coded index, but rather going through the events in reverse order and checking if the type of the event was bot. And I’m not sure whether you need the UserUtteranceReverted because you are triggering that after the form, right?

I have tried that, I was looking for built in actions, so we do not have to traverse through events.

It’s already included in FormPolicy. You can check the formbot example in rasa github. You need to provide relevant stories for that.

Here is a code that repeats all the messages till the last user input without any hardcoding. This works well for text and buttons. You can do the same for images.

class ActionRepeat(Action): def name(self): return “action_repeat”

def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:

    user_ignore_count = 2
    count = 0
    tracker_list = []

    while user_ignore_count > 0:
        event = tracker.events[count].get('event')
        if event == 'user':
            user_ignore_count = user_ignore_count - 1
        if event == 'bot':
            tracker_list.append(tracker.events[count])
        count = count - 1

    i = len(tracker_list) - 1
    while i >= 0:
        data = tracker_list[i].get('data')
        if data:
            if "buttons" in data:
                dispatcher.utter_message(text=tracker_list[i].get('text'), buttons=data["buttons"])
            else:
                dispatcher.utter_message(text=tracker_list[i].get('text'))
        i -= 1

    return []
2 Likes

This worked for me pretty well. Thank you @sibbsnb.

1 Like