public void GenerateString_ShouldBeExpectedMessage(ChatMessage message, string expected) { //Arrange //Act var result = ChatMessageHelper.GenerateString(message); //Assert Assert.Equal(expected, result); }
public async Task <string> GetMessageAsync(RebalanceOperation message) { _log.Info("Wallets Rebalancer Provider - formatting a message...", message); var messageText = await GetMessage(message); _log.Info("Wallets Rebalancer Provider - finished formatting a message.", messageText); return(ChatMessageHelper.CheckSizeAndCutMessageIfNeeded(messageText)); }
public Task <string> GetWarningMessageAsync(IList <BalanceIssueDto> balancesWithIssues) { var sb = new StringBuilder(); sb.AppendLine($"======= {DateTime.UtcNow:yyyy/MM/dd HH:mm:ss} =======\r\n\r\n" + "Balances Warnings:\r\n"); foreach (var balanceIssue in balancesWithIssues) { sb.AppendLine($"Wallet Id: {balanceIssue.ClientId}\r\n" + $"Wallet Name: {balanceIssue.Name}\r\n" + $"Asset: {(!string.IsNullOrWhiteSpace(balanceIssue.AssetName) ? balanceIssue.AssetName : balanceIssue.AssetId)}\r\n" + $"Balance: {balanceIssue.Balance:0.000}\r\n" + $"Min Balance: {balanceIssue.MinBalance:0.000}"); sb.AppendLine(); } return(Task.FromResult(ChatMessageHelper.CheckSizeAndCutMessageIfNeeded(sb.ToString()))); }
public Task <string> GetWarningMessageAsync(IMarketMakersArbitragesWarning mmArbitrages) { var sb = new StringBuilder(); sb.AppendLine($"====== {DateTime.UtcNow:yyyy/MM/dd HH:mm:ss} ======"); sb.Append(Environment.NewLine); sb.AppendLine("Market Maker Arbitrages Warning"); sb.Append(Environment.NewLine); sb.AppendLine($"Total: {mmArbitrages.ArbitragesCount}"); if (mmArbitrages.BiggestSpread.HasValue) { sb.AppendLine($"by Spread: {mmArbitrages.BiggestSpread:0.##}%"); sb.AppendLine($"{ mmArbitrages.BiggestSpreadRow}"); } if (mmArbitrages.BiggestPnlInUsd.HasValue) { sb.AppendLine($"by PnL: ${mmArbitrages.BiggestPnlInUsd:0}"); sb.AppendLine($"{mmArbitrages.BiggestPnlInUsdRow}"); } if (mmArbitrages.BiggestVolumeInUsd.HasValue) { sb.AppendLine($"by Volume: ${mmArbitrages.BiggestVolumeInUsd:0}"); sb.AppendLine($"{mmArbitrages.BiggestVolumeInUsdRow}"); } if (mmArbitrages.MostFrequentAssetPairs.Length > 0) { sb.Append(Environment.NewLine); sb.AppendLine($"Most used asset pairs:"); sb.AppendLine($"{mmArbitrages.MostFrequentAssetPairs}"); } if (mmArbitrages.MarketMakers.Length > 0) { sb.Append(Environment.NewLine); sb.AppendLine($"All market makers involved: {mmArbitrages.MarketMakers}"); } return(Task.FromResult(ChatMessageHelper.CheckSizeAndCutMessageIfNeeded(sb.ToString()))); }
private async Task ReciveMessages(CancellationToken cancellationToken) { while (!cancellationToken.IsCancellationRequested) { var messages = await _chatApiClient.GetChatMessagesAsync(); var filteredMessages = messages.Where(message => message.IdChatMessage > _lastDisplayedId) .OrderBy(message => message.IdChatMessage) .ToList(); if (filteredMessages.Count == 1 && filteredMessages.Last().Author == _user.Name) { OverwriteLastLine?.Invoke(this, null); } foreach (var message in filteredMessages) { NewMessageRecived?.Invoke(this, ChatMessageHelper.GenerateString(message)); _lastDisplayedId = message.IdChatMessage; } await Task.Delay(500); } }
public async Task <ActionResult> SendNotificationToUser(TaskInfo taskInfo) { TaskHelper.AddTaskToFeed(taskInfo); var graphClient = SimpleGraphClient.GetGraphClient(taskInfo.access_token); var graphClientApp = SimpleGraphClient.GetGraphClientforApp(_configuration["AzureAd:MicrosoftAppId"], _configuration["AzureAd:MicrosoftAppPassword"], _configuration["AzureAd:TenantId"]); var user = await graphClient.Users[taskInfo.userName] .Request() .GetAsync(); var installedApps = await graphClient.Users[user.Id].Teamwork.InstalledApps .Request() .Expand("teamsAppDefinition") .GetAsync(); var installationId = installedApps.Where(id => id.TeamsAppDefinition.DisplayName == "NotifyFeedApp").Select(x => x.Id); var userName = user.UserPrincipalName; if (taskInfo.taskInfoAction == "customTopic") { ChatMessageHelper chatMessage = new ChatMessageHelper(_configuration); var getChannelMessage = await chatMessage.CreateChatMessageForChannel(taskInfo, taskInfo.access_token); var customTopic = new TeamworkActivityTopic { Source = TeamworkActivityTopicSource.Text, Value = "Deployment Approvals Channel", WebUrl = getChannelMessage.WebUrl }; var CustomActivityType = "deploymentApprovalRequired"; var CustomPreviewText = new ItemBody { Content = "New deployment requires your approval" }; var CustomTemplateParameters = new List <Microsoft.Graph.KeyValuePair>() { new Microsoft.Graph.KeyValuePair { Name = "deploymentId", Value = "6788662" } }; try { await graphClientApp.Users[user.Id].Teamwork .SendActivityNotification(customTopic, CustomActivityType, null, CustomPreviewText, CustomTemplateParameters) .Request() .PostAsync(); } catch (Exception ex) { Console.WriteLine(ex); } } else { ViewBag.taskID = new Guid(); var topic = new TeamworkActivityTopic { Source = TeamworkActivityTopicSource.EntityUrl, Value = "https://graph.microsoft.com/beta/users/" + user.Id + "/teamwork/installedApps/" + installationId.ToList()[0] }; var activityType = "taskCreated"; var previewText = new ItemBody { Content = "New Task Created" }; var templateParameters = new List <Microsoft.Graph.KeyValuePair>() { new Microsoft.Graph.KeyValuePair { Name = "taskName", Value = taskInfo.title } }; try { await graphClientApp.Users[user.Id].Teamwork .SendActivityNotification(topic, activityType, null, previewText, templateParameters) .Request() .PostAsync(); } catch (Exception ex) { Console.WriteLine(ex); } } return(View("Index")); }
public async Task <ActionResult> sendNotificationToTeam(TaskInfo taskInfo) { TaskHelper.AddTaskToFeed(taskInfo); var graphClient = SimpleGraphClient.GetGraphClient(taskInfo.access_token); var graphClientApp = SimpleGraphClient.GetGraphClientforApp(_configuration["AzureAd:MicrosoftAppId"], _configuration["AzureAd:MicrosoftAppPassword"], _configuration["AzureAd:TenantId"]); var user = await graphClient.Users[taskInfo.userName] .Request() .GetAsync(); if (taskInfo.taskInfoAction == "customTopic") { ChatMessageHelper chatMessage = new ChatMessageHelper(_configuration); var getChannelMessage = await chatMessage.CreateChatMessageForChannel(taskInfo, taskInfo.access_token); var customTopic = new TeamworkActivityTopic { Source = TeamworkActivityTopicSource.Text, Value = "Deployment Approvals Channel", WebUrl = getChannelMessage.WebUrl }; var CustomActivityType = "approvalRequired"; var CustomPreviewText = new ItemBody { Content = "New deployment requires your approval" }; var customRecipient = new AadUserNotificationRecipient { UserId = user.Id }; var CustomTemplateParameters = new List <Microsoft.Graph.KeyValuePair>() { new Microsoft.Graph.KeyValuePair { Name = "approvalTaskId", Value = "5654653" } }; try { await graphClientApp.Teams[taskInfo.teamId] .SendActivityNotification(customTopic, CustomActivityType, null, CustomPreviewText, CustomTemplateParameters, customRecipient) .Request() .PostAsync(); } catch (Exception ex) { Console.WriteLine(ex); } } else if (taskInfo.taskInfoAction == "channelTab") { ChatMessageHelper chatMessage = new ChatMessageHelper(_configuration); var getChannelMessage = chatMessage.CreateChannelMessageAdaptiveCard(taskInfo, taskInfo.access_token); var tabs = await graphClient.Teams[taskInfo.teamId].Channels[taskInfo.channelId].Tabs .Request() .Expand("teamsApp") .GetAsync(); var tabId = tabs.Where(a => a.DisplayName == "NotifyFeedApp").Select(x => x.Id).ToArray()[0]; var topic = new TeamworkActivityTopic { Source = TeamworkActivityTopicSource.EntityUrl, Value = "https://graph.microsoft.com/beta/teams/" + taskInfo.teamId + "/channels/" + taskInfo.channelId + "/tabs/" + tabId }; var activityType = "reservationUpdated"; var previewText = new ItemBody { Content = "Your Reservation Updated:" }; var recipient = new AadUserNotificationRecipient { UserId = user.Id }; var templateParameters = new List <Microsoft.Graph.KeyValuePair>() { new Microsoft.Graph.KeyValuePair { Name = "reservationId", Value = taskInfo.reservationId }, new Microsoft.Graph.KeyValuePair { Name = "currentSlot", Value = taskInfo.currentSlot } }; try { await graphClientApp.Teams[taskInfo.teamId] .SendActivityNotification(topic, activityType, null, previewText, templateParameters, recipient) .Request() .PostAsync(); } catch (Exception ex) { Console.WriteLine(ex); } } else { ChatMessageHelper chatMessage = new ChatMessageHelper(_configuration); var getChannelMessage = await chatMessage.CreatePendingFinanceRequestCard(taskInfo, taskInfo.access_token); var topic = new TeamworkActivityTopic { Source = TeamworkActivityTopicSource.Text, WebUrl = getChannelMessage.WebUrl, Value = "Deep Link to Chat" }; var activityType = "pendingFinanceApprovalRequests"; var previewText = new ItemBody { Content = "These are the count of pending request pending request:" }; var recipient = new AadUserNotificationRecipient { UserId = user.Id }; var templateParameters = new List <Microsoft.Graph.KeyValuePair>() { new Microsoft.Graph.KeyValuePair { Name = "pendingRequestCount", Value = "5" } }; try { await graphClientApp.Teams[taskInfo.teamId] .SendActivityNotification(topic, activityType, null, previewText, templateParameters, recipient) .Request() .PostAsync(); } catch (Exception ex) { Console.WriteLine(ex); } } return(View("teamnotification")); }
public async Task <ActionResult> SendNotificationToGroupChat(TaskInfo taskInfo) { TaskHelper.AddTaskToFeed(taskInfo); var graphClient = SimpleGraphClient.GetGraphClient(taskInfo.access_token); var graphClientApp = SimpleGraphClient.GetGraphClientforApp(_configuration["AzureAd:MicrosoftAppId"], _configuration["AzureAd:MicrosoftAppPassword"], _configuration["AzureAd:TenantId"]); var user = await graphClient.Users[taskInfo.userName] .Request() .GetAsync(); if (taskInfo.taskInfoAction == "customTopic") { ChatMessageHelper chatMessage = new ChatMessageHelper(_configuration); var getChatMessage = chatMessage.CreateGroupChatMessage(taskInfo, taskInfo.access_token); var customTopic = new TeamworkActivityTopic { Source = TeamworkActivityTopicSource.EntityUrl, Value = "https://graph.microsoft.com/beta/chats/" + taskInfo.chatId + "/messages/" + getChatMessage.Id }; var CustomActivityType = "approvalRequired"; var CustomPreviewText = new ItemBody { Content = "Deployment requires your approval" }; var customRecipient = new AadUserNotificationRecipient { UserId = user.Id }; var CustomTemplateParameters = new List <Microsoft.Graph.KeyValuePair>() { new Microsoft.Graph.KeyValuePair { Name = "approvalTaskId", Value = "2020AAGGTAPP" } }; try { await graphClientApp.Chats[taskInfo.chatId] .SendActivityNotification(customTopic, CustomActivityType, null, CustomPreviewText, CustomTemplateParameters, customRecipient) .Request() .PostAsync(); } catch (Exception ex) { Console.WriteLine(ex); } } else { var topic = new TeamworkActivityTopic { Source = TeamworkActivityTopicSource.EntityUrl, Value = "https://graph.microsoft.com/beta/chats/" + taskInfo.chatId }; var activityType = "taskCreated"; var previewText = new ItemBody { Content = "Hello:" }; var recipient = new AadUserNotificationRecipient { UserId = user.Id }; var templateParameters = new List <Microsoft.Graph.KeyValuePair>() { new Microsoft.Graph.KeyValuePair { Name = "taskName", Value = taskInfo.title } }; try { await graphClientApp.Chats[taskInfo.chatId] .SendActivityNotification(topic, activityType, null, previewText, templateParameters, recipient) .Request() .PostAsync(); } catch (Exception ex) { Console.WriteLine(ex); } } return(View("groupchatnotification")); }
public void InformarNuevoMensaje(DTONuevoMensajeChat nuevoMensajeChat) { ChatMessageHelper.InformarNuevoMensaje(nuevoMensajeChat); }
public void InformarNuevoGrupo(DTONuevoChat nuevoChat) { ChatMessageHelper.InformarNuevoGrupo(nuevoChat); }
public void EnviarMensaje(DTOChat chat) { ChatMessageHelper.PublicarMensajes(chat); }
public async Task <string> GetAuditMessageAsync(AuditMessage auditMessage) { var message = await GetAuditMessage(auditMessage); return(ChatMessageHelper.CheckSizeAndCutMessageIfNeeded(message)); }
public async Task <string> GetStateMessageAsync(InventorySnapshotModel prevSnapshot, InventorySnapshotModel snapshot) { var messageText = await GetStateMessage(prevSnapshot, snapshot); return(ChatMessageHelper.CheckSizeAndCutMessageIfNeeded(messageText)); }