Exemplo n.º 1
0
        public Responses.SlackIMListResponse Im_List()
        {
            if (!IsAuthorized)
            {
                throw new Exceptions.SlackAuthException("Not Authorized.");
            }

            Dictionary <String, String> parameters = new Dictionary <string, string>();

            parameters["token"] = _access_token;

            Uri im_list_uri = GetApiUri("im.list", parameters);

            Responses.SlackIMListResponse imlistResponse = JsonConvert.DeserializeObject <Responses.SlackIMListResponse>(NetHelper.GetRequest(im_list_uri));

            return(imlistResponse);
        }
Exemplo n.º 2
0
        public void SendMessageToSelectedFriends()
        {
            foreach (SlackHelper user_helper in users_helpers)
            {
                if (!user_helper.IsAuthorized)
                {
                    continue;
                }

                Responses.SlackIMListResponse slackIMListResponse = user_helper.Im_List();

                if (!slackIMListResponse.Ok)
                {
                    continue;
                }

                List <Models.SlackIM> ims = slackIMListResponse.IMs?.ToList();

                if (ims == null)
                {
                    continue;
                }

                List <FriendsListItem>   friends_items = applicationContract.GetFriendsListItems();
                List <SendMessageStatus> statuses      = new List <SendMessageStatus>();

                foreach (FriendsListItem friend_item in friends_items)
                {
                    if (!friend_item.SocialNetworkName.Equals(getSocialNetworkName()))
                    {
                        continue;
                    }
                    if (!friend_item.IsChecked)
                    {
                        continue;
                    }
                    if (friend_item.User.ID != user_helper.User.ID)
                    {
                        continue;
                    }

                    String channel_id = null;

                    foreach (Models.SlackIM im in ims)
                    {
                        if (friend_item.Friend.ID == im.User)
                        {
                            channel_id = im.ID;
                            break;
                        }
                    }

                    if (channel_id == null)
                    {
                        continue;
                    }

                    SendMessageStatus status = new SendMessageStatus();
                    status.SocialNetworkName = getSocialNetworkName();
                    status.UserNameTo        = friend_item.Friend.Name;
                    status.UserNameFrom      = friend_item.User.Name;
                    status.IsMessageSended   = user_helper.Chat_MeMessage(channel_id, applicationContract.GetMessage()).Ok;
                    statuses.Add(status);
                }

                applicationContract.AddSendMessageStatuses(statuses);
            }
        }