public void CanPostMessageToChannelTest() { //Arrange string token = "xoxp-6704290194-6704290242-6795193635-107a63"; ISlackIntegration slackIntegration = new SlackIntegration(token); //Act var result = slackIntegration.PostMessage("#fortesdoc", "teste de mensagem", "fortesbot"); //Asserts Assert.IsNotNull(result); Console.WriteLine(result); }
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously async Task <(SlackIntegration SlackIntegration, Mock <ISlackConnector> Connector, Mock <ISlackConnection> Connection)> CreateSlackIntegration(bool init = true) { var slackConnectionFake = new Mock <ISlackConnection>(); var slackConnectorFake = new Mock <ISlackConnector>(); slackConnectorFake.Setup(s => s.Connect(It.IsAny <string>(), null)).ReturnsAsync(slackConnectionFake.Object); var slack = new SlackIntegration(slackConnectorFake.Object, "a"); if (init) { await slack.Connect(); } return(slack, slackConnectorFake, slackConnectionFake); }
CreateSlackIntegration(bool init = true) { var slackConnectionFake = new Mock <ISlackConnection>(); var slackConnectorFake = new Mock <ISlackConnector>(); slackConnectorFake.Setup(x => x.Connect(SlackKey)).ReturnsAsync(slackConnectionFake.Object); var slack = new SlackIntegration(slackConnectorFake.Object, SlackKey); if (init) { await slack.Connect(); } return(slack, slackConnectorFake, slackConnectionFake); }
public BBS(IBBSHost host_system, StateObject so, string ConnectionString) { ConnectionTimeStamp = DateTime.Now; _dataInterface = new DataInterface(ConnectionString); Host_System = host_system; State_Object = so; MessageQueueTimer.Enabled = false; MessageQueueTimer.Interval = 100; MessageQueueTimer.Elapsed += new System.Timers.ElapsedEventHandler(MessageQueueTimer_Elapsed); _remoteAddress = so.workSocket.RemoteEndPoint.ToString(); _slackEnabled = (_dataInterface.GetUserDefinedField(0, "SLACKENABLED") == "1"); if (_slackEnabled) { _slackIntegration = new SlackIntegration(_dataInterface); } LoggingAPI.SysLogEntry(_remoteAddress + ": User Connected"); }
public ComicSendingController(ComicStrip comic) { teams = new TeamsIntegration(comic); slack = new SlackIntegration(comic); }
public IIntegration CreateIntegration() { SlackIntegration slack = new SlackIntegration(System.IO.File.ReadAllText("slack_token.txt")); return(slack); }
private static void SendToSlack(MetricConfiguration metricConfiguration, string pathOnS3) { ISlackIntegration slackIntegration = null; IAmazonS3Integration amazonS3Integration = null; if (metricConfiguration.SlackChannel == null) throw new ArgumentNullException("SendToS3", "When SendSignUrlToSlack is true, SendToS3 enabled is required"); if (metricConfiguration.SlackChannel == null) throw new ArgumentNullException("SlackChannel", "When SendSignUrlToSlack is true, SlackChannel is required"); if (metricConfiguration.SlackMessage == null) throw new ArgumentNullException("SlackMessage", "When SendSignUrlToSlack is true, SlackMessage is required"); if (metricConfiguration.SlackToken == null) throw new ArgumentNullException("SlackToken", "When SendSignUrlToSlack is true, SlackToken is required"); if (metricConfiguration.SlackUserName == null) throw new ArgumentNullException("SlackUserName", "When SendSignUrlToSlack is true, SlackUserName is required"); amazonS3Integration = new AmazonS3Integration(metricConfiguration.AwsAccessKey, metricConfiguration.AwsSecretKey); var signedUrl = amazonS3Integration.SignUrl(pathOnS3, "index.html", metricConfiguration.BucketS3, metricConfiguration.SlackUrlExpirationInSeconds.GetValueOrDefault(86400)); var dtExpirationLink = DateTime.Now.AddSeconds(metricConfiguration.SlackUrlExpirationInSeconds.GetValueOrDefault(86400)); Console.WriteLine("Signed Url Metrics Report generated. Date Expiration: {0:u}.", dtExpirationLink); slackIntegration = new SlackIntegration(metricConfiguration.SlackToken); slackIntegration.PostMessage(metricConfiguration.SlackChannel, string.Format("{0}{1}. Link expire at {2}: ", metricConfiguration.SlackMessage, signedUrl, dtExpirationLink), metricConfiguration.SlackUserName); Console.WriteLine("Link Url Metrics Report sent to Slack: {0}. Dt Expiration", signedUrl); }
private void SetupIntegrations() { string discordToken = "", slackToken = ""; try { discordToken = System.IO.File.ReadAllText("discord_token.txt"); slackToken = System.IO.File.ReadAllText("slack_token.txt"); } catch (System.IO.FileNotFoundException) { Console.WriteLine("Missing tokens! discord_token.txt, slack_token.txt"); Environment.Exit(0); } IntegrationThreads.Clear(); foreach (IntegrationType integration in Enum.GetValues(typeof(IntegrationType))) { if (integration == IntegrationType.Discord) { IntegrationCancellations[integration] = new CancellationTokenSource(); IntegrationThreads[integration] = Task.Run(() => { DiscordIntegration discord = new DiscordIntegration(discordToken); SetupCommands(IntegrationType.Discord, discord); discord.StartIntegration(); discord.Connected += (sender, e) => { Log(IntegrationType.Discord, $"Discord connected!"); }; discord.ConnectionClosed += (sender, e) => { Console.ForegroundColor = ConsoleColor.Red; Console.Write("[Discord Error]: "); Console.ForegroundColor = ConsoleColor.White; Console.Write($"Socket Closed. Code: {e.Code}, Reason: {e.Reason}, Clean?: {e.Clean}\n"); }; discord.MessageReceived += (sender, e) => { Log(IntegrationType.Discord, string.Format("Message from {0} in #{1}: {2}", e.Member.Name, e.Channel.Name, e.Text)); if (e.Text.Length > 0 && e.Text[0] == '-') { try { CommandManagers[IntegrationType.Discord].ExecuteOnMessageCommand(e.Text.Substring(1), e.Channel, e.Member); } catch { } } }; }, IntegrationCancellations[integration].Token); } else if (integration == IntegrationType.Slack) { IntegrationCancellations[integration] = new CancellationTokenSource(); IntegrationThreads[integration] = Task.Run(() => { SlackIntegration slackClient = new SlackIntegration(slackToken); SetupCommands(IntegrationType.Slack, slackClient); slackClient.StartIntegration(); slackClient.Connected += (sender, e) => { Log(integration, "Connected to Slack!"); }; slackClient.MessageReceived += (x, s) => { Log(integration, string.Format("Message from {0} in {1}: {2}", s.Member.Name, s.Channel.Name, s.Text)); if (s.Text.Length > 0 && s.Text[0] == '-') { try { CommandManagers[IntegrationType.Slack].ExecuteOnMessageCommand(s.Text.Substring(1), s.Channel, s.Member); } catch { } } }; }, IntegrationCancellations[integration].Token); } } }