Something like that
from random import randrange
class ActionGoodbye(Action):
def name(self):
return 'action_goodbye'
def run(self, dispatcher, tracker, domain):
goodbyes = [
'bye!', # 0
'hope to see you soon.' # 1
'have a nice day.' # 2
]
already_uttered = tracker.get_slot('uttered_goobye') # For example [0, 2] means the first and third sentences were already uttered
if len(already_uttered) >= len(goodbyes): # If all the sentences were already uttered, reset
already_uttered = [] # Reset the slot
random_index = None
while (random_index is None) or (random_index not in already_uttered): # Do this until we get a random_index that was not uttered
random_index = randrange(len(goodbyes))
utterance = goodbyes[random_index]
already_uttered.append(random_index)
return [SlotSet('uttered_goobye', already_uttered)]