peer____42 peer____42 - 18 days ago 5
C# Question

skype for business outgoing call and play audio file

Goal is to develop an interface of a systems monitoring solution to a module, which calls an on-call duty person and plays some speech/audio file from file system.

i have an skype for business 2015 (fomerly lync) user with phone options enabled. i am also able to call phone a number. but then the question is, how to wait until the dialed person accepts the phone call and play an audio file (or better is the System.Speech variant instead of playing an audio file) and after that the person has to approve that he/she received the call.

what i currently have:

public void SendLyncCall(string numberToCall, string textToSpeech)
{
var targetContactUris = new List<string> {numberToCall}; //"tel:+4900000000" }; //removed here

_automation.BeginStartConversation(AutomationModalities.Audio, targetContactUris, null, StartConversationCallback, null);

while (this.globalConv == null)
{
Thread.Sleep(1);
}
if (globalConv != null)
{
LyncClient client = LyncClient.GetClient();

client.DeviceManager.EndPlayAudioFile(
client.DeviceManager.BeginPlayAudioFile(@"d:\tmp\test1.wav",
AudioPlayBackModes.Communication,
false,
null,
null));
}
}

private void StartConversationCallback(IAsyncResult asyncop)
{
// this is called once the dialing completes..
if (asyncop.IsCompleted == true)
{

ConversationWindow newConversationWindow = _automation.EndStartConversation(asyncop);
globalConv = newConversationWindow;
AVModality avModality = globalConv.Conversation.Modalities[ModalityTypes.AudioVideo] as AVModality;


foreach (char c in "SOS")
{
avModality.AudioChannel.BeginSendDtmf(c.ToString(), null, null);
System.Threading.Thread.Sleep(300);
}

}
}


and the other question is, is it possible to change whole module to be a registered endpoint that it can run as a windows service? Currently my sfb has to be opened and logged in..

Answer

Please note this is NOT UCMA code you posted, it's Lync Client SDK code.

I'm going to assume you want to know how to do what you ask with the Lync Client SDK.

You need to hook the AVModality.ModalityStateChanged event to see know when it changes to the AVModality.State changes to Connected.

Once in the Connected state, you can do what you want.

Adjusting your code I came up with:

private void StartConversationCallback(IAsyncResult asyncop)
{
    // this is called once the dialing completes..
    if (asyncop.IsCompleted == true)
    {
        ConversationWindow newConversationWindow = _automation.EndStartConversation(asyncop);
        AVModality avModality = newConversationWindow.Conversation.Modalities[ModalityTypes.AudioVideo] as AVModality;
        avModality.ModalityStateChanged += ConversationModalityStateChangedCallback;
    }
}

private void ConversationModalityStateChangedCallback(object sender, ModalityStateChangedEventArgs e)
{
    AVModality avModality = sender as AVModality;
    if (avModality != null)
    {
        switch (e.NewState)
        {
            case ModalityState.Disconnected:
                avModality.ModalityStateChanged -= ConversationModalityStateChangedCallback;
                break;

            case ModalityState.Connected:
                avModality.ModalityStateChanged -= ConversationModalityStateChangedCallback;
                foreach (char c in "SOS")
                {
                    avModality.AudioChannel.BeginSendDtmf(c.ToString(), null, null);
                    System.Threading.Thread.Sleep(300);
                }
                break;
        }
    }
}
Comments