/// <inheritdoc /> /// <summary> /// Intercepts each turn to determine whether the source of the message is from the bespoke DirectLine based NotifyConnector. /// Pushes the outgoing message on to a queue if so. /// </summary> /// <param name="context">The turn context</param> /// <param name="next">the next OnTurn operation in the pipeline</param> /// <param name="cancellationToken"></param> /// <returns>The <see cref="T:System.Threading.Tasks.Task" /></returns> public async Task OnTurnAsync( ITurnContext context, NextDelegate next, CancellationToken cancellationToken = new CancellationToken()) { if (context.Activity.Type == ActivityTypes.Message) { // Create a send activity handler to grab all response activities // from the activity list. context.OnSendActivities( async(activityContext, activityList, activityNext) => { dynamic channelData = context.Activity.ChannelData; if (channelData?.NotifyMessage == null) { return(await activityNext()); } foreach (Activity activity in activityList) { if (activity.Type != ActivityTypes.Message || !activity.HasContent()) { continue; } await this.EnqueueMessageAsync(context, activity); } return(await activityNext()); }); } // Pass execution on to the next layer in the pipeline. await next.Invoke(cancellationToken); }
/// <inheritdoc /> public async Task OnTurnAsync( ITurnContext context, NextDelegate next, CancellationToken cancellationToken = new CancellationToken()) { if (context.Activity.Type == ActivityTypes.Message) { context.OnSendActivities( async(activityContext, activityList, activityNext) => { foreach (Activity activity in activityList) { if (activity.Type != ActivityTypes.Message || !activity.HasContent()) { continue; } if (activity.Id == null) { var dialogState = await feedbackBotStateRepository.ConversationDialogState.GetAsync(context); var dialogInstance = dialogState.DialogStack?.FirstOrDefault()?.State.First().Value as DialogState; activity.Id = dialogInstance?.DialogStack?.FirstOrDefault()?.Id; } } return(await activityNext()); }); } await next.Invoke(cancellationToken); }
/// <inheritdoc /> public async Task OnTurnAsync( ITurnContext context, NextDelegate next, CancellationToken cancellationToken = new CancellationToken()) { if (context.Activity.Type == ActivityTypes.Message) { context.OnSendActivities( async(activityContext, activityList, activityNext) => { foreach (Activity activity in activityList) { if (activity.Type != ActivityTypes.Message || !activity.HasContent()) { continue; } var turnProperty = feedbackBotStateRepository.ConversationState.CreateProperty <long>("turnId"); var turnId = await turnProperty.GetAsync(activityContext, defaultValueFactory: () => 0, cancellationToken: cancellationToken); await turnProperty.SetAsync(activityContext, ++turnId, cancellationToken); await feedbackBotStateRepository.ConversationState.SaveChangesAsync(activityContext, cancellationToken: cancellationToken); } return(await activityNext()); }); } await next.Invoke(cancellationToken); }
public async Task OnTurnAsync(ITurnContext turnContext, NextDelegate next, CancellationToken cancellationToken = default) { Debug.WriteLine($"{turnContext.Activity.From}:{turnContext.Activity.Type}"); Debug.WriteLineIf( !string.IsNullOrEmpty(turnContext.Activity.Text), turnContext.Activity.Text); await next.Invoke(cancellationToken); }
public async Task OnTurnAsync( ITurnContext turnContext, NextDelegate next, CancellationToken cancellationToken = new CancellationToken()) { dynamic channelData = turnContext.Activity.ChannelData; var supported = Enum.TryParse(turnContext.Activity.ChannelId, true, out BotChannel channelId); if (!supported) { channelId = BotChannel.Unsupported; } switch (channelId) { case BotChannel.Slack: if (channelData?.SlackMessage != null) { // only reply in threads if ([email protected]_ts == null) { turnContext.Activity.Conversation.Id += $":{[email protected]}"; } } break; case BotChannel.DirectLine: if (channelData?.NotifyMessage != null) { turnContext.Activity.Conversation.ConversationType = "personal"; turnContext.Activity.Conversation.IsGroup = false; } break; case BotChannel.Sms: // The notify SMS channel doesn't actually use this channel type - it hangs off the DirectLine API (above) break; case BotChannel.Emulator: break; case BotChannel.Unsupported: break; default: throw new ArgumentOutOfRangeException(); } // Pass execution on to the next layer in the pipeline. await next.Invoke(cancellationToken); }
public async Task OnTurnAsync(ITurnContext turnContext, NextDelegate next, CancellationToken cancellationToken = default(CancellationToken)) { /* * throw new System.NotImplementedException(); * //*/ Debug.WriteLine($"{turnContext.Activity.From}:{turnContext.Activity.Type}"); Debug.WriteLineIf( !string.IsNullOrEmpty(turnContext.Activity.Text), turnContext.Activity.Text ); await next.Invoke(cancellationToken); }
public async Task OnTurnAsync(ITurnContext turnContext, NextDelegate next, CancellationToken cancellationToken = default(CancellationToken)) { // If the channel is LINE, then replace ConnectorClient if (turnContext.Activity.ServiceUrl.Contains("https://line")) { if (turnContext.TurnState["Microsoft.Bot.Connector.IConnectorClient"] is ConnectorClient) { turnContext.TurnState.Remove("Microsoft.Bot.Connector.IConnectorClient"); turnContext.TurnState.Add("Microsoft.Bot.Connector.IConnectorClient", new LINEConnectorClient(config) ); } } await next.Invoke(cancellationToken); }
public async Task OnTurnAsync(ITurnContext turnContext, NextDelegate next, CancellationToken cancellationToken = default) { // 添付ファイルがある var activity = turnContext.Activity; if (activity.Type == ActivityTypes.Message && activity.Attachments != null && activity.Attachments.Any()) { await turnContext.SendActivityAsync("テキストを送ってください"); } else { await next.Invoke(cancellationToken); } }
public async Task OnTurnAsync(ITurnContext turnContext, NextDelegate next, CancellationToken cancellationToken = default(CancellationToken)) { /* * throw new System.NotImplementedException(); * //*/ var activity = turnContext.Activity; //添付ファイルのチェック if (activity.Type == ActivityTypes.Message && activity.Attachments != null && activity.Attachments.Count != 0) { //添付ファイルがあるとき await turnContext.SendActivityAsync("テキストを送ってね!"); } else { //添付ファイルがないとき await next.Invoke(cancellationToken); } }
public async Task OnTurnAsync(ITurnContext turnContext, NextDelegate next, CancellationToken cancellationToken = default) { Console.WriteLine("turnContext.Activity.Id : " + turnContext.Activity.Id); Console.WriteLine("turnContext.Activity.MembersAdded : " + turnContext.Activity.MembersAdded); Console.WriteLine("turnContext.Activity.MembersRemoved : " + turnContext.Activity.MembersRemoved); Console.WriteLine("turnContext.Activity.Recipient : " + turnContext.Activity.Recipient); Console.WriteLine("turnContext.Activity.ReplyToId : " + turnContext.Activity.ReplyToId); Console.WriteLine("turnContext.Activity.ServiceUrl : " + turnContext.Activity.ServiceUrl); Console.WriteLine("turnContext.Activity.Text: " + turnContext.Activity.Text); Console.WriteLine("turnContext.Activity.TopicName : " + turnContext.Activity.TopicName); Console.WriteLine("turnContext.Activity.ValueType : " + turnContext.Activity.ValueType); Console.WriteLine("turnContext.Activity.TopicName : " + turnContext.Activity.TopicName); Console.WriteLine("turnContext.Activity.ChannelId : " + turnContext.Activity.ChannelId); Console.WriteLine("turnContext.Activity.From.Id : " + turnContext.Activity.From.Id); Console.WriteLine("turnContext.Activity.From.Name : " + turnContext.Activity.From.Name); Console.WriteLine("turnContext.Activity.From.Role : " + turnContext.Activity.From.Role); Console.WriteLine("turnContext.Activity.Conversation.Id : " + turnContext.Activity.Conversation.Id); Console.WriteLine("turnContext.Activity.Conversation.Name : " + turnContext.Activity.Conversation.Name); Console.WriteLine("turnContext.Activity.Conversation.Role : " + turnContext.Activity.Conversation.Role); Console.WriteLine("turnContext.Activity.Conversation.TenantId : " + turnContext.Activity.Conversation.TenantId); Debug.WriteLine($"{turnContext.Activity.From}:{turnContext.Activity.Type}"); Debug.WriteLineIf( !string.IsNullOrEmpty(turnContext.Activity.Text), turnContext.Activity.Text); // string file_path = System.IO.Path.Combine("/var/logs/test.txt"); // ファイルへテキストデータを書き込む // string file_data = $"{turnContext.Activity.From}:{turnContext.Activity.Type}"; // ファイルのデータ // using (System.IO.StreamWriter sw = new System.IO.StreamWriter(file_path)) // UTF-8のテキスト用 //using (System.IO.StreamWriter sw = new System.IO.StreamWriter(file_path, Encoding.GetEncoding("shift-jis"))) // シフトJISのテキスト用 // { // sw.Write(file_data); // ファイルへテキストデータを出力する // } await next.Invoke(cancellationToken); }
async public Task OnTurnAsync(ITurnContext context, NextDelegate next, CancellationToken cancellationToken = default(CancellationToken)) { Console.WriteLine(context.Activity.Type); switch (context.Activity.Type) { case ActivityTypes.ConversationUpdate: if (context.Activity.MembersAdded != null) { var msg = "Hi! I'm Gartner Bot. You can ask me questions about vendor briefings or the magic quadrant process. I can also find reports for you if you ask me 'get me the top 5 reports about mobile development based on IDE'."; foreach (var newMember in context.Activity.MembersAdded) { if (newMember.Id != context.Activity.Recipient.Id) { await context.SendActivityAsync(msg); } } } break; case ActivityTypes.Message: if (_didHandoff == context.Activity.From.Id || _isWatching == context.Activity.From.Id) { await next.Invoke(cancellationToken); return; } if (context.Activity.Text == "agent-sign-in") { _isWatching = context.Activity.From.Id; context.Activity.Text = "command watch"; context.Activity.From.Role = "agent"; await next.Invoke(cancellationToken); return; } if (_didAskForHandoff == context.Activity.From.Id && context.Activity.Text.Equals("yes", StringComparison.InvariantCultureIgnoreCase)) { _didHandoff = context.Activity.From.Id; //User indicated they want to be connected to live agent context.Activity.Text = "human"; context.Activity.From.Role = "user"; await next.Invoke(cancellationToken); return; } //Get the intent recognition result var recognizerResult = await DispatchService.RecognizeAsync(context, cancellationToken); var topIntent = recognizerResult?.GetTopScoringIntent(); if (topIntent == null) { await AskForHandoff(context, "I'm not quite sure what you mean."); } else { await DispatchToTopIntentAsync(context, topIntent, cancellationToken); } break; } //await next(cancellationToken).ConfigureAwait(false); }