<commit_before>﻿using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Newtonsoft.Json;
using RestSharp;
using SlackConnector.Connections.Models;
using SlackConnector.Exceptions;
using SlackConnector.Models;

namespace SlackConnector.Connections.Messaging
{
    internal class ChatMessenger : IChatMessenger
    {
        internal const string SEND_MESSAGE_PATH = "/api/chat.postMessage";
        private readonly IRestSharpFactory _restSharpFactory;

        public ChatMessenger(IRestSharpFactory restSharpFactory)
        {
            _restSharpFactory = restSharpFactory;
        }

        public async Task PostMessage(string slackKey, string channel, string text, SlackAttachment[] attachments)
        {
            var client = _restSharpFactory.CreateClient("https://slack.com");

            var request = new RestRequest(SEND_MESSAGE_PATH);
            request.AddParameter("token", slackKey);
            request.AddParameter("channel", channel);
            request.AddParameter("text", text);
            request.AddParameter("as_user", "true");

            if (attachments != null && attachments.Any())
            {
                request.AddParameter("attachments", JsonConvert.SerializeObject(attachments));
            }

            IRestResponse response = await client.ExecutePostTaskAsync(request);
            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw new CommunicationException($"Error occured while posting message '{response.StatusCode}'");
            }<commit_msg>Fixed bug<commit_after>﻿using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Newtonsoft.Json;
using RestSharp;
using SlackConnector.Connections.Models;
using SlackConnector.Exceptions;
using SlackConnector.Models;

namespace SlackConnector.Connections.Messaging
{
    internal class ChatMessenger : IChatMessenger
    {
        internal const string SEND_MESSAGE_PATH = "/api/chat.postMessage";
        private readonly IRestSharpFactory _restSharpFactory;

        public ChatMessenger(IRestSharpFactory restSharpFactory)
        {
            _restSharpFactory = restSharpFactory;
        }

        public async Task PostMessage(string slackKey, string channel, string text, SlackAttachment[] attachments)
        {
            var client = _restSharpFactory.CreateClient("https://slack.com");

            var request = new RestRequest(SEND_MESSAGE_PATH);
            request.AddParameter("token", slackKey);
            request.AddParameter("channel", channel);
            request.AddParameter("text", text);
            request.AddParameter("as_user", "true");

            if (attachments != null && attachments.Any())
            {
                request.AddParameter("attachment", JsonConvert.SerializeObject(attachments));
            }

            IRestResponse response = await client.ExecutePostTaskAsync(request);
            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw new CommunicationException($"Error occured while posting message '{response.StatusCode}'");
            }
{'fraction_non_alphanumeric': 0.08888888888888889, 'fraction_numerical': 0.0, 'mean_word_length': 2.8825, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5625988', 'n_tokens_mistral': 783, 'n_tokens_neox': 755, 'n_words': 167}