コード例 #1
0
 public Function()
 {
     _client   = new HttpClient();
     _closeApi = new CloseClient(_client);
 }
コード例 #2
0
        public async Task <JObject> BuildSlackPayload(string header, string sourceId, ICloseClient closeApi, string jobPostCustomer = null)
        {
            Dictionary <string, Option> customers = await closeApi.GetListOfCustomers();

            BlocksBuilder builder        = new BlocksBuilder();
            StaticSelect  customerSelect = new StaticSelect("customer_select", customers.Values.ToList(), "Customer");
            SlackAction   actions        = new SlackAction("actions")
                                           .AddElement(customerSelect);

            // check if we have detected a customer and if so set it as initial option
            if (!string.IsNullOrEmpty(jobPostCustomer))
            {
                actions.AddElement(new Button("addToClose_btn", "Add to Close", ButtonStyle.PRIMARY));
                if (customers.ContainsKey(jobPostCustomer))
                {
                    customerSelect.AddInitialOption(customers[jobPostCustomer]);
                }
            }

            // adding button in the proper place
            actions.AddElement(new Button("qualifyLead_btn", "Qualify Lead", string.IsNullOrEmpty(jobPostCustomer) ? ButtonStyle.PRIMARY : ButtonStyle.DEFAULT));

            builder.AddBlock(new Section(new Text(" ")));
            builder.AddBlock(new Section(new Text(" ")));
            builder.AddBlock(new Section(new Text("*" + header + "*" + Environment.NewLine + sourceId, "mrkdwn"), "msg_header"));
            builder.AddBlock(actions);
            builder.AddBlock(new Divider());

            return(builder.GetJObject());
        }