Closing of chat widget when chat ends

I have a problem that when conversation between user and bot ends, if user greets “hi” after sometimes in the same session, the bot again start conversation from starting. I want, when user says “bye” and bot says “bye” and session must be end. It will not start conversation if user says “hi”.

Is there any solution or any alternate suggestion?