/// <summary>
        /// Processess an incoming activity and if it is for MsTeams attaches <see cref="ITeamsContext"/> instances along with the context.
        /// </summary>
        /// <param name="context">The context object for this turn.</param>
        /// <param name="nextDelegate">The delegate to call to continue the bot middleware pipeline.</param>
        /// <param name="cancellationToken">Cancellation token.</param>
        /// <returns>
        /// Task tracking operation.
        /// </returns>
        /// <remarks>
        /// Middleware calls the <paramref name="nextDelegate" /> delegate to pass control to
        /// the next middleware in the pipeline. If middleware doesn’t call the next delegate,
        /// the adapter does not call any of the subsequent middleware’s request handlers or the
        /// bot’s receive handler, and the pipeline short circuits.
        /// <para>The <paramref name="context" /> provides information about the
        /// incoming activity, and other data needed to process the activity.</para>
        /// </remarks>
        /// <seealso cref="ITurnContext" />
        /// <seealso cref="Schema.IActivity" />
        public async Task OnTurnAsync(ITurnContext context, NextDelegate nextDelegate, CancellationToken cancellationToken = default(CancellationToken))
        {
            BotAssert.ContextNotNull(context);

            if (context.Activity.ChannelId.Equals(Channels.Msteams, StringComparison.OrdinalIgnoreCase))
            {
                // BotFrameworkAdapter when processing activity, post Auth adds BotIdentity into the context.
                ClaimsIdentity claimsIdentity = context.TurnState.Get <ClaimsIdentity>("BotIdentity");

                // If we failed to find ClaimsIdentity, create a new AnonymousIdentity. This tells us that Auth is off.
                if (claimsIdentity == null)
                {
                    claimsIdentity = new ClaimsIdentity(new List <Claim>(), "anonymous");
                }

                ITeamsConnectorClient teamsConnectorClient = await this.CreateTeamsConnectorClientAsync(context.Activity.ServiceUrl, claimsIdentity).ConfigureAwait(false);

                context.TurnState.Add((ITeamsContext) new TeamsContext(context, teamsConnectorClient));
            }

            await nextDelegate(cancellationToken).ConfigureAwait(false);
        }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TeamsContext"/> class.
 /// </summary>
 /// <param name="turnContext">Turn context created by adapter and sent over through middlewares.</param>
 /// <param name="teamsConnectorClient">Teams connector client instance.</param>
 internal TeamsContext(ITurnContext turnContext, ITeamsConnectorClient teamsConnectorClient)
 {
     this.turnContext          = turnContext;
     this.teamsConnectorClient = teamsConnectorClient;
 }