コード例 #1
0
        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);
            }
        }
コード例 #2
0
        public async Task Publish(HashSet <Transaction> increment, DateTime incrementFrom, DateTime incrementTo)
        {
            var fileName = $"transactions-{incrementTo:s}.csv";

            _log.Info($"Uploading transactions increment to Slack {fileName}...");

            using (var stream = new MemoryStream())
            {
                await _writer.WriteAsync(increment, stream, leaveOpen : true);

                stream.Position = 0;

                await _client.UploadFileAsync
                (
                    stream.ToArray(),
                    fileName,
                    new[] { _settings.ReportChannel },
                    title : $"Transactions for the period {incrementFrom:s} - {incrementTo:s}"
                );
            }

            _log.Info($"Transactions increment with {increment.Count} transactions uploaded to Slack");
        }