Exemplo n.º 1
0
        public async Task OnTurnAsync(ITurnContext turnContext, NextDelegate next, CancellationToken cancellationToken = default(CancellationToken))
        {
            var proactiveState = await _proactiveStateAccessor.GetAsync(turnContext, () => new ProactiveModel());

            ProactiveData data;
            var           userId = turnContext.Activity.From.Id;
            var           conversationReference = turnContext.Activity.GetConversationReference();
            var           proactiveData         = new ProactiveData {
                Conversation = conversationReference
            };

            if (proactiveState.TryGetValue(userId, out data))
            {
                data.Conversation = conversationReference;
            }
            else
            {
                data = new ProactiveData {
                    Conversation = conversationReference
                };
            }

            proactiveState[userId] = data;
            await _proactiveStateAccessor.SetAsync(turnContext, proactiveState);

            await _proactiveState.SaveChangesAsync(turnContext);

            await next(cancellationToken).ConfigureAwait(false);
        }
Exemplo n.º 2
0
        public async Task OnTurnAsync(ITurnContext turnContext, NextDelegate next, CancellationToken cancellationToken = default(CancellationToken))
        {
            var activity = turnContext.Activity;

            if (activity.From.Properties["role"].ToString().Equals("user", StringComparison.InvariantCultureIgnoreCase))
            {
                var proactiveState = await _proactiveStateAccessor.GetAsync(turnContext, () => new ProactiveModel());

                ProactiveData data;
                var           hashedUserId          = MD5Util.ComputeHash(turnContext.Activity.From.Id);
                var           conversationReference = turnContext.Activity.GetConversationReference();
                var           proactiveData         = new ProactiveData {
                    Conversation = conversationReference
                };

                if (proactiveState.TryGetValue(hashedUserId, out data))
                {
                    data.Conversation = conversationReference;
                }
                else
                {
                    data = new ProactiveData {
                        Conversation = conversationReference
                    };
                }

                proactiveState[hashedUserId] = data;
                await _proactiveStateAccessor.SetAsync(turnContext, proactiveState);

                await _proactiveState.SaveChangesAsync(turnContext);
            }

            await next(cancellationToken).ConfigureAwait(false);
        }