Options
All
  • Public
  • Public/Protected
  • All
Menu

Class SessionService

Service that provides session for addresses. Injects code into a Universal bot to allow session save and load listeners to work

Hierarchy

  • SessionService

Index

Constructors

constructor

Properties

Private bot

bot: UniversalBot

Private currentSessionLoadResolver

currentSessionLoadResolver: function

Type declaration

    • (s: Session): void
    • Parameters

      • s: Session

      Returns void

Private savePerformed

savePerformed: Promise<any>

This is a crucial field to proper serial execution of the BotTester framework. session.save occurs asynchronously in UniversalBot batch executions. We do not want to be able to load a session if session.save has been called, but the bot's batch has yet to execute. This promise will be set to resolved when the bot's latest batch has finished, should the framework be watching for a save call. This value is defaulted to a resolved promise.

Methods

Private applySessionLoadListener

  • applySessionLoadListener(): void
  • adds middleware to the bot that checks for incoming load messages sent by createSessionWrapperWithLoadMessageOverride's bot.createSession wrapper. This lets us know that the message was never meant to go through the bot's middelware and ignore it. The session loaded into this message is then used as the value that the Promise returned from getSession resolves to

    Returns void

Private applySessionSaveListener

  • applySessionSaveListener(): void
  • Adds a routing event listner which is the first execution path called after a session has been successfully loaded. If this session has not already gone through this listener, then it wraps session.save in a function that sends the internal save message that is mocked to be sent to the user, and thereby intercepted by the MessageService. This ensures that the test runner does not continue preemptively. When the session's save method is called, the message is actually sent and alerts the BotTester framework

    Returns void

Private createSessionWrapperWithLoadMessageOverride

  • createSessionWrapperWithLoadMessageOverride(addr: IAddress): void
  • This is a delicate hack that relies on accessing and modifying the private field createSession on UniversalBot. This makes the bot's next createSession call result in a session with a message of type 'load'. This allows the sessionLoadListener to know if a message that the bot thinks it received was actually the result of a call to bot.createSession

    Parameters

    • addr: IAddress

      address of the message that is being loaded

    Returns void

getInternalSaveMessage

  • getInternalSaveMessage(address: IAddress): IMessage
  • a message internal to the BotTester framework. Due limitations in the botbuilder framework, this message is sent to the bot whenever session.save is called. This allows the framework to know when session.save is called and resolve accordingly. Without this, the session state may not be persisted before the next test step is run

    Parameters

    • address: IAddress

      address that the save message should come from

    Returns IMessage

getSession

  • getSession(addr: IAddress): Promise<Session>
  • fetches a session for a particular address

    Parameters

    • addr: IAddress

      address of session to load

    Returns Promise<Session>

Private loadSession

  • loadSession(address: IAddress): void
  • Loads a session associated with an address.

    Parameters

    • address: IAddress

      address to be loaded

    Returns void