so when someone is calling me I want to get his phonenumber.
Contact inviter = conversation.Properties[ConversationProperty.Inviter] as Contact; // The person that is calling
ContactEndpoint inviterContactEndpoint = inviter.Settings[ContactSetting.DefaultContactEndpoint] as ContactEndpoint;
How do I get it?
Using this
string phoneNumber = inviterContactEndpoint.Uri;
returns me from Skype to Skype
and from phone to Skype
I also tried using
inviter.GetContactInformation(ContactInformationType);
but ContactInformationType
has no phone number property.
You use GetContactInformation method to get a list of ContactEndpoint objects. Now you can go through the list and find the phone number type that you want.
e.g.
var contactEndpoints = (Contact.GetContactInformation(ContactInformationType.ContactEndpoints) as List<object> ?? new List<object>()).Select(_ => _ as ContactEndpoint).Where(_ => _ != null);
foreach (var contactEndpoint in contactEndpoints)
{
switch (contactEndpoint.Type)
{
case ContactEndpointType.WorkPhone:
break;
case ContactEndpointType.MobilePhone:
break;
case ContactEndpointType.HomePhone:
break;
case ContactEndpointType.OtherPhone:
break;
case ContactEndpointType.Lync:
break;
case ContactEndpointType.VoiceMail:
break;
case ContactEndpointType.Invalid:
break;
default:
throw new ArgumentOutOfRangeException();
}
}
Now the problem you will have is that for non-cached contact's ContactInformationType.ContactEndpoints will return null (or a empty list, I forget which).
So you need to understand to get this information will not happen synchronously. If you really want this information you need to request it and it will come in a event update for the contact object. To do this you need to create a contact subscription for the details that you want and then subscribe specific contacts to the subscriptions.
Setup a subscription using the client ContactManager on app startup:
_contactSubscription = _client.ContactManager.CreateSubscription();
_contactSubscription.Subscribe(ContactSubscriptionRefreshRate.High,
new[]
{
ContactInformationType.ContactEndpoints
});
}
catch (Exception e)
{
Log.WriteLine(e);
_mediator.ClientComConnectionDead();
}
}
Setup the contact and subscribe to contact changes:
contact.ContactInformationChanged += ContactOnContactInformationChanged;
_contactSubscription.AddContact(contact);
Handle the updated contact information:
private void ContactOnContactInformationChanged(object sender, ContactInformationChangedEventArgs e)
{
if (e.ChangedContactInformation.Any(_ => _ == ContactInformationType.ContactEndpoints))
{
var contactEndpoints = (Contact.GetContactInformation(ContactInformationType.ContactEndpoints) as List<object> ?? new List<object>()).Select(_ => _ as ContactEndpoint).Where(_ => _ != null);
foreach (var contactEndpoint in contactEndpoints)
{
switch (contactEndpoint.Type)
{
case ContactEndpointType.WorkPhone:
break;
case ContactEndpointType.MobilePhone:
break;
case ContactEndpointType.HomePhone:
break;
case ContactEndpointType.OtherPhone:
break;
case ContactEndpointType.Lync:
break;
case ContactEndpointType.VoiceMail:
break;
case ContactEndpointType.Invalid:
break;
default:
throw new ArgumentOutOfRangeException();
}
}
}
}
When you are finished with the contact you need to unhook and cleanup:
contact.ContactInformationChanged -= ContactOnContactInformationChanged;
_contactSubscription.RemoveContact(contact);
When you are finished with the subscription you need to unsubscribe at the application cleanup:
_contactSubscription.Unsubscribe();
The contact updates can come in at any time and also at multiple times or may not be updated at all if there is no contact endpoints. The backend for this is the AD contact information, so if the AD contact updates then you will be sent a update to the information that you have subscribed to.
This interface is not really for asking for contact information and getting a answer back, it's more for hooking up to userinterface elements so that they can be updated in realtime while they are currently being displayed.