How to send an automatic message to the user when the conversation ends

How can I send the message “I’m ending the session if you won’t talk to me” to the user when 30 minutes have passed after the conversational ends? for example;

user: hello What’s your name?

chatbot: I’m a bot

after 30 minute;

chatbot: I’m ending the session if you won’t talk to me

I think you’ll need to use External Events for this. There’s a session timeout but no event that is thrown when the timeout is hit (Rasa is not monitoring this - it determines the timeout if and when the user tries to start the session again).

Maybe an external process (service or cron job) that processes the tracker store since it’s last interval, notes new session id’s, checks for last activity on other session id’s. If the 30 mins have passed, send an external event with your message.

Or use action server, followup messages and start timer, and when timer runs out, send message.

I developed a coding like this, but it doesn’t work. After the user is inactive, there is no message even after 120 seconds.

class ActionHelloWorld(Action):

def name(self) -> Text:
    return "action_finish_conversation"

def run(self, dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
   
    date_time = datetime.datetime.now() + datetime.timedelta(seconds=120) 
    return [ReminderScheduled(action_name="utter_finish", trigger_date_time=date_time, kill_on_user_message=True)]

Also, I added this action to the end of each story. for example;

  • story: happy path

    steps:

    • intent: greet

    • action: utter_greet

    • intent: mood_great

    • action: utter_happy

    • action: action_finish_conversation

You could use something like this, just add reset if user sends new message

# import the time module
import time

# define the countdown func.
def countdown(t):
	
	while t:
		mins, secs = divmod(t, 60)
		timer = '{:02d}:{:02d}'.format(mins, secs)
		print(timer, end="\r")
		time.sleep(1)
		t -= 1
	
	print('Fire in the hole!!')


# input time in seconds
t = input("Enter the time in seconds: ")

# function call
countdown(int(t))

Thank you very much

1 Like

How should I define in the story section? I did it this way but there was a problem. The problem is that; The chatbot waits for 120 seconds to give the answer and then both the reply and the logout message come at the same time.

image

after 120 seconds;

image

I want to say “Great, carry on!” the text will come, and after 120 seconds the text “I’m ending the session if you won’t talk to me” will come.

class ActionHelloWorld(Action):

def name(self) -> Text:

    return "action_finish_conversation2"

def run(self, dispatcher: CollectingDispatcher,

        tracker: Tracker,

        domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:

   

    def countdown(t):



        while t:

            mins, secs = divmod(t, 60)

            timer = '{:02d}:{:02d}'.format(mins, secs)

         
            time.sleep(1)

            t -= 1



        return []

    d=countdown(120)

    dispatcher.utter_message(response="utter_finish")

    return []

this is story definition

  • story: happy path

    steps:

    • intent: greet

    • action: utter_greet

    • intent: mood_great

    • action: utter_happy

    • action: action_finish_conversation2

Please can you help me

1 Like

Can you do

rasa run shell --debug

and paste relevant parts here?

1 Like

It didn’t give any output after that. It’s been like this for about 10 minutes.