Example #1
0
        static void Main(string[] args)
        {
            SlackRepository SR = new SlackRepository();

            SR.SendMessage("<webhookURL>",
                           "#882BD5",
                           "New Alert",
                           "<link>",
                           "AlertTitle!");
        }
Example #2
0
        public async Task AddQuoteSlackEventTest(string input, string expectedQuote, string expectedUser)
        {
            using (var ctx = new ApplicationDbContext(options))
            {
                var repository = new SlackRepository(ctx);
                await repository.AddQuoteAsync(input);


                var quoteDb = ctx.Quote.Include(q => q.User).FirstOrDefault();


                Assert.NotNull(quoteDb);
                Assert.Equal(expectedQuote, quoteDb.Content);
                Assert.Equal(expectedUser, quoteDb.User.Name);
            }
        }
Example #3
0
        public async Task TestVerification()
        {
            using (var ctx = new ApplicationDbContext(options))
            {
                var repository = new SlackRepository(ctx);
                var request    = new SlackEventRequestModel()
                {
                    challenge = "MAH_XALENDI",
                    token     = "MAH_TOQUIN",
                    type      = "url_verification"
                };

                var response = await repository.ProcessRequest(request);

                Assert.Equal(request.challenge, response);
            }
        }
        public async Task <string> Default()
        {
            var multiPart = await Request.Content.ReadAsMultipartAsync();

            var requestJson   = await multiPart.Contents[0].ReadAsStringAsync();
            var requestObject = JsonConvert.DeserializeObject <PlexMessage>(requestJson);

            if (requestObject == null)
            {
                return("Nay");
            }
            if (!requestObject.IsActionable())
            {
                return("Nay");
            }

            var messageContent = new
            {
                icon_emoji  = ":plex:",
                attachments = new[]
                {
                    new
                    {
                        fallback    = "Required plain-text summary of the attachment.",
                        color       = "#a67a2d",
                        title       = requestObject.CreateTitle(),
                        text        = $"{requestObject.Account.title} at ip: { requestObject.Player.publicAddress}",
                        thumb_url   = "http://khaoznet.xyz/host/Pictures/3.png",
                        footer      = requestObject.GetFooter(),
                        footer_icon = requestObject.Account.thumb
                    }
                }
            };

            var slackUrl           = System.Web.Configuration.WebConfigurationManager.AppSettings["SlackUrl"];
            var messageContentJson = JsonConvert.SerializeObject(messageContent);
            var slackRepo          = new SlackRepository();

            slackRepo.SendMessage(slackUrl, messageContentJson);

            return("Yay");
        }