public async Task Test(string msg) { const string TOKEN = "TODO-TBD"; var slackClient = new SlackTaskClient(TOKEN); var response = await slackClient.PostMessageAsync("#general", msg); }
public SlackApiWrapper(IOptions <SlackConfig> cfg, ILogger <SlackApiWrapper> logger, IHttpClientFactory http) { _token = cfg.Value.OauthToken; _client = new SlackTaskClient(cfg.Value.OauthToken); _logger = logger; _http = http; }
public BotSendMessageController(IConfiguration configuration, ILogger <BotSendMessageController> logger) { _logger = logger; var token = configuration["SlackToken"]; var slackClient = new SlackTaskClient(token); _client = slackClient; }
public async Task Start(string token) { // SlackAPI Examples: https://github.com/Inumedia/SlackAPI/wiki/Examples reactions = MessageReaction.GetReactions <IMessageReaction>().ToList(); this.slackClient = new SlackTaskClient(token); //this.slackClient.Connect((connection) => { clientReady.Set(); }); //this.slackClient.OnMessageReceived += ConnectOnOnMessageReceived; }
public MessageSender(AppConfig appConfig) { _slackClient = new SlackTaskClient(appConfig.SlackToken); if (appConfig.RunTelegramBot) { _telegramClient = new TelegramBotClient(appConfig.TelegramToken, new HttpToSocks5Proxy(appConfig.TelegramProxyHost, appConfig.TelegramProxyPort)); } _isMocked = appConfig.MockSender; }
public SlackService(string token) { SlackClient = new SlackTaskClient(token); Task <string> task = Task.Run(GetUserIdBasedOnToken); task.Wait(); UserIdOfToken = task.Result; }
private async Task SendSlackMessageAsync(string message) { var client = new SlackTaskClient(_slackApiToken); _logger.Log("Sending message '{0}'", message); var response = await client.PostMessageAsync(_targetChannel, message, linkNames : true, as_user : true); response.AssertOk(); }
public SlackBotClient( IOptions <SlackBotOptions> options, ILogger <SlackBotClient> logger) { SlackBotOptions = options.Value; SlackTaskClient = new SlackTaskClient(SlackBotOptions.Token); SlackSocketClient = new SlackSocketClient(SlackBotOptions.Token); Logger = logger; }
public async Task <string> GetManualDiary() { var client = new SlackTaskClient(OAuthAccessToken); var channels = await client.GetChannelListAsync(); var diaryChannel = channels.channels .Where(x => x.name == "diary") .FirstOrDefault(); if (diaryChannel == null) { Console.WriteLine("not found diary channel."); return(null); } var history = await client.GetChannelHistoryAsync(diaryChannel); var yesterday = DateTime.UtcNow.AddDays(-1); var stringBuilder = new StringBuilder(); var targetMessages = history.messages .Where(x => string.IsNullOrEmpty(x.subtype)) .Reverse() .ToArray(); foreach (var targetMessage in targetMessages) { var messageUtc = targetMessage.ts.ToUniversalTime(); if (messageUtc >= yesterday) { stringBuilder.AppendLine("(jst) " + messageUtc.AddHours(9).ToString("yyyy/MM/dd HH:mm:ss")); var lines = targetMessage.text.Split('\n'); foreach (var line in lines) { if (line.StartsWith("<http") && line.EndsWith(">")) { var url = line.TrimStart('<').TrimEnd('>'); stringBuilder.AppendLine(url); } else { stringBuilder.AppendLine(line); } } stringBuilder.AppendLine(); } } return(stringBuilder.ToString()); }
public SlackTransactionsIncrementPublisher( ILogFactory logFactory, TransactionsReportWriter writer, SlackSettings settings) { _log = logFactory.CreateLog(this); _writer = writer; _settings = settings; _client = new SlackTaskClient(settings.AuthToken); }
private bool SendToSlack(string message) { var token = GetSecret("slack-token"); var client = new SlackTaskClient(token); var channel = "signup"; var response = client.PostMessageAsync(channel, message); return(response.Result.ok); }
public SlackClient( ILogger <SlackClient> log, IEntityRepository <Dao.SlackMessage> slackMessageRepository, SlackClientWrapper actualClient, ISlackApiClient netStandardSlackClient ) { _log = log; _slackMessageRepository = slackMessageRepository; _actualClient = actualClient; _netStandardSlackClient = netStandardSlackClient; }
static async Task CheckStuff(SlackTaskClient slackClient, Channel channel, UserListResponse users) { await _semaphore.WaitAsync(); threadCount++; //Console.WriteLine("Thread {0} starting", threadCount); try { var history = await slackClient.GetChannelHistoryAsync(channel, null, DateTime.Now.AddDays(-7), 1000); if (history.messages == null) { Console.WriteLine("Rate Limited: Backing Off for 10s"); await Task.Delay(10000); history = await slackClient.GetChannelHistoryAsync(channel, null, DateTime.Now.AddDays(-7), 1000); if (history.messages == null) { throw new Exception("Something went bad. You was rate limited"); } } if (history.messages.Count() == 0) { return; } Console.WriteLine("{0}: Count: {1}, More Messages? : {2}", channel.name, history.messages.Count(), history.has_more); foreach (var message in history.messages) { var user = users.members.FirstOrDefault(s => s.id == message.user); var name = user != null ? user.name : "bot or unknown"; lock (key) { peoples.Add(name); } } } catch (Exception e) { Console.WriteLine("Exception: " + e.Message); throw; } finally { //Console.WriteLine("Thread {0} finished", threadCount); threadCount--; _semaphore.Release(); } }
static async Task Main(string[] args) { string TOKEN = Environment.GetEnvironmentVariable("SLACK_TOKEN"); if (String.IsNullOrEmpty(TOKEN)) { throw new Exception("Please provide a SLACK_TOKEN environment variable"); } var dop = Environment.GetEnvironmentVariable("SLACK_MAXDOP"); var dopValue = 1; if (dop != null && Int32.TryParse(dop, out dopValue)) { MAX_DEGREE_OF_PARALLELISM = dopValue; } Console.WriteLine("Parallel processing threads: " + MAX_DEGREE_OF_PARALLELISM); var slackClient = new SlackTaskClient(TOKEN); var list = await slackClient.GetChannelListAsync(); Console.WriteLine("channels: " + list.channels.Count()); var users = await slackClient.GetUserListAsync(); Console.WriteLine("users: " + users.members.Count()); var tasks = new List <Task>(); foreach (var channel in list.channels) { tasks.Add(CheckStuff(slackClient, channel, users)); } await Task.WhenAll(tasks.ToArray()); Console.WriteLine(""); Console.WriteLine("------------------------------------------------------------"); Console.WriteLine(""); var counts = peoples.GroupBy(s => s).OrderByDescending(x => x.Count()); foreach (var cnt in counts) { Console.WriteLine(cnt.Key + ": " + cnt.Count()); } }
/// <summary> /// Initializes a new instance of the <see cref="SlackClientWrapper"/> class. /// Creates a Slack client by supplying the access token. /// </summary> /// <param name="options">An object containing API credentials, a webhook verification token and other options.</param> public SlackClientWrapper(SlackClientWrapperOptions options) { Options = options ?? throw new ArgumentNullException(nameof(options)); if (string.IsNullOrWhiteSpace(options.SlackVerificationToken) && string.IsNullOrWhiteSpace(options.SlackClientSigningSecret)) { const string message = "****************************************************************************************" + "* WARNING: Your bot is operating without recommended security mechanisms in place. *" + "* Initialize your adapter with a clientSigningSecret parameter to enable *" + "* verification that all incoming webhooks originate with Slack: *" + "* *" + "* var adapter = new SlackAdapter({clientSigningSecret: <my secret from slack>}); *" + "* *" + "****************************************************************************************" + ">> Slack docs: https://api.slack.com/docs/verifying-requests-from-slack"; throw new InvalidOperationException(message + Environment.NewLine + "Required: include a verificationToken or clientSigningSecret to verify incoming Events API webhooks"); } _api = new SlackTaskClient(options.SlackBotToken); LoginWithSlackAsync(default).Wait();
public async Task <bool> SendToSlack(string channel, string message, byte[] file, string fileName, string fileType) { try { SlackTaskClient slackClient = new SlackTaskClient(configuration["Slack:Token"]); var response = await slackClient.UploadFileAsync(file, fileName, new string[] { channel }, initialComment : message, fileType : fileType); if (response.ok) { return(true); } else { logger.LogError($"Failed to send file notification to slack."); return(false); } } catch (Exception ex) { logger.LogError(ex, $"Failed to send file notification to slack. ({ex.GetType().Name}: {ex.Message})"); return(false); } }
public async Task <bool> SendToSlack(string channel, string message) { try { SlackTaskClient slackClient = new SlackTaskClient(configuration["Slack:Token"]); var response = await slackClient.PostMessageAsync(channel, message); if (response.ok) { return(true); } else { logger.LogError($"Failed to send notification to slack."); return(false); } } catch (Exception ex) { logger.LogError(ex, $"Failed to send notification to slack. ({ex.GetType().Name}: {ex.Message})"); return(false); } }
private async Task sendDM(string whoSent, string message) { var token = Environment.GetEnvironmentVariable("SLACK_ACCESS_TOKEN"); if (token == null) { throw new Exception("Error getting slack token from ssm"); } var client = new SlackTaskClient(token); var response = await client.PostMessageAsync(whoSent, message, null, null, false, null, null, false, null, null, true); // process response from API call if (response.ok) { Console.WriteLine("Message sent successfully"); } else { Console.WriteLine("Message sending failed. error: " + response.error); } }
public SlackClient(SlackTaskClient slackTaskClient) { _slackTaskClient = slackTaskClient ?? throw new ArgumentNullException(nameof(slackTaskClient)); }
public Chirpy(string token, string channel) { _client = new SlackTaskClient(token); _channel = channel; }