Beispiel #1
0
        private static StackCard CreateCard(Question q)
        {
            var sc = new StackCard(q.QuestionId.ToString());

            sc.Card.summary = $"New question posted on StackOverflow from {q.Owner.DisplayName}";

            sc.Card.sections[0].startGroup       = true;
            sc.Card.sections[0].title            = $"**{q.Title}**";
            sc.Card.sections[0].activityImage    = q.Owner.ProfileImage;
            sc.Card.sections[0].activityTitle    = $"Posted by: [**{q.Owner.DisplayName}**]({q.Owner.Link})";
            sc.Card.sections[0].activitySubtitle = $"Created: {q.CreationDate.ToUniversalTime().ToShortDateString()} {q.CreationDate.ToUniversalTime().ToShortTimeString()}";

            sc.Card.sections[0].facts[0].name = "Tags";

            var tags = "";

            foreach (var t in q.Tags)
            {
                tags += $"[{t}](https://stackoverflow.com/questions/tagged/{t}), ";
            }
            tags.TrimEnd(", ".ToCharArray());

            sc.Card.sections[0].facts[0].value = tags;

            sc.Card.sections[0].facts[1].name  = "Views:";
            sc.Card.sections[0].facts[1].value = q.ViewCount.ToString();

            sc.Card.sections[0].facts[2].name  = "Up Vote:";
            sc.Card.sections[0].facts[2].value = q.UpVoteCount.ToString();

            sc.Card.sections[0].facts[3].name  = "Down Vote:";
            sc.Card.sections[0].facts[3].value = q.DownVoteCount.ToString();

            sc.Card.sections[0].facts[4].name  = "Favorited:";
            sc.Card.sections[0].facts[4].value = q.FavoriteCount.ToString();

            sc.Card.sections[0].potentialAction[0].type = "OpenUri";
            sc.Card.sections[0].potentialAction[0].name = "View on StackOverflow";

            sc.Card.sections[0].potentialAction[0].targets[0].os  = "default";
            sc.Card.sections[0].potentialAction[0].targets[0].uri = q.Link;

            sc.Card.sections[0].potentialAction[0].targets[1].os  = "iOS";
            sc.Card.sections[0].potentialAction[0].targets[1].uri = q.Link;

            sc.Card.sections[0].potentialAction[0].targets[2].os  = "android";
            sc.Card.sections[0].potentialAction[0].targets[2].uri = q.Link;

            return(sc);
        }
Beispiel #2
0
 public static async Task RunQueue(
     [QueueTrigger("questions", Connection = "AzureWebJobsStorage")] StackCard question,
     [DocumentDB("questionDatabase", "questions", ConnectionStringSetting = "stackoverazure_documentdb", Id = "{Id}", CreateIfNotExists = true)] dynamic inDocument,
     [DocumentDB("questionDatabase", "questions", ConnectionStringSetting = "stackoverazure_documentdb")] IAsyncCollector <dynamic> outDocuments,
     TraceWriter log)
 {
     if (question != null)
     {
         if (inDocument == null)
         {
             await outDocuments.AddAsync(question);
             await SendToTeams(question);
         }
     }
 }
Beispiel #3
0
        private static async Task <string> SendToTeams(StackCard question)
        {
            var    webhook  = Util.GetSetting("TeamWebhookUri");
            string jsonCard = JsonConvert.SerializeObject(question.Card, Formatting.Indented);

            using (var client = new HttpClient())
            {
                var request = new HttpRequestMessage(HttpMethod.Post, webhook);

                request.Content = new StringContent(jsonCard, Encoding.UTF8, "application/json");

                var result = await client.SendAsync(request);

                return(await result.Content.ReadAsStringAsync());
            }
        }