title: Accessing variables within a botbuilder dialog
body: <p>I'm building a bot in nodejs where I would like the user to move through different dialog paths dependent on how the interaction started. I'm looking to distinguish between proactive messages, onmembersadded and onmessage.</p>
  <p>My idea to do this was to create a variable with the type of interaction (onmessage or onmembersadded) and then pass this through to my main dialog and route from there. Annoyingly I can't find a way to access this variable within the main dialog. Can anyone help me with how to do this or suggest another way of achieving the same goal?</p>
  <p>I've looked through a lot of the existing material and I can't find anything attempting the same.</p>
  <p>Dialogbot</p>
  <pre><code>const CONVERSATION_DATA_PROPERTY = 'conversationData';
  
  class TeamsBot extends DialogBot {
      /**
       *
       * @param {ConversationState} conversationState
       * @param {UserState} userState
       * @param {Dialog} dialog
       */
      constructor(conversationState, userState, dialog) {
          super(conversationState, userState, dialog);
  
          this.conversationDataAccessor = conversationState.createProperty(CONVERSATION_DATA_PROPERTY);
  
          this.onMembersAdded(async (context, next) =&gt; {
              const membersAdded = context.activity.membersAdded;
              for (let cnt = 0; cnt &lt; membersAdded.length; cnt++) {
                  if (membersAdded[cnt].id !== context.activity.recipient.id) {
                      const conversationData = await this.conversationDataAccessor.get(context, {});
                      conversationData.trigger = &quot;onNewMemberAdded&quot;;
                      console.log(this.dialogState);
                      await this.dialog.run(context, this.dialogState);
                  }
              }
  </code></pre>
  <p>This will then save down the conversationData.trigger but when I then try to access it in mainDialog as below I get a &quot;Conversationstate is not defined&quot; error</p>
  <pre><code>class MainDialog extends LogoutDialog {
      constructor() {
          super(MAIN_DIALOG);
  
          this.conversationDataAccessor = conversationState.createProperty(CONVERSATION_DATA_PROPERTY);
  </code></pre>
  <p>Then within a step</p>
  <pre><code>const conversationData = await this.conversationDataAccessor.get(context, {});
  </code></pre>
  <p>edit:</p>
  <p>Thanks for replying. I was initialising main dialog in index.js as follows:</p>
  <pre><code>const memoryStorage = new MemoryStorage();
  
  // Create conversation and user state with in-memory storage provider.
  const conversationState = new ConversationState(memoryStorage);
  const userState = new UserState(memoryStorage);
  
  // Create the main dialog.
  const dialog = new MainDialog();
  // Create the bot that will handle incoming messages.
  const bot = new TeamsBot(conversationState, userState, dialog);
  </code></pre>
  <p>I think that I can't initialise it in index.js as at this point I don't have the conversationdataAccessors set up (these are done in the bot code as above). I've tried to then change this to not pass through the dialog param to the bot code but this is then difficult to get the dialogs working correctly. Hopefully this helps to answer your question!</p>