Exemple #1
0
        public override async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken)
        {
            // Client notifying this bot took to long to respond (timed out)
            if (turnContext.Activity.Code == EndOfConversationCodes.BotTimedOut)
            {
                _telemetryClient.TrackTrace($"Timeout in {turnContext.Activity.ChannelId} channel: Bot took too long to respond.", Severity.Information, null);
                return;
            }

            var dc = await _dialogs.CreateContextAsync(turnContext);

            if (dc.Context.Activity.Locale == "en")
            {
                dc.Context.Activity.Locale = "en-us";
            }

            if (dc.ActiveDialog != null)
            {
                var result = await dc.ContinueDialogAsync();
            }
            else
            {
                await dc.BeginDialogAsync(typeof(T).Name);
            }
        }
Exemple #2
0
 /// <summary>
 /// Log a DialogView using the TrackPageView method on the IBotTelemetryClient if IBotPageViewTelemetryClient has been implemented.
 /// Alternatively log the information out via TrackTrace.
 /// </summary>
 /// <param name="telemetryClient">The TelemetryClient that implements IBotTelemetryClient.</param>
 /// <param name="dialogName">The name of the dialog to log the entry / start for.</param>
 /// <param name="properties">Named string values you can use to search and classify events.</param>
 /// <param name="metrics">Measurements associated with this event.</param>
 public static void TrackDialogView(this IBotTelemetryClient telemetryClient, string dialogName, IDictionary <string, string> properties = null, IDictionary <string, double> metrics = null)
 {
     if (telemetryClient is IBotPageViewTelemetryClient pageViewClient)
     {
         pageViewClient.TrackPageView(dialogName, properties, metrics);
     }
     else
     {
         telemetryClient.TrackTrace($"Dialog View: {dialogName}", Severity.Information, properties);
     }
 }
        /// <summary>
        /// Primary adapter method for processing activities sent from calling bot.
        /// </summary>
        /// <param name="activity">The activity to process.</param>
        /// <param name="callback">The BotCallBackHandler to call on completion.</param>
        /// <param name="cancellationToken">Cancellation token.</param>
        /// <returns>The response to the activity.</returns>
        public async Task <InvokeResponse> ProcessActivityAsync(Activity activity, BotCallbackHandler callback, CancellationToken cancellationToken)
        {
            BotAssert.ActivityNotNull(activity);

            _botTelemetryClient.TrackTrace($"Received an incoming activity. ActivityId: {activity.Id}", Severity.Information, null);

            using (var context = new TurnContext(this, activity))
            {
                await RunPipelineAsync(context, callback, cancellationToken).ConfigureAwait(false);

                // We do not support Invoke in websocket transport
                if (activity.Type == ActivityTypes.Invoke)
                {
                    return(new InvokeResponse {
                        Status = (int)HttpStatusCode.NotImplemented
                    });
                }

                return(null);
            }
        }
        public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
        {
            // Client notifying this bot took to long to respond (timed out)
            if (turnContext.Activity.Code == EndOfConversationCodes.BotTimedOut)
            {
                _telemetryClient.TrackTrace($"Timeout in {turnContext.Activity.ChannelId} channel: Bot took too long to respond.", Severity.Information, null);
                return;
            }

            await _dialog.RunAsync(turnContext, _conversationState.CreateProperty<DialogState>(nameof(DialogState)), cancellationToken);

            // Save any state changes that might have occured during the turn.
            await _conversationState.SaveChangesAsync(turnContext, false, cancellationToken);
            await _userState.SaveChangesAsync(turnContext, false, cancellationToken);
        }
        /// <summary>
        /// Primary adapter method for processing activities sent from calling bot.
        /// </summary>
        /// <param name="activity">The activity to process.</param>
        /// <param name="callback">The BotCallBackHandler to call on completion.</param>
        /// <param name="cancellationToken">Cancellation token.</param>
        /// <returns>The response to the activity.</returns>
        public async Task <InvokeResponse> ProcessActivityAsync(Activity activity, BotCallbackHandler callback, CancellationToken cancellationToken)
        {
            // Ensure the Activity has been retrieved from the HTTP POST
            BotAssert.ActivityNotNull(activity);

            _botTelemetryClient.TrackTrace($"SkillHttpBotAdapter: Received an incoming activity. Activity id: {activity.Id}", Severity.Information, null);

            // Process the Activity through the Middleware and the Bot, this will generate Activities which we need to send back.
            using (var context = new TurnContext(this, activity))
            {
                await RunPipelineAsync(context, callback, default(CancellationToken));
            }

            _botTelemetryClient.TrackTrace($"SkillHttpBotAdapter: Batching activities in the response. ReplyToId: {activity.ReplyToId}", Severity.Information, null);

            // Any Activity responses are now available (via SendActivitiesAsync) so we need to pass back for the response
            var response = new InvokeResponse
            {
                Status = (int)HttpStatusCode.OK,
                Body   = GetReplies(),
            };

            return(response);
        }
Exemple #6
0
        private async Task CreateWebSocketConnectionAsync(ClaimsIdentity claimsIdentity, HttpContext httpContext, IBot bot)
        {
            var socket = await httpContext.WebSockets.AcceptWebSocketAsync().ConfigureAwait(false);

            var handler = new SkillWebSocketRequestHandler(claimsIdentity, _botTelemetryClient);
            var server  = new WebSocketServer(socket, handler);

            server.Disconnected += Server_Disconnected;
            _skillWebSocketBotAdapter.Server = server;
            handler.Bot = bot;
            handler.SkillWebSocketBotAdapter = _skillWebSocketBotAdapter;

            _botTelemetryClient.TrackTrace("Starting listening on websocket", Severity.Information, null);
            _stopWatch.Start();
            var startListening = server.StartAsync();

            Task.WaitAll(startListening);
        }
        public async Task ProcessAsync(HttpRequest httpRequest, HttpResponse httpResponse, IBot bot, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (httpRequest == null)
            {
                throw new ArgumentNullException(nameof(httpRequest));
            }

            if (httpResponse == null)
            {
                throw new ArgumentNullException(nameof(httpResponse));
            }

            if (bot == null)
            {
                throw new ArgumentNullException(nameof(bot));
            }

            if (_authenticationProvider != null)
            {
                var authenticated = _authenticationProvider.Authenticate(httpRequest.Headers["Authorization"]);

                if (!authenticated)
                {
                    httpResponse.StatusCode = (int)HttpStatusCode.Unauthorized;
                    return;
                }
            }

            // deserialize the incoming Activity
            var activity = ReadRequest(httpRequest);

            var cancellationTokenSource = new CancellationTokenSource();

            _botTelemetryClient.TrackTrace($"SkillHttpAdapter: Processing incoming activity. Activity id: {activity.Id}", Severity.Information, null);

            // process the inbound activity with the bot
            var invokeResponse = await _skillHttpBotAdapter.ProcessActivityAsync(activity, bot.OnTurnAsync, cancellationTokenSource.Token).ConfigureAwait(false);

            // trigger cancel token after activity is handled. this will stop the typing indicator
            cancellationTokenSource.Cancel();

            // write the response, potentially serializing the InvokeResponse
            WriteResponse(httpResponse, invokeResponse);
        }
 public static void TrackTraceEx(this IBotTelemetryClient telemetryClient, string message, Severity severityLevel, Activity activity, IDictionary <string, string> properties, string dialogId = null)
 {
     telemetryClient.TrackTrace(message, severityLevel, GetFinalProperties(activity, dialogId, properties));
 }
Exemple #9
0
        public async Task SendReminderChat(IBotFrameworkHttpAdapter adapter)
        {
            try
            {
                TelemetryClient.TrackTrace("Sending reminder from Bot", Severity.Information, null);
                var team = await this.tableService.getDailyChallengeTeamInfo();

                var dailyChallenge = await tableService.GetDailyChallenge();

                // If no photo selected, send update
                if (dailyChallenge.winnerName == null)
                {
                    MicrosoftAppCredentials.TrustServiceUrl(team.ServiceUrl);
                    TelemetryClient.TrackTrace("Sending MicrosoftAppId: " + Configuration["MicrosoftAppId"], Severity.Information, null);
                    ConnectorClient connectorClient = new ConnectorClient(new Uri(team.ServiceUrl), Configuration["MicrosoftAppId"], Configuration["MicrosoftAppPassword"]);
                    var             teamName        = await this.GetTeamNameAsync(connectorClient, team.TeamId);

                    var    bot       = new ChannelAccount(team.BotId);
                    string replyText = $"<at>@{teamName}</at> ";

                    var activity = MessageFactory.Text(replyText);

                    var mentioned = JObject.FromObject(new
                    {
                        id   = team.TeamId,
                        name = teamName
                    });
                    var mentionedEntity = new Entity("mention")
                    {
                        Properties = JObject.FromObject(new { mentioned = mentioned, text = replyText }),
                    };
                    activity.Entities = new[] { mentionedEntity };
                    activity.Text     = "It's reminder time, " + replyText;
                    var convParams = new ConversationParameters()
                    {
                        TenantId    = team.TenantId,
                        Bot         = bot,
                        IsGroup     = true,
                        ChannelData = team.ChannelData,
                        Activity    = (Activity)activity
                    };
                    TelemetryClient.TrackTrace("ConvParams: " + JsonConvert.SerializeObject(convParams), Severity.Information, null);
                    var conversation = await connectorClient.Conversations.CreateConversationAsync(convParams);

                    BotAdapter ba = (BotAdapter)adapter;

                    var conversationReference = new ConversationReference(conversation.ActivityId);
                    conversationReference.Bot          = bot;
                    conversationReference.ChannelId    = team.ChannelId;
                    conversationReference.Conversation = new ConversationAccount();
                    var convAccount = new ConversationAccount(true, null, conversation.Id);
                    convAccount.TenantId = team.TenantId;

                    conversationReference.Conversation = convAccount;
                    conversationReference.ServiceUrl   = team.ServiceUrl;
                    TelemetryClient.TrackTrace("Sending to Conversation", Severity.Information, null);
                    await ba.ContinueConversationAsync(Configuration["MicrosoftAppId"], conversationReference, ReminderBotCallback, default(CancellationToken));
                }
            }
            catch (Exception ex)
            {
                TelemetryClient.TrackTrace("Error sending reminder: " + ex.Message + ex.StackTrace, Severity.Error, null);
                Logger.LogError(ex, $"Error making pairups: {ex.Message}");
            }
        }