示例#1
0
        //methods
        public virtual async Task <ProcessingResult> Send(SignalDispatch <TKey> item)
        {
            SlackDispatch <TKey> slackDispatch = (SlackDispatch <TKey>)item;

            //serialize payload
            var payload = new SlackPayload()
            {
                Channel  = slackDispatch.Channel,
                Username = slackDispatch.Username,
                Text     = slackDispatch.Text
            };
            string payloadJson = JsonConvert.SerializeObject(payload);
            var    data        = new KeyValuePair <string, string>[]
            {
                new KeyValuePair <string, string>("payload", payloadJson)
            };

            //send payload
            using (var client = new HttpClient())
            {
                HttpResponseMessage response = await client.PostAsync(_urlWithAccessToken, new FormUrlEncodedContent(data));

                string responseString = await response.Content.ReadAsStringAsync();

                bool completed = responseString == "ok";
                if (!completed)
                {
                    return(ProcessingResult.Fail);
                }
            }

            return(ProcessingResult.Success);
        }
        protected virtual SlackDispatch <TKey> AssembleSlackMessage(EventSettings <TKey> settings
                                                                    , SignalEvent <TKey> signalEvent, Subscriber <TKey> subscriber, string content)
        {
            var dispatch = new SlackDispatch <TKey>()
            {
                Text     = content,
                Channel  = Channel,
                Username = Username
            };

            SetBaseProperties(dispatch, settings, signalEvent, subscriber);
            return(dispatch);
        }