Bridge Communications

Saturday, June 6, 2015

Adding a User to an Existing Skype4B/Lync Conversation

One of the best things about the Skype for Business / Lync ecosystem is the ease in which a 2 party conversation can quickly and easily become a collaboration with a group of people.  Today I am going to show you the simple and powerful process of adding a user to a 2 party call.



When using the Lync client sdk rule #1 is always having Lync/Skype4b running, then declare a variable and attach to the running Lync client.


Microsoft.Lync.Model.LyncClient _LyncClient;
 _LyncClient = LyncClient.GetClient();

After that we really only need 2 things to make our app happen.

1.  The conversation we want to add the new party to.
2.  The URI of the new party to add.

We will accomplish this work by passing this information to our procedure shown below.

 public static void AddConferenceParticipant(Conversation c, string part)
        {
            if (c == null)
                return;

            Task.Factory.StartNew(() =>
            {
                try
                {
                    foreach (Participant p in c.Participants)
                    {
                        if (p != c.SelfParticipant)
                        {
                            logAction("ADDCONF", part );
                        }
                    }
                }
                catch { }
            });

            try
            {
                if (c.CanInvoke(ConversationAction.AddParticipant))
                {
                    Console.WriteLine("Adding " + part + " to Call as Conference");
                    c.AddParticipant(lc.ContactManager.GetContactByUri(part));
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(ex, true);
                string er;
                er = "AddConferenceParticipant: Error Trapped in " + Dlib.ProgramSource + ".\r\n";
                er = er + trace.GetFrame(0).GetMethod().Name + "\r\n" + ex.Message.ToString();
                er = er + "Line: " + trace.GetFrame(0).GetFileLineNumber();
                er = er + "Column: " + trace.GetFrame(0).GetFileColumnNumber();
                Dlib.report_error(er);
            }
        }

Now there is some extra error handling in this block above, which makes sure there is an actual conversation that isn't null passed.  I also have an action logging routine which is helpful in the case of a error, or the need to find out who added whom to the call.

That will wrap up this week, short and sweet, thanks for stopping by the read.

Doug Routledge, C# Lync, Skype for Business, SQL, Exchange, UC Developer  BridgeOC
Twitter - @droutledge @ndbridge

No comments:

Post a Comment

Any spam comments will be deleted and your user account will be disabled.