コード例 #1
0
        /// <summary>
        /// Handles any incoming command and route them to the appropriate dialog.
        /// </summary>
        /// <param name="context">A <see cref="IDialogContext"/>.</param>
        /// <param name="result">An <see cref="IMessageActivity"/>.</param>
        /// <returns>A <see cref="Task"/>.</returns>
        public virtual async Task HandleCommandAsync(IDialogContext context, IMessageActivity result)
        {
            context.ThrowIfNull(nameof(context));
            result.ThrowIfNull(nameof(result));

            // Message is coming from a group chat, so skipping if the bot is not explicitly mentioned.
            if (result.Conversation.IsGroup.GetValueOrDefault() && !result.MentionsRecipient())
            {
                context.Wait(this.HandleActivityAsync);
                return;
            }

            var dialog = GlobalConfiguration.Configuration.DependencyResolver.Find(result.RemoveRecipientMention());

            context.UserData.TryGetValue("userData", out UserData data);

            if (dialog == null || (data == null && !(dialog is ConnectDialog)))
            {
                if (data == null)
                {
                    data = new UserData();
                }

                var reply = context.MakeMessage();

                reply.Text = result.Text.Trim().Equals(CommandMatchHelp, StringComparison.OrdinalIgnoreCase)
                    ? Labels.Help
                    : Labels.UnknownCommand;

                reply.Attachments.Add(new MainOptionsCard(!string.IsNullOrEmpty(data.TeamProject)));

                await context.PostAsync(reply);

                context.Wait(this.HandleActivityAsync);
            }
            else
            {
                this.telemetryClient.TrackEvent(result.Text);

                await context.Forward(dialog, this.ResumeAfterChildDialog, result, CancellationToken.None);
            }
        }