IT chats or Squeeze out all the juices from Skype

    imageOften, beginners in a particular IT field experience an acute shortage of knowledge and acquaintances who can be “asked” on the topic. Yes, StackOverflow, Google and other similar resources are just a storehouse of useful information, however, you must admit, there are situations when the question is so general that only an experienced person working in this field can answer it for more than a year.

    For the most part, this concerns these very newcomers, because seasoned IT people not only can take someone else’s soul out of Google, they usually have enough acquaintances in this area - the question will be solved one way or another.

    And here the thought flew by - why not make IT chats and break them down into specific topics / technologies? Ok, let's try. And Skype will help us here.

    If you want to know why Skype was chosen, how you can "get around" the limit of 300 people per chat, or you just hid an altruistic IT note and you like to help colleagues - take cookies and welcome to cat .


    Why skype


    There are many online boards / forums where you can go and ask your specific question. However, there are several BUT:

    1) It is there. And Skype is here. And between these "there" and "here" in my opinion there is an abyss. To ask someone to do something, to go somewhere there, to register somewhere there is an unrealistic case. As techies say and sold, the conversion will be zero. Seriously, people are lazy, especially when they are not motivated, so we try to simplify the “entrance” as much as possible and try to use what everyone has at hand.

    2) Ping.You went in, wrote and ... are waiting. Clarification of the issue may drag on for days. Therefore, we don’t write, and even if we write, it’s only in completely ruined situations where neither friends nor Google could help us, but usually each individual person doesn’t have such questions, right?

    There are of course the disadvantages of such a solution:

    1) Skype. It is not as good as we would like, but it provides basic functionality for conducting groups, which in general is already not bad.
    2) Lack of message history. No, of course you can scroll to the nth moment, but we all understand that this is not the search that is required.
    3) The ability to spam. A conversation between two people will affect everyone. / alertsoff will be your best friend and comrade here.

    In my opinion, the advantages outweigh, because when there is a goal, all obstacles are just obstacles, aren't they? It would be a desire, and Morse code can be banged with neighbors.

    How to fit everyone?


    Skype for some reason made a limit of 300 participants per group. Why, in general, it’s clear, but this does not suit us. What if more than three hundred people want to enter certain chats? I found a way to synchronize several chats with each other through the Chat bot , written in my free time. He will help us by connecting the necessary chats to each other by broadcasting messages from one group to another and vice versa. Crutch? Crutch. But what to do.

    How this synchronization works. Pieces of implementation and explanation of the binding mechanism. C #
    Bot needs to get attached to something. The topic of the group was not the best solution, and I found that when I tried to take the Chat name, api also returned its id.

    Each chat has this id and it is unique. You can get it only through the api. To find out, you need to add a bot (skypename: “mensclubbot” or your personal running implementation / fork) to both chats and execute the “! Get id” command in each of them, after which the bot will issue a unique chat id.

    Next, go to app.config and configure synchronization in a similar way:



    Format:

    - {id}: chat id;
    - {group name} - the name of the group that the members of the opposite chat will see can be left blank, in this case the chat will not be indicated during the broadcast;
    - {from}: direction of broadcasting messages. It can be "from", "to", "both".

    As a result, you should get something like this:

    image

    You can add new configurations through ";".

    Everything is ready, now messages from one chat are broadcast to another and vice versa. It looks something like this:

    image

    C # code class synchronization
    public class SkypeChatSyncer
        {
            private List chatSyncRelations { get; set; }
            public delegate void OnSendMessageRequiredDelegate(string message, string toSkypeId);
            public event OnSendMessageRequiredDelegate OnSendMessageRequired;
            public SkypeChatSyncer()
            {
                chatSyncRelations = new List();
                LoadRelations();
            }
            private void LoadRelations()
            {
                string configValue = ConfigurationManager.AppSettings["ChatSyncRelations"];
                if (!string.IsNullOrEmpty(configValue))
                {
                    var relations = configValue.Split(';');
                    foreach (string relation in relations)
                    {
                        var relationParts = relation.Split('|');
                        if (relationParts.Length == 3)
                        {
                            var fromChatIdParts = relationParts[0];
                            var toChatIdParts = relationParts[2];
                            string relationOperator = relationParts[1];
                            if (relationOperator == "from")
                            {
                                string tempChatId = fromChatIdParts;
                                fromChatIdParts = toChatIdParts;
                                toChatIdParts = tempChatId;
                            }
                            chatSyncRelations.Add(new ChatSyncerRelation(fromChatIdParts, toChatIdParts));
                            if (relationOperator == "both")
                            {
                                //reverse
                                chatSyncRelations.Add(new ChatSyncerRelation(toChatIdParts,fromChatIdParts));
                            }
                        }
                    }
                }
            }
            public void HandleMessage(string message, string fromName, string fromChatId)
            {
                var sendToChats = chatSyncRelations.Where(x => x.FromChatId == fromChatId).ToList();
                foreach (var chat in sendToChats)
                {
                    string formattedMessage = string.Format("[{0}]{1} : {2}", chat.FromChatName, fromName, message);
                    if (OnSendMessageRequired != null)
                    {
                        OnSendMessageRequired(formattedMessage, chat.TochatId);
                    }
                }
            }
        }
    



    We use it like this
    class Program
        {
            private static Skype skype = new Skype();
            private static HelloBot bot;
            private static SkypeChatSyncer chatSyncer;
            private static IDictionary chats { get; set; }
            private static object _chatLocker = new object();
            static void Main(string[] args)
            {
                bot = new HelloBot();
                bot.OnErrorOccured += BotOnErrorOccured;
                Task.Run(delegate
                {
                    try
                    {
                        skype.MessageStatus += OnMessageReceived;
                        skype.Attach(5, true);
                        chatSyncer = new SkypeChatSyncer(); //init chat sync
                        chatSyncer.OnSendMessageRequired += ChatSyncerOnOnSendMessageRequired;
                        Console.WriteLine("skype attached");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("top lvl exception : " + ex.ToString());
                    }
                    while (true)
                    {
                        Thread.Sleep(1000);
                    }
                });
                while (true)
                {
                    Thread.Sleep(1000);
                }
            }
            private static void ChatSyncerOnOnSendMessageRequired(string message, string toSkypeId)
            {
                var chat = GetChatById(toSkypeId);
                if (chat != null)
                {
                    SendMessage(message,chat);
                }
            }
            private static IChat GetChatById(string chatId)
            {
                if (chats == null)
                {
                    lock (_chatLocker)
                    {
                        if (chats == null)
                        {
                            chats = new Dictionary();
                            foreach (IChat chat in skype.Chats)
                            {
                                string tChatId = chat.Name.Split(';').Last();
                                chats.Add(tChatId,chat);
                            }
                        }
                    }
                }
                IChat toReturn = null;
                chats.TryGetValue(chatId, out toReturn);
                return toReturn;
            }
            static void BotOnErrorOccured(Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            private static void OnMessageReceived(ChatMessage pMessage, TChatMessageStatus status)
            {
                Console.WriteLine(status + pMessage.Body);
                if (status == TChatMessageStatus.cmsReceived)
                {
                    bot.HandleMessage(pMessage.Body, answer => SendMessage(answer,pMessage.Chat),new SkypeData(pMessage));
                    string fromChatId = pMessage.Chat.Name.Split(';').Last();
                    chatSyncer.HandleMessage(pMessage.Body,pMessage.FromDisplayName,fromChatId);
                }
            }
            public static object _lock = new object();
            private static void SendMessage(string message, IChat toChat)
            {
                if (message.StartsWith("/"))
                {
                    message = "(heidy) " + message;
                }
                    lock (_lock)
                    {
                        toChat.SendMessage(message);
                    }
            }
        }
    





    Well, okay, how do I view a list of chats and join one of them?


    View the list of chats here:
    docs.google.com/spreadsheets/d/1re0ntO6ZpPprYrMpKKuV_7I367Th30iRZWEL6ThXkUg - this is a list of chats with a brief description. They are few, but if you need some more, then write, be sure to add. You can directly enter by clicking on this link: jsfiddle.net/KTt3V/1 (it will change when you add new chats, so take it better from the link above, on google docks) and clicking on the group of interest. The browser will pick up the Skype protocol and Skype will join you in the group.

    image



    Rules?


    I understand that Skype alerts appear even if you turn them off via / alertsoff , so if you suddenly wanted to ask a question or answer it, or just chat, respect the other chat participants, try to write only on business.

    Conclusion


    I perfectly understand that this solution is through the Bender Brick Factory , however, it is possible that for some people these groups will be useful.

    References


    Select a chat like and you can start here: docs.google.com/spreadsheets/d/1re0ntO6ZpPprYrMpKKuV_7I367Th30iRZWEL6ThXkUg
    Githab chat bot: github.com/Nigrimmist/HelloBot
    Descriptions teams Skype: habrahabr.ru/post/97561

    Thank you for your attention and ... Join now! - because power is in the communities.
    Report errors in the text please in PM. Thanks!

    Update
    Chat bot is still disabled, I’ll file one of these days.

    Also popular now: