Example #1
0
        /// <summary>
        /// Creates the task.
        /// </summary>
        /// <param name="msg">The MSG.</param>
        /// <returns></returns>
        private string CreateTask(SlackMessage msg)
        {
            IcZeroBotTask task = new IcZeroBotTask()
            {
                Title       = msg.Text.Replace("create task ", ""),
                Description = msg.Text.Replace("create task ", ""),
                Creator     = msg.User?.Name ?? "Unidentified user. Probably new."
            };

            List <byte[]> atta = new List <byte[]>();

            if (msg.Files.Any())
            {
                var webClient = new WebClient();
                webClient.Headers.Add("Authorization", $"Bearer #{this._botController.cfg.Get("Slack", "ApiToken", "xxx")}");

                foreach (SlackFile f in msg.Files)
                {
                    byte[] img = webClient.DownloadData(f.Url_private);
                    atta.Add(img);
                }
            }

            if (atta.Any())
            {
                task.Attachements = atta;
            }

            string uid = _icZeroBotConnector.CreateTask(task);

            return($"Yeeeyyy, task created ${uid}");
        }
Example #2
0
        public string CreateTask(IcZeroBotTask task)
        {
            var client = new RestClient(_baseURL);

            client.AddDefaultHeader("Content-type", "application/json");

            var request = new RestRequest("tasks", Method.POST);

            request.AddJsonBody(task);

            IRestResponse response = client.Execute(request);

            if (response.StatusCode != System.Net.HttpStatusCode.OK)
            {
                throw new Exception(response.ErrorMessage);
            }

            return("empty");
        }