예제 #1
0
        private void LogFeedback(FeedbackRecord record)
        {
            var properties = new Dictionary <string, string>()
            {
                { nameof(FeedbackRecord.Tag), record.Tag },
                { nameof(FeedbackRecord.Feedback), record.Feedback },
                { nameof(FeedbackRecord.Comment), record.Comment },
                { nameof(FeedbackRecord.Request.Text), record.Request?.Text },
                { nameof(FeedbackRecord.Request.Id), record.Request?.Conversation.Id },
                { nameof(FeedbackRecord.Request.ChannelId), record.Request?.ChannelId },
            };

            _telemetryClient.TrackEvent(_traceName, properties);
        }
예제 #2
0
        /// <summary>
        /// Sends a Feedback Request activity with suggested actions to the user.
        /// </summary>
        /// <param name="context">Turn context for sending activities.</param>
        /// <param name="tag">Tag to categorize feedback record in Application Insights.</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        public static async Task RequestFeedbackAsync(ITurnContext context, string tag)
        {
            // clear state
            await _feedbackAccessor.DeleteAsync(context).ConfigureAwait(false);

            // create feedbackRecord with original activity and tag
            var record = new FeedbackRecord()
            {
                Request = context.Activity,
                Tag     = tag,
            };

            // store in state. No need to save changes, because its handled in IBot
            await _feedbackAccessor.SetAsync(context, record).ConfigureAwait(false);

            // If channel supports suggested actions
            if (Channel.SupportsSuggestedActions(context.Activity.ChannelId))
            {
                // prompt for feedback
                // if activity already had suggested actions, add the feedback actions
                if (context.Activity.SuggestedActions != null)
                {
                    var actions = new List <CardAction>()
                                  .Concat(context.Activity.SuggestedActions.Actions)
                                  .Concat(GetFeedbackActions())
                                  .ToList();

                    await context.SendActivityAsync(MessageFactory.SuggestedActions(actions)).ConfigureAwait(false);
                }
                else
                {
                    var actions = GetFeedbackActions();
                    await context.SendActivityAsync(MessageFactory.SuggestedActions(actions)).ConfigureAwait(false);
                }
            }
            else
            {
                // else channel doesn't support suggested actions, so use hero card.
                var hero = new HeroCard(buttons: GetFeedbackActions());
                await context.SendActivityAsync(MessageFactory.Attachment(hero.ToAttachment())).ConfigureAwait(false);
            }
        }