コード例 #1
0
        private static SlackMessage GetSlackMessage(DetectionResults results)
        {
            SlackMessage message = new SlackMessage
            {
                Text        = "Detection Notification",
                Attachments = new List <Attachment>
                {
                    new Attachment
                    {
                        Pretext  = results.ToString(),
                        Text     = $"{results.DeviceName} @ {results.DateTime}",
                        ImageUrl = results.Url
                    }
                }
            };

            return(message);
        }
コード例 #2
0
        public static void Run([EventHubTrigger("AzureIotEvent", Connection = "AzureIotHack_events_IOTHUB", ConsumerGroup = "$Default")] string myEventHubMessage, TraceWriter log)
        {
            log.Info($"C# Event Hub trigger function processed a message: {myEventHubMessage}");
            DetectionResults results = (DetectionResults)JsonConvert.DeserializeObject(myEventHubMessage, typeof(DetectionResults));
            SlackMessage     message = GetSlackMessage(results);

            HttpClient client = new HttpClient
            {
                BaseAddress = new Uri("{Slack Webhook post endpoint}")
            };

            string serializeObject = JsonConvert.SerializeObject(message);

            log.Info($"Serialized Value: {serializeObject}");
            var httpContent = new StringContent(serializeObject);

            client.PostAsync("", httpContent);
        }