Esempio n. 1
0
        //
        public static PostMessage_Rsp PostMessage(string channelId, string message, string username = null, bool link_names = false)
        {
            // see: https://api.slack.com/methods/chat.postMessage
            // example:
            // https://slack.com/api/chat.postMessage?token=xoxp-3569429651-5010389533-5146963048-ecd20d&channel=C053600BQ&text=hello+world&username=FTX

            var endpoint = string.Format("https://slack.com/api/chat.postMessage?token={0}&channel={1}&text={2}",
                                         AccessToken, channelId, WebServices.UrlEncode(message));

            if (username != null)
            {
                endpoint += "&username="******"&link_names=1";
            }

            string responseStr = null;

            try
            {
                responseStr = WebServices.getServiceResult(endpoint);
                var pmr = new PostMessage_Rsp();
                JsonConvert.PopulateObject(responseStr, pmr);
                return(pmr);
            }

            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 2
0
        //
        public static PostMessage_Rsp PostMessage(string channelId, string message, string username = null, bool link_names = false)
        {
            // see: https://api.slack.com/methods/chat.postMessage
            // example:
            // https://slack.com/api/chat.postMessage?token=xoxp-3569429651-5010389533-5146963048-ecd20d&channel=C053600BQ&text=hello+world&username=FTX

            var endpoint = string.Format("https://slack.com/api/chat.postMessage?token={0}&channel={1}&text={2}",
                                         AccessToken, channelId, WebServices.UrlEncode(message));
            if (username != null)
                endpoint += "&username="******"&link_names=1";

            string responseStr = null;
            try
            {
                responseStr = WebServices.getServiceResult(endpoint);
                var pmr = new PostMessage_Rsp();
                JsonConvert.PopulateObject(responseStr, pmr);
                return pmr;
            }

            catch (Exception)
            {
                throw;
            }
        }