Skip to content

Instantly share code, notes, and snippets.

@MikeSel
Last active December 20, 2015 13:39
Show Gist options
  • Save MikeSel/6140056 to your computer and use it in GitHub Desktop.
Save MikeSel/6140056 to your computer and use it in GitHub Desktop.
Automated Lync Dialer
Imports Microsoft.Lync.Model
Imports Microsoft.Lync.Model.Extensibility
Public Class Form1
Public WithEvents _Client As LyncClient 'MS Lync Client object
Public WithEvents _ConversationMgr As Microsoft.Lync.Model.Conversation.ConversationManager 'MS Lync Conversation Object
Public WithEvents _ContactManager As Microsoft.Lync.Model.ContactManager 'MS Lync Contact Manager Object
Private _InitializeFlag As Boolean = False
Public automation As Microsoft.Lync.Model.Extensibility.Automation
Private Sub StartConversationCallback(result As IAsyncResult)
Try
automation.EndStartConversation(result)
Catch lyncClientException As LyncClientException
MessageBox.Show("Call failed.")
End Try
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
MakeCall()
End Sub
Public Sub MakeCall()
Dim conversationModes As AutomationModalities = AutomationModalities.Audio
Dim conversationSettings As New Dictionary(Of AutomationModalitySettings, Object)()
automation = _Client.GetAutomation()
If automation IsNot Nothing Then
Dim participants As New List(Of String)(1)
participants.Add("0123456789")
Try
automation.BeginStartConversation(conversationModes, participants, conversationSettings, AddressOf StartConversationCallback, Nothing)
Catch lyncClientException As LyncClientException
MessageBox.Show("Call failed.")
End Try
Else
MessageBox.Show("Lync was not initialized property. Please restart this application.")
End If
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
_Client = LyncClient.GetClient() 'Hook onto current Lync Client
_ConversationMgr = _Client.ConversationManager 'Hook onto Lync Client conversation manager
_ContactManager = _Client.ContactManager 'Hook onto Lync contact manager
Select Case _Client.State 'Check current Lync status
Case ClientState.Uninitialized 'If client unitialized then..
_Client.BeginInitialize(AddressOf InitializeCallback, Nothing) 'initialize client
Case ClientState.SignedIn 'If client is signed in then there's nothing more to do
Case ClientState.SignedOut 'If client is currently signed out then..
_Client.EndSignIn(_Client.BeginSignIn(Nothing, Nothing, Nothing, Nothing, Nothing)) 'sign in Lync client with cached credentials
End Select
End Sub
Private Sub InitializeCallback(ByVal ar As IAsyncResult) 'Lync client initialization callback
_Client.EndInitialize(ar)
_InitializeFlag = True
_Client.EndSignIn(_Client.BeginSignIn(Nothing, Nothing, Nothing, Nothing, Nothing))
End Sub
Private Sub _ConversationMgr_ConversationRemoved(sender As Object, e As Conversation.ConversationManagerEventArgs) Handles _ConversationMgr.ConversationRemoved
MakeCall()
End Sub
End Class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment