1

I am using LyncClient library to create a widget and when a call comes in externally the remote participant sometimes comes up as 'sip:emailaddress@domain' if the contact is in the users outlook contacts.

Wondering if there is a way or library that allows me to open up the contact card for that email address and then get phone numbers if there are any.

Been pulling at my hair for a while now and can't figure it out. Any tips or experiences (good and bad) would be great! Let me know if you guys need more information.

SharpCode
  • 1,385
  • 3
  • 12
  • 29
  • So at the moment I have been matching on the emailaddress@domain and if it exists in our database then my app will do its thing. This is fine but would still be very interested to know if there is a way to get the contents of an outlook card if the emailaddress@domain is on a card. – SharpCode May 19 '17 at 01:17

2 Answers2

2

I made a program that gets the phone address out of a SIP URL. a SIP Url is basically in this format(Without quotes): "sip:username@domain"

    try
    {
        LyncClient lyncClient = LyncClient.GetClient();
        Contact contact;
        List<object> endPoints = new List<object>();

        Dictionary<string, string> phoneNumbers = new Dictionary<string, string>();
        contact = lyncClient.ContactManager.GetContactByUri("sip:myusername@domain.com"); //PASS THE SIP ADDRESS HERE

        var telephoneNumber = (List<object>)contact.GetContactInformation(ContactInformationType.ContactEndpoints);
        //var contactName = contact.GetContactInformation(ContactInformationType.DisplayName).ToString();
        //var availability = contact.GetContactInformation(ContactInformationType.Activity).ToString();

        //foreach (object endPoint in telephoneNumber)
        //{
        //Console.WriteLine(((ContactEndpoint)endPoint).DisplayName + " " + ((ContactEndpoint)endPoint).Type.ToString());
        //}
        endPoints = telephoneNumber.Where<object>(N => ((ContactEndpoint)N).Type == ContactEndpointType.HomePhone || ((ContactEndpoint)N).Type == ContactEndpointType.MobilePhone || ((ContactEndpoint)N).Type == ContactEndpointType.OtherPhone || ((ContactEndpoint)N).Type == ContactEndpointType.WorkPhone).ToList<object>();
        foreach (var endPoint in endPoints)
        {
                    //Console.WriteLine(((ContactEndpoint)test).DisplayName.ToString());
            string numberType = Regex.Replace(((ContactEndpoint)endPoint).Type.ToString(), @"Phone", "");
            //string number = Regex.Replace(((ContactEndpoint)endPoint).DisplayName.ToString(), @"[^0-9]", "");
            string number = "";
            //Numbers only with dashes
            if (Regex.IsMatch(((ContactEndpoint)endPoint).DisplayName.ToString(), @"^\d{3}-\d{3}-\d{4}$"))
            {
                number = ((ContactEndpoint)endPoint).DisplayName.ToString();

                try
                {
                    phoneNumbers.Add(numberType, number);
                }
                catch
                {

                }
            }
            //Console.WriteLine(numberType + " " + number);
        }
        foreach (var entry in phoneNumbers)
        {
            //entry.Key is the PhoneType

            //entry.Value is the Phone Number
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show("An error occurred: " + ex.Message);
    }
Rafael
  • 727
  • 13
  • 30
  • Feel free to play around with the comments, they will give you more information about that sip contact. – Rafael Jun 29 '17 at 18:31
  • Going to look at this issue again when I get back on to the project. But in the meantime i just checked the DB for the email address as well. So if a client calls and it comes up with sip:email@domain then we will notify the receiver if we find it otherwise nothing. But going to try and get the phone number as well so we can check for that too. Will let you know how it goes. Was a side/MVP project done for the company. Hopefully some downtime soon. – SharpCode Aug 08 '17 at 00:38
0

I don't think that this is the email address.

SIP URI's has the same format as an email address: sip:username@sipdomain, so maybe Lync is just sending the peer sip address.

In this case you just have to grab the sub-string between "sip:" and "@" to get the caller id.

Another problem is that there are multiple ways for SIP to send the caller id. Maybe you should look for Asserted/Preferred identity (and Lync just extracts it from the SIP "Contact" header).

Adam Wright
  • 129
  • 4
  • It is definitely the email address as I spoke to the networking team. So my main question was what options do I have to work out what card the SIP address is on and to get the other details on the card. – SharpCode May 19 '17 at 01:15