コード例 #1
0
        public virtual async Task <HttpResponseMessage> Post([FromBody] Activity activity)
        {
            // check if activity is of type message
            if (activity != null && activity.GetActivityType() == ActivityTypes.Message)
            {
                await Conversation.SendAsync(activity, () => new EchoDialog());
            }
            else if (activity != null && activity.Type == "invoke")
            {
                //await Conversation.SendAsync(activity, () => new SearchResultDialog());

                ComposeExtensionResponse invokeResponse = new ComposeExtensionResponse();
                // query.Parameters has the parameters sent by client
                var results = new ComposeExtensionResult()
                {
                    AttachmentLayout = "list",
                    Type             = "result",
                    Attachments      = new List <ComposeExtensionAttachment>(),
                };
                var query = activity.GetComposeExtensionQueryData();
                if (query.CommandId != null && query.Parameters != null && query.Parameters.Count > 0)
                {
                    var searchText = query.Parameters.First().Value;

                    using (var _client = new HttpClient())
                    {
                        var res = await _client.GetAsync("https://msopenhackeu.azurewebsites.net/api/trivia/search?k=" + searchText);

                        var responseText = await res.Content.ReadAsStringAsync();

                        var att = JsonConvert.DeserializeObject <List <SearchResultDto> >(responseText);


                        foreach (var x in att)
                        {
                            var heroCard = new HeroCard
                            {
                                Title    = x.name,
                                Subtitle = x.achievementBadge,
                                Text     = "Score: " + x.score.ToString(),
                                Images   = new List <CardImage> {
                                    new CardImage(x.achievementBadgeIcon)
                                }
                            };

                            results.Attachments.Add(heroCard.ToAttachment().ToComposeExtensionAttachment());
                        }
                        invokeResponse.ComposeExtension = results;

                        // Return the response
                        return(Request.CreateResponse <ComposeExtensionResponse>(HttpStatusCode.OK, invokeResponse));
                    }
                }
            }
            else
            {
                await HandleSystemMessage(activity);
            }
            return(new HttpResponseMessage(System.Net.HttpStatusCode.Accepted));
        }
コード例 #2
0
        private ComposeExtensionResponse HandleSomeCommand(Activity activity)
        {
            ComposeExtensionResult   catResult = new ComposeExtensionResult(null, "message", null, null, "Here is a cat ┬┴┬┴┤・ω・)ノ├┬┴┬┴");
            ComposeExtensionResponse flyingCat = new ComposeExtensionResponse(catResult);

            return(flyingCat);
        }
コード例 #3
0
        public static ComposeExtensionResponse HandleMessageExtensionQuery(ConnectorClient connector, Activity activity)
        {
            ComposeExtensionResponse invokeResponse = new ComposeExtensionResponse();
            // This helper method gets the query as an object.
            var query = activity.GetComposeExtensionQueryData();

            var results = new ComposeExtensionResult()
            {
                AttachmentLayout = "list",
                Type             = "result",
                Attachments      = new List <ComposeExtensionAttachment>()
            };


            if (query.CommandId != null && query.Parameters != null && query.Parameters.Count > 0)
            {
                //用户没有设置参数,而是初始化
                if (query.Parameters[0].Name.Equals("initialRun"))
                {
                    results.Attachments = GetAttachment();
                }
                else
                {
                    //根据传入的参数来返回结果的个数
                    string keyword = query.Parameters[0].Value.ToString();
                    results.Attachments = GetAttachment(keyword);
                }
            }


            invokeResponse.ComposeExtension = results;

            return(invokeResponse);
        }
コード例 #4
0
        public static ComposeExtensionResult GetMessageResponseResult(string message)
        {
            ComposeExtensionResult composeExtensionResult = new ComposeExtensionResult();

            composeExtensionResult.Type = "message";
            composeExtensionResult.Text = message;
            return(composeExtensionResult);
        }
コード例 #5
0
        public static ComposeExtensionResponse GetComposeExtenionQueryResult(ComposeExtensionResponse composeExtensionResponse, List <ComposeExtensionAttachment> lstComposeExtensionAttachment)
        {
            composeExtensionResponse = new ComposeExtensionResponse();
            ComposeExtensionResult composeExtensionResult = new ComposeExtensionResult();

            composeExtensionResult.Type               = "result";
            composeExtensionResult.Attachments        = lstComposeExtensionAttachment;
            composeExtensionResult.AttachmentLayout   = "list";
            composeExtensionResponse.ComposeExtension = composeExtensionResult;

            return(composeExtensionResponse);
        }
コード例 #6
0
        public ComposeExtensionResponse GetComposeExtensionQueryResult(List <ComposeExtensionAttachment> composeExtensionAttachments)
        {
            ComposeExtensionResponse composeExtensionResponse = new ComposeExtensionResponse();
            ComposeExtensionResult   composeExtensionResult   = new ComposeExtensionResult();

            composeExtensionResult.Type               = "result";
            composeExtensionResult.Attachments        = composeExtensionAttachments;
            composeExtensionResult.AttachmentLayout   = "list";
            composeExtensionResponse.ComposeExtension = composeExtensionResult;

            return(composeExtensionResponse);
        }
コード例 #7
0
        private ComposeExtensionResponse GetComposeExtensionResponse(Activity activity)
        {
            var composeExtensionQuery = activity.GetComposeExtensionQueryData();
            var composeExtParamValue  = composeExtensionQuery.Parameters[0].Value.ToString();
            // Process data and return the response.
            ComposeExtensionResponse          composeExtensionResponse      = new ComposeExtensionResponse();
            ComposeExtensionResult            composeExtensionResult        = new ComposeExtensionResult();
            List <ComposeExtensionAttachment> lstComposeExtensionAttachment = new List <ComposeExtensionAttachment>();
            string imageUrl    = "https://luna1.co/cae4f2.png";
            string deepLinkUrl = TemplateUtility.GetDeepLink(activity, composeExtParamValue);

            lstComposeExtensionAttachment.Add(TemplateUtility.GenerateComposeExtentionAttachments(activity));
            composeExtensionResult.Type               = "result";
            composeExtensionResult.AttachmentLayout   = "list";
            composeExtensionResult.Attachments        = lstComposeExtensionAttachment;
            composeExtensionResponse.ComposeExtension = composeExtensionResult;
            return(composeExtensionResponse);
        }
コード例 #8
0
        private ComposeExtensionResponse GetComposeExtensionResponse(Activity activity)
        {
            var composeExtensionQuery = activity.GetComposeExtensionQueryData();
            var composeExtParamValue  = composeExtensionQuery.Parameters[0].Value.ToString();
            // Process data and return the response.
            ComposeExtensionResponse          composeExtensionResponse      = new ComposeExtensionResponse();
            ComposeExtensionResult            composeExtensionResult        = new ComposeExtensionResult();
            List <ComposeExtensionAttachment> lstComposeExtensionAttachment = new List <ComposeExtensionAttachment>();
            string imageUrl    = "https://luna1.co/cae4f2.png";
            string deepLinkUrl = TemplateUtility.GetDeepLink(activity, composeExtParamValue);

            lstComposeExtensionAttachment.Add(TemplateUtility.CreateComposeExtensionCardsAttachments("Deep Link", "Clicking on the button will redirect you to the configuration tab", imageUrl, "hero", deepLinkUrl));
            composeExtensionResult.Type               = "result";
            composeExtensionResult.AttachmentLayout   = "list";
            composeExtensionResult.Attachments        = lstComposeExtensionAttachment;
            composeExtensionResponse.ComposeExtension = composeExtensionResult;
            return(composeExtensionResponse);
        }
        public IActionResult Post([FromBody] Activity activity)
        {
            if (activity.Type == ActivityTypes.Invoke)
            {
                if (activity.IsComposeExtensionQuery())
                {
                    // This is the response object that will get sent back to the messaging extension request.
                    var invokeResponse = new ComposeExtensionResponse();

                    // This helper method gets the query as an object.
                    var query = activity.GetComposeExtensionQueryData();

                    if (query.CommandId != null && query.Parameters != null && query.Parameters.Count > 0)
                    {
                        string[] cities;
                        if (query.Parameters[0].Name == "initialRun")
                        {
                            cities = s_sampleCities;
                        }
                        else
                        {
                            var keyword = query.Parameters[0].Value.ToString();
                            cities = s_sampleCities
                                     .Where(c => c.Contains(keyword, StringComparison.InvariantCultureIgnoreCase))
                                     .ToArray();
                        }

                        var results = new ComposeExtensionResult()
                        {
                            AttachmentLayout = "list",
                            Type             = "result",
                            Attachments      = BuildAttachments(cities)
                        };
                        invokeResponse.ComposeExtension = results;
                    }

                    // Return the response
                    return(Ok(invokeResponse));
                }
            }

            // Failure case catch-all.
            return(BadRequest("Invalid request! This API supports only messaging extension requests. Check your query and try again"));
        }
コード例 #10
0
        /// <summary>
        /// Help method to generate a compose extension
        ///
        /// Note that for this sample, we are returning random tasks, for illustration purposes only.
        /// </summary>
        /// <returns></returns>
        public ComposeExtensionResponse CreateComposeExtensionResponse()
        {
            ComposeExtensionResponse response = null;
            const int numResults = 10;

            var query = activity.GetComposeExtensionQueryData();

            //Check to make sure a query was actually made:
            if (query.CommandId == null || query.Parameters == null)
            {
                return(null);
            }
            else if (query.Parameters.Count > 0)
            {
                // query.Parameters has the parameters sent by client
                var results = new ComposeExtensionResult()
                {
                    AttachmentLayout = "list",
                    Type             = "result",
                    Attachments      = new List <ComposeExtensionAttachment>(),
                };

                // Generate cards for the response.
                for (var i = 0; i < numResults; i++)
                {
                    var card = GenerateResultCard();
                    // Add content to the response title.
                    if (query.Parameters[0].Name != "initialRun")
                    {
                        card.Title += " " + query.Parameters[0].Value;
                    }
                    var composeExtensionAttachment = card.ToAttachment().ToComposeExtensionAttachment();
                    results.Attachments.Add(composeExtensionAttachment);
                }

                response = new ComposeExtensionResponse()
                {
                    ComposeExtension = results
                };
            }

            return(response);
        }
コード例 #11
0
        public static ComposeExtensionResponse GetSignin(ComposeExtensionResponse composeExtensionResponse)
        {
            string            configUrl     = ConfigurationManager.AppSettings["BaseUri"].ToString() + "/composeExtensionSettings.html";
            CardAction        configExp     = new CardAction(ActionTypes.OpenUrl, "Config", null, configUrl);
            List <CardAction> lstCardAction = new List <CardAction>();

            lstCardAction.Add(configExp);
            composeExtensionResponse = new ComposeExtensionResponse();
            ComposeExtensionResult composeExtensionResult = new ComposeExtensionResult();

            ComposeExtensionSuggestedAction objSuggestedAction = new ComposeExtensionSuggestedAction();

            objSuggestedAction.Actions = lstCardAction;

            composeExtensionResult.SuggestedActions   = objSuggestedAction;
            composeExtensionResult.Type               = "auth";
            composeExtensionResponse.ComposeExtension = composeExtensionResult;

            return(composeExtensionResponse);
        }
コード例 #12
0
        public async Task <IActionResult> Post([FromBody] Activity activity)
        {
            if (activity.Type == ActivityTypes.Invoke)
            {
                if (activity.IsComposeExtensionQuery())
                {
                    // This is the response object that will get sent back to the messaging extension request.
                    var invokeResponse = new ComposeExtensionResponse();

                    // This helper method gets the query as an object.
                    var query = activity.GetComposeExtensionQueryData();

                    if (query.CommandId != null && query.Parameters != null && query.Parameters.Count > 0)
                    {
                        var keyword = string.Empty;
                        if (query.Parameters[0].Name != "initialRun")
                        {
                            keyword = query.Parameters[0].Value.ToString();
                        }

                        var stories = await SearchStories(keyword);

                        var results = new ComposeExtensionResult()
                        {
                            AttachmentLayout = "list",
                            Type             = "result",
                            Attachments      = BuildAttachments(stories)
                        };
                        invokeResponse.ComposeExtension = results;
                    }

                    // Return the response
                    return(Ok(invokeResponse));
                }
            }

            // Failure case catch-all.
            return(BadRequest("Invalid request! This API supports only messaging extension requests. Check your query and try again"));
        }
コード例 #13
0
        /// <summary>
        /// Helper method to generate a the messaging extension response.
        ///
        /// Note that for this sample, we are returning generated positions for illustration purposes only.
        /// </summary>
        /// <returns></returns>
        public ComposeExtensionResponse CreateResponse()
        {
            ComposeExtensionResponse response = null;

            var     query = activity.GetComposeExtensionQueryData();
            JObject data  = activity.Value as JObject;

            // Check if this is a task module invocation.
            if (data != null && data["type"] != null)
            {
                // Handle other types of Invoke activities here, e.g. CardActions
                if (data["type"].ToString() == TaskModuleCommandType && data["command"].ToString() == CreatePostingCommand)
                {
                    response = CreateTaskModuleResponse();
                }
            }
            else
            {
                //Check to make sure a query was actually made:
                if (query.CommandId == null || query.Parameters == null)
                {
                    return(null);
                }
                else if (query.Parameters.Count > 0)
                {
                    // query.Parameters has the parameters sent by client
                    var results = new ComposeExtensionResult()
                    {
                        AttachmentLayout = "list",
                        Type             = "result",
                        Attachments      = new List <ComposeExtensionAttachment>(),
                    };

                    if (query.CommandId == "searchPositions")
                    {
                        OpenPositionsDataController controller = new OpenPositionsDataController();
                        IEnumerable <OpenPosition>  positions;

                        if (query.Parameters[0].Name == "initialRun")
                        {
                            // Default query => list all
                            positions = controller.ListOpenPositions(10);
                        }
                        else
                        {
                            // Basic search.
                            string title = query.Parameters[0].Value.ToString().ToLower();
                            positions = controller.ListOpenPositions(10).Where(x => x.Title.ToLower().Contains(title));
                        }

                        // Generate cards for the response.
                        foreach (OpenPosition pos in positions)
                        {
                            var card = CardHelper.CreateCardForPosition(pos, true);

                            var composeExtensionAttachment = card.ToAttachment().ToComposeExtensionAttachment();
                            results.Attachments.Add(composeExtensionAttachment);
                        }
                    }
                    else if (query.CommandId == "searchCandidates")
                    {
                        string name = query.Parameters[0].Value.ToString();
                        CandidatesDataController controller = new CandidatesDataController();

                        foreach (Candidate c in controller.GetTopCandidates("ABCD1234"))
                        {
                            c.Name = c.Name.Split(' ')[0] + " " + CultureInfo.CurrentCulture.TextInfo.ToTitleCase(name);
                            var card = CardHelper.CreateSummaryCardForCandidate(c);

                            var composeExtensionAttachment = card.ToAttachment().ToComposeExtensionAttachment(CardHelper.CreatePreviewCardForCandidate(c).ToAttachment());
                            results.Attachments.Add(composeExtensionAttachment);
                        }
                    }

                    response = new ComposeExtensionResponse()
                    {
                        ComposeExtension = results
                    };
                }
            }
            return(response);
        }
コード例 #14
0
        public static async Task <string> HandleInvoke(Activity activity)
        {
            // these are the values specified in manifest.json
            string COMMANDID = "searchCmd";
            string PARAMNAME = "searchText";

            if (!activity.IsComposeExtensionQuery())
            {
                return(null);
            }

            // This helper method gets the query as an object.
            var query = activity.GetComposeExtensionQueryData();

            if (query.CommandId == null || query.Parameters == null)
            {
                return(null);
            }


            if (query.CommandId != COMMANDID)
            {
                return(null);
            }

            var param = query.Parameters.FirstOrDefault(p => p.Name.Equals(PARAMNAME)).Value.ToString();

            if (String.IsNullOrEmpty(param))
            {
                return(null);
            }

            // This is the response object that will get sent back to the compose extension request.
            ComposeExtensionResponse invokeResponse = null;

            // search our data
            var data       = BotChannels.GetBotChannels();
            var resultData = data.Where(t => t.Title.IndexOf(param, StringComparison.InvariantCultureIgnoreCase) >= 0).ToList();

            // format the results
            var results = new ComposeExtensionResult()
            {
                AttachmentLayout = "list",
                Type             = "result",
                Attachments      = new List <ComposeExtensionAttachment>(),
            };

            foreach (var resultDataItem in resultData)
            {
                var card = new ThumbnailCard()
                {
                    Title  = resultDataItem.Title,
                    Images = new List <CardImage>()
                    {
                        new CardImage()
                        {
                            Url = resultDataItem.LogoUrl
                        }
                    }
                };

                var composeExtensionAttachment = card.ToAttachment().ToComposeExtensionAttachment();
                results.Attachments.Add(composeExtensionAttachment);
            }

            invokeResponse = new ComposeExtensionResponse();
            invokeResponse.ComposeExtension = results;

            string response = String.Empty;

            try
            {
                response = Newtonsoft.Json.JsonConvert.SerializeObject(invokeResponse);
            }
            catch (Exception ex)
            {
                response = ex.ToString();
            }
            return(response);
        }
コード例 #15
0
        public ComposeExtensionResponse CreateComposeExtensionResponse()
        {
            ComposeExtensionResponse response = null;

            var query = activity.GetComposeExtensionQueryData();

            if (query.CommandId == null || query.Parameters == null)
            {
                return null;
            }

            if (query.CommandId == "driversCmd")
            {
                var results = new ComposeExtensionResult()
                {
                    AttachmentLayout = "list",
                    Type = "result",
                    Attachments = new List<ComposeExtensionAttachment>(),
                };


                var competitiors = Utils.Competitors.GetCompetitors();

                var driverName = "Unknown";

                for (int i = 0; i < query.Parameters.Count(); i++)
                {
                    if (query.Parameters[i].Name == "drivers")
                    {
                        driverName = query.Parameters[i].Value.ToString();
                    }
                }


                List<Competitor> result = competitiors.FindAll(x => x.DriverName.ToLower().Contains(driverName.ToLower()));

                if (result != null)
                {
                    foreach (var competitor in result)
                    {
                        var card = GenerateTyreSelectionCard(competitor);

                        var composeExtensionAttachment = card.ToAttachment().ToComposeExtensionAttachment();

                        //This code gets around the bug where 'preview' doesn't work
                        composeExtensionAttachment.ThumbnailUrl = card.Images[0].Url;
                        composeExtensionAttachment.Name = card.Title;

                        results.Attachments.Add(composeExtensionAttachment);
                    }
                }

                response = new ComposeExtensionResponse();
                response.ComposeExtension = results;

                return response;
            }


            return response;
        }
コード例 #16
0
    public static async Task <HttpResponseMessage> HandleInvoke(Activity activity)
    {
        // these are the values specified in manifest.json
        string COMMANDID = "searchCmd";
        string PARAMNAME = "searchText";

        var unrecognizedResponse = new HttpResponseMessage(HttpStatusCode.BadRequest);

        unrecognizedResponse.Content = new StringContent("Invoke request was not recognized.");

        if (!activity.IsComposeExtensionQuery())
        {
            return(unrecognizedResponse);
        }

        // This helper method gets the query as an object.
        var query = activity.GetComposeExtensionQueryData();

        if (query.CommandId == null || query.Parameters == null)
        {
            return(unrecognizedResponse);
        }


        if (query.CommandId != COMMANDID)
        {
            return(unrecognizedResponse);
        }

        var param = query.Parameters.FirstOrDefault(p => p.Name.Equals(PARAMNAME)).Value.ToString();

        if (String.IsNullOrEmpty(param))
        {
            return(unrecognizedResponse);
        }

        // This is the response object that will get sent back to the compose extension request.
        ComposeExtensionResponse invokeResponse = new ComposeExtensionResponse();

        // search our data
        var resultData = BotChannels.GetBotChannels().FindAll(t => t.Title.ToLowerInvariant().Contains(param.ToLowerInvariant()));

        // format the results
        var results = new ComposeExtensionResult()
        {
            AttachmentLayout = "list",
            Type             = "result",
            Attachments      = new List <ComposeExtensionAttachment>(),
        };

        foreach (var resultDataItem in resultData)
        {
            var card = new ThumbnailCard()
            {
                Title  = resultDataItem.Title,
                Images = new List <CardImage>()
                {
                    new CardImage()
                    {
                        Url = resultDataItem.LogoUrl
                    }
                }
            };

            var composeExtensionAttachment = card.ToAttachment().ToComposeExtensionAttachment();
            results.Attachments.Add(composeExtensionAttachment);
        }

        invokeResponse.ComposeExtension = results;

        // Return the response
        StringContent stringContent;

        try
        {
            stringContent = new StringContent(JsonConvert.SerializeObject(invokeResponse));
        }
        catch (Exception ex)
        {
            stringContent = new StringContent(ex.ToString());
        }
        var response = new HttpResponseMessage(HttpStatusCode.OK);

        response.Content = stringContent;
        return(response);
    }
コード例 #17
0
        /// <summary>
        /// Helper method to generate a compose extension
        ///
        /// Note that for this sample, we are returning generated positions for illustration purposes only.
        /// </summary>
        /// <returns></returns>
        public ComposeExtensionResponse CreateResponse()
        {
            try
            {
                ComposeExtensionResponse   response = null;
                ComposeExtensionAttachment composeExtensionAttachment = new ComposeExtensionAttachment();
                var query   = activity.GetComposeExtensionQueryData();
                var results = new ComposeExtensionResult()
                {
                    AttachmentLayout = "list",
                    Type             = "result",
                    Attachments      = new List <ComposeExtensionAttachment>(),
                };
                string text = "";
                //Check to make sure a query was actually made:
                if (query.CommandId == null || query.Parameters == null)
                {
                    return(null);
                }
                else if (query.Parameters.Count > 0)
                {
                    // query.Parameters has the parameters sent by client

                    string headRefName = "";

                    if (query.CommandId == "PRs")
                    {
                        var titleParam = query.Parameters?.FirstOrDefault(p => p.Name == "PRs" || p.Name == "Repos" || p.Name == "Issues");
                        if (titleParam != null)
                        {
                            headRefName = titleParam.Value.ToString().ToLower();
                        }

                        var             query3 = @"query($headRefName: String!) { 
                                      viewer { 
                                      pullRequests (first : 100, headRefName : $headRefName){
                                        edges {   
                                          node {
                                            id
                                            title
                                            body
                                            state
                                            headRefName
                                            revertUrl
                                            url
                                            repository {
                                                nameWithOwner
                                            }
                                            headRefName
                                          }
                                        }
                                      }
                                      }
                                    }";
                        var             client = new GraphQLClient();
                        string          data   = client.Query(query3, new { headRefName = headRefName });
                        RootPullRequest obj    = Newtonsoft.Json.JsonConvert.DeserializeObject <RootPullRequest>(data);


                        if (obj.data.viewer.pullRequests.edges.Count == 0)
                        {
                            text = "No  pull request exists.";
                        }
                        else
                        {
                            HeroCard card = new HeroCard
                            {
                                Title = obj.data.viewer.pullRequests.edges[0].node.headRefName,
                                Text  = "<b>Id         :</b>" + obj.data.viewer.pullRequests.edges[0].node.id + "</br>"
                                        + "<b>Body       :</b>" + obj.data.viewer.pullRequests.edges[0].node.body + "</br>"
                                        + "<b>State      :</b>" + obj.data.viewer.pullRequests.edges[0].node.state + "</br>"
                                        + "<b>RevertUrl  :</b>" + obj.data.viewer.pullRequests.edges[0].node.revertUrl + "</br>"
                                        + "<b>Repository :</b>" + obj.data.viewer.pullRequests.edges[0].node.repository.nameWithOwner,
                                Buttons = new List <CardAction> {
                                    new CardAction(ActionTypes.OpenUrl, "More Info", value: obj.data.viewer.pullRequests.edges[0].node.url)
                                }
                            };
                            composeExtensionAttachment = card.ToAttachment().ToComposeExtensionAttachment();
                        }

                        if (text != "")
                        {
                            results.Text = text;
                        }
                        else
                        {
                            results.Attachments.Add(composeExtensionAttachment);
                        }
                    }
                    else if (query.CommandId == "Repos")
                    {
                        string repository = "";
                        var    titleParam = query.Parameters?.FirstOrDefault(p => p.Name == "PRs" || p.Name == "Repos" || p.Name == "Issues");
                        if (titleParam != null)
                        {
                            repository = titleParam.Value.ToString().ToLower();
                        }
                        var    query3            = @"query($owner: String!,$name: String! ) {
                                                repository(owner: $owner, name: $name)
                                                {
                                                  id
                                                  name
                                                  homepageUrl
                                                  resourcePath
                                                  isPrivate
                                                  updatedAt
                                                  createdAt
                                                  nameWithOwner
                                                  url
                                                            }
                                                        }";
                        var    client            = new GraphQLClient();
                        string data              = client.Query(query3, new { owner = "poonam0025", name = repository });
                        RepositoryRootObject obj = Newtonsoft.Json.JsonConvert.DeserializeObject <RepositoryRootObject>(data);

                        if (obj.data.repository == null)
                        {
                            text = "No " + repository + "found.";
                        }
                        else
                        {
                            HeroCard card = new HeroCard
                            {
                                Title = repository,
                                Text  = "<b>Id : </b> " + obj.data.repository.id + "</br>"
                                        + "<b>Resource path : </b> " + obj.data.repository.resourcePath + "</br>"
                                        + "<b>IsPrivate : </b> " + obj.data.repository.isPrivate + "</br>"
                                        + "<b>CreatedAt : </b> " + Convert.ToDateTime(obj.data.repository.createdAt).ToString("dd MMM yyyy hh:mm:ss tt") + "</br>"
                                        + "<b>UpdatedAt : </b> " + Convert.ToDateTime(obj.data.repository.updatedAt).ToString("dd MMM yyyy hh:mm:ss tt") + "</br>"
                                        + "<b>Name with Owner : </b> " + obj.data.repository.nameWithOwner,
                                Buttons = new List <CardAction> {
                                    new CardAction(ActionTypes.OpenUrl, "More Info", value: obj.data.repository.url)
                                }
                            };

                            composeExtensionAttachment = card.ToAttachment().ToComposeExtensionAttachment();
                        }

                        if (text != "")
                        {
                            results.Text = text;
                        }
                        else
                        {
                            results.Attachments.Add(composeExtensionAttachment);
                        }
                    }

                    else if (query.CommandId == "Issues")
                    {
                        string repository = "";
                        var    titleParam = query.Parameters?.FirstOrDefault(p => p.Name == "PRs" || p.Name == "Repos" || p.Name == "Issues");
                        if (titleParam != null)
                        {
                            repository = titleParam.Value.ToString().ToLower();
                        }
                        var    query3 = @"query($owner:String!,$name:String!) {
                                repository(owner : $owner, name: $name)
                                  {
                                    issues(first:20) { 
                                      edges { 
                                        node { 
                                          title 
                                          url 
                                          state
                                          body
                                          createdAt
                                        } 
                                      } 
                                    } 
                                  } 
                                }";
                        var    client = new GraphQLClient();
                        string data   = client.Query(query3, new { owner = "poonam0025", name = repository });
                        RepositoryDetailRoot repositorydata = Newtonsoft.Json.JsonConvert.DeserializeObject <RepositoryDetailRoot>(data);

                        if (repositorydata.data.repository.issues.edges.Count == 0)
                        {
                            text = "No issue found.";
                        }
                        else
                        {
                            HeroCard card = new HeroCard();
                            for (int i = 0; i < repositorydata.data.repository.issues.edges.Count; i++)
                            {
                                card = new HeroCard
                                {
                                    Title = "<b>" + repositorydata.data.repository.issues.edges[i].node.title + "</b>",
                                    Text  = "<b>Description     :</b>" + repositorydata.data.repository.issues.edges[i].node.body + "</br>"
                                            + "<b>Created At  :</b>" + Convert.ToDateTime(repositorydata.data.repository.issues.edges[i].node.createdAt).ToString("dd MMM yyyy hh:mm:ss tt") + "</br>"
                                            + "<b>State :</b>" + repositorydata.data.repository.issues.edges[i].node.state,
                                    Buttons = new List <CardAction> {
                                        new CardAction(ActionTypes.OpenUrl, "More Info", value: repositorydata.data.repository.issues.edges[i].node.url)
                                    }
                                };

                                composeExtensionAttachment = card.ToAttachment().ToComposeExtensionAttachment();
                                results.Attachments.Add(composeExtensionAttachment);
                            }
                        }
                    }

                    response = new ComposeExtensionResponse()
                    {
                        ComposeExtension = results
                    };
                }
                return(response);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
コード例 #18
0
        public static async Task <ComposeExtensionResponse> CreateResponse(Activity activity)
        {
            ComposeExtensionResponse response = null;

            var     query = activity.GetComposeExtensionQueryData();
            JObject data  = activity.Value as JObject;

            //Check to make sure a query was actually made:
            if (query.CommandId == null || query.Parameters == null)
            {
                return(null);
            }
            else if (query.Parameters.Count > 0)
            {
                // query.Parameters has the parameters sent by client
                var results = new ComposeExtensionResult()
                {
                    AttachmentLayout = "list",
                    Type             = "result",
                    Attachments      = new List <ComposeExtensionAttachment>(),
                };


                if (query.CommandId == "searchInventory")
                {
                    InventoryDataController inventoryDataController = new InventoryDataController();
                    IEnumerable <Inventory> inventories;

                    if (query.Parameters[0].Name == "initialRun")
                    {
                        // Default query => list all
                        inventories = inventoryDataController.ListInventory(10);
                    }
                    else
                    {
                        // Basic search.
                        string title = query.Parameters[0].Value.ToString().ToLower();
                        inventories = inventoryDataController.ListInventory(10).Where(x => x.Title.ToLower().Contains(title));
                    }

                    // Generate cards for the response.
                    foreach (Inventory inv in inventories)
                    {
                        var card = CardHelper.CreateCardForInventory(inv, true);

                        var composeExtensionAttachment = card.ToAttachment().ToComposeExtensionAttachment();
                        results.Attachments.Add(composeExtensionAttachment);
                    }
                }

                else if (query.CommandId == "searchSupplier")
                {
                    SupplierDataController supplierDataController = new SupplierDataController();
                    IEnumerable <Supplier> suppliers;

                    if (query.Parameters[0].Name == "initialRun")
                    {
                        // Default query => list all
                        suppliers = supplierDataController.ListSupplier(10);
                    }
                    else
                    {
                        string title = query.Parameters[0].Value.ToString().ToLower();
                        suppliers = supplierDataController.ListSupplier(10).Where(x => x.Title.ToLower().Contains(title));
                    }

                    foreach (Supplier sup in suppliers)
                    {
                        var card = CardHelper.CreateCardForSupplier(sup, true);

                        var composeExtensionAttachment = card.ToAttachment().ToComposeExtensionAttachment();
                        results.Attachments.Add(composeExtensionAttachment);
                    }
                }

                response = new ComposeExtensionResponse()
                {
                    ComposeExtension = results
                };
            }

            return(response);
        }