title: Terminate all dialogs and exit conversation in MS Bot Framework when the user types "exit", "quit" etc
body: <p>I can't figure out how to do the a very simple thing in MS Bot Framework: allow the user to break out of any conversation, leave the current dialogs and return to the main menu by typing "quit", "exit" or "start over". </p>
  
  <p>Here's the way my main conversation is set up:</p>
  
  <pre><code>    public async Task&lt;HttpResponseMessage&gt; Post([FromBody]Activity activity)
      {
          try
          {
              if (activity.Type == ActivityTypes.Message)
              {
                  UserActivityLogger.LogUserBehaviour(activity);
  
                  if (activity.Text.ToLower() == "start over")
                  {
                      //Do something here, but I don't have the IDialogContext here!
                  }
                  BotUtils.SendTyping(activity); //send "typing" indicator upon each message received
                  await Conversation.SendAsync(activity, () =&gt; new RootDialog());
              }
              else
              {
                  HandleSystemMessage(activity);
              }
          }
  </code></pre>
  
  <p>I know how to terminate a dialog with <code>context.Done&lt;DialogType&gt;(this);</code>, but in this method, I do not have access to the IDialogContext object, so I cannot call <code>.Done()</code>. </p>
  
  <p>Is there any other way to terminate the whole dialog stack when the user types a certain message, other than adding a check for that in each step of all dialogs?</p>
  
  <p><strong>Posted bounty:</strong></p>
  
  <p>I need a way to terminate all <code>IDialog</code>s without using the outrageous hack that I've posted here (which deletes all user data, which I need, e.g. user settings and preferences). </p>
  
  <p>Basically, when the user types "quit" or "exit", I need to exit whatever <code>IDialog</code> is currently in progress and return to the fresh state, as if the user has just initiated a conversation. </p>
  
  <p>I need to be able to do this from <code>MessageController.cs,</code> where I still do not have access to <code>IDialogContext</code>. The only useful data I seem to have there is the <code>Activity</code> object. I will be happy if someone points out to other ways to do that. </p>
  
  <p>Another way to approach this is find some other way to check for the "exit" and "quit" keywords at some other place of the bot, rather than in the Post method.</p>
  
  <p>But it shouldn't be a check that is done at every single step of the <code>IDialog</code>, because that's too much code and not even always possible (when using <code>PromptDialog</code>, I have no access to the text that the user typed). </p>
  
  <p><strong>Two possible ways that I didn't explore:</strong> </p>
  
  <ul>
  <li>Instead of terminating all current <code>IDialog</code>s, start a new conversation
  with the user (new <code>ConversationId</code>) </li>
  <li>Obtain the <code>IDialogStack</code> object and do something with it to manage the dialog stack.</li>
  </ul>
  
  <p>The Microsoft docs are silent on this object so I have no idea how to get it. I do not use the <code>Chain</code> object that allows <code>.Switch()</code> anywhere in the bot, but if you think it can be rewritten to use it, it can be one of the ways to solve this too. However, I haven't found how to do branching between various types of dialogs (<code>FormFlow</code> and the ordinary <code>IDialog</code>) which in turn call their own child dialogs etc.</p>