Пример #1
0
        public static async Task SaveMessageToStorageAccount(EmailSubmission submission)
        {
            var connectionString  = Environment.GetEnvironmentVariable("AZURE_STORAGE_CONNECTION_STRING");
            var blobServiceClient = new BlobServiceClient(connectionString);
            var containerName     = DateTime.Now.ToString("yyyy-MM-dd");
            var containerClient   = blobServiceClient.GetBlobContainerClient(containerName);
            await containerClient.CreateIfNotExistsAsync();

            var blobClient = containerClient.GetBlobClient(DateTime.Now.ToString("O"));

            var options = new JsonSerializerOptions {
                WriteIndented = true
            };

            await using var ms = new MemoryStream(Encoding.UTF8.GetBytes(JsonSerializer.Serialize(submission, options)));
            await blobClient.UploadAsync(ms);
        }
Пример #2
0
        public static async Task PostMessageToSlack(EmailSubmission submission, Guid id, Uri uri)
        {
            var payload = new SlackPayload()
            {
                Attachments = new List <SlackAttachment>()
                {
                    new SlackAttachment()
                    {
                        Pretext    = "New submission",
                        Title      = submission.Subject,
                        AuthorName = $"{submission.Name} <{submission.Email}>",
                        Text       = submission.Content,
                    },
                    new SlackAttachment()
                    {
                        Fallback   = "Your client does not support approving/rejecting messages",
                        CallbackId = "submit",
                        Actions    = new List <SlackAction>()
                        {
                            new SlackAction()
                            {
                                Name    = "approve",
                                Text    = "Approve",
                                Style   = "primary",
                                Type    = "button",
                                Value   = id.ToString(),
                                Confirm = new SlackConfirm()
                                {
                                    Text        = "Are you sure you want to approve this message?",
                                    OkText      = "Yes",
                                    DismissText = "Not right now"
                                }
                            },
                            new SlackAction()
                            {
                                Name    = "reject",
                                Text    = "Reject",
                                Type    = "button",
                                Confirm = new SlackConfirm()
                                {
                                    Text        = "Are you sure you want to reject this message?",
                                    OkText      = "Yes",
                                    DismissText = "Not right now"
                                }
                            }
                        }
                    }
                }
            };

            if (submission.Recipients?.Count > 0)
            {
                payload.Attachments[0].Fields = new List <SlackField>()
                {
                    new SlackField()
                    {
                        Title = "Recipients",
                        Value = string.Join(", ", submission.Recipients),
                        Short = false,
                    }
                };
            }
            await PostMessage(payload, uri);
        }