Example #1
0
        private async Task GetMarvel(SlackCommandRequest slackCommandRequest)
        {
            var marvelGoogleCx = Environment.GetEnvironmentVariable("MARVEL_GOOGLE_CX", EnvironmentVariableTarget.Process);
            var gsr            = await GetGoogleSearchSlackResponseJson(slackCommandRequest.Text, marvelGoogleCx);

            if (gsr != null)
            {
                var client  = new SbmClient(slackCommandRequest.ResponseUrl);
                var message = new Message();

                var gsrMetaTags = gsr.Items.ElementAtOrDefault(0)?.PageMap.MetaTags.ElementAtOrDefault(0) ?? new MetaTag();
                var snippet     = gsr.Items.ElementAtOrDefault(0)?.Snippet.CleanString() ?? string.Empty;

                var title = gsr.Items.ElementAtOrDefault(0)?.Title.Split("|").ElementAtOrDefault(0)?.Trim();

                var attachment = new Attachment()
                {
                    Fallback = snippet,
                    Pretext  = $"Excelsior! I found {title} :star-struck:!"
                }
                .AddField("Name", title, true)
                .AddField("Website", gsrMetaTags.OgUrl, true)
                .AddField("Bio", snippet)
                .SetImage(gsr.Items[0].PageMap.CseImage[0].Src)
                .SetColor(Color.Green);

                message.AddAttachment(attachment);
                var response = await client.SendAsync(message);

                if (response == "ok")
                {
                    _logger.LogInformation("GetMarvel: Sent message {@Message}", message);
                }
                else
                {
                    _logger.LogError("GetMarvel: Error sending {@Message}", message);
                }
            }
            else
            {
                _logger.LogError("GetMarvel: GetGoogleSearchSlackResponseJson is null. {@SlackCommandRequest}", slackCommandRequest);
            }
        }
Example #2
0
        private async Task GetTest(SlackCommandRequest slackCommandRequest)
        {
            var client  = new SbmClient(slackCommandRequest.ResponseUrl);
            var message = new Message();

            const string bio = @"I’m a techie inside and out. If it involves technology, chances are I’ve at least dabbled with it. "
                               + "I enjoy helping people and organizations learn how to leverage technology to level up their lives or organization. "
                               + "I’ve worn many hats from having my own businesses, helping startups launch, and developing small to large scale web applications & APIs utilizing .NET & C# as the backend for many of my projects."
                               + "\n\nCombining my interests in technology and sociology, I’m simply passionate about the human side of technology… and Marvel Comics.";

            var attachment = new Attachment()
            {
                Fallback = $"Testing for {slackCommandRequest.Text}",
                Pretext  = $"Testing for {slackCommandRequest.Text}"
            }
            .AddField("Name", "AJ Tatum", true)
            .AddField("Website", "https://ajt.io", true)
            .AddField("Bio", bio)
            .SetThumbUrl("https://ajtatum.com/wp-content/uploads/2014/08/AJ-Tatum-120x120.png")
            .SetColor(Color.Green);

            message.AddAttachment(attachment);
            await client.SendAsync(message);
        }