Exemplo n.º 1
0
        public async Task HandleMessage(IBotContext botContext)
        {
            var context = new DetectiveBotContext(botContext, _faceRecognitionService, _customVisionService);

            var handled = false;

            if (context.RecognizedIntents.TopIntent?.Name == Intents.Quit)
            {
                await context.SendActivity($"Stopping current action");

                context.ConversationState.ActiveTopic = new DefaultTopic(_customVisionService, _faceRecognitionService);
                handled = await context.ConversationState.ActiveTopic.StartTopic(context);

                return;
            }

            if (context.ConversationState.ActiveTopic == null)
            {
                context.ConversationState.ActiveTopic = new DefaultTopic(_customVisionService, _faceRecognitionService);
                handled = await context.ConversationState.ActiveTopic.StartTopic(context);
            }
            else
            {
                handled = await context.ConversationState.ActiveTopic.ContinueTopic(context);
            }

            // if activeTopic's result is false and the activeTopic is NOT already the default topic
            if (handled == false && !(context.ConversationState.ActiveTopic is DefaultTopic))
            {
                // USe DefaultTopic as the active topic
                context.ConversationState.ActiveTopic = new DefaultTopic(_customVisionService, _faceRecognitionService);
                handled = await context.ConversationState.ActiveTopic.StartTopic(context);
            }
        }
Exemplo n.º 2
0
        private async Task GetOrAddUserProfile(IBotContext botContext)
        {
            try
            {
                var context = new DetectiveBotContext(botContext, _faceRecognitionService, _customVisionService);

                var activity = context.Request.AsConversationUpdateActivity();
                var user     = activity.MembersAdded.Where(m => m.Id == activity.Recipient.Id).FirstOrDefault();
                if (user != null)
                {
                    await context.SendActivity($"Hello {user.Name}, welcome to the Detective bot!");
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Failed to get user.");
            }
        }