LotusScript to Make TAPI 3 call
Category Lotus Notes LotusScript TAPI
This may be old hat for someone out there, but it was very new and very cool for me recently.
I just purchased a new telephone system, an Avaya IP Office 500, and have a mixture of hard and soft phones, all running over IP. One area of interest for me in this purchase was the ability to integrate some of our Notes apps with the phone system, to have an 'Easy Dialer' capability.
I thought it would be easy enough to do, and sure it was...here is a document action button script I have cleaned up to publish...
Dim wkspace As New NotesUIWorkspace 'Setup to get a handle to the current document
Dim uidoc As NotesUIDocument
Set uidoc = wkspace.CurrentDocument
sNumToCall = uidoc.Document.phonenumber(0) 'this grabs the phone number to call from the current document
If Len(sNumToCall) <> 4 Then 'If it is an internal number (4 digits) then don't do anything to the number
If Left(sNumToCall,2) <> "9," Then 'Check to see if it starts with an outside line 'escape code', if not prefix to the number
sNumToCall = "9," & sNumToCall 'Clearly, if it is a long distance number or a toll free, then we need to add a '1' for the long distance escape code, but we will handle that later
End If
End If
Dim gobjTAPI As Variant 'the base TAPI 3 object
Dim gobjAddress As Variant 'this represents a placeholder TAPI device we will use to place the call
Dim objCollAddresses As Variant 'this represents all of the TAPI devices on the machine
Dim objCrtAddress As Variant 'this is THE TAPI device we will use for the call
Set gobjTapi = createobject("tapi.tapi.1") 'Create the base object
Call gobjTapi.Initialize 'Initialize the object (std call)
Set objCollAddresses = gobjTapi.Addresses 'Get a collection of the TAPI devices available for the call
bFound = False 'Set a check flag
For indexAddr = 1 To objCollAddresses.Count 'Loop through the TAPI devices to find the one we want to use (my IP Office Phone Manager Pro softphone)
Set objCrtAddress = objCollAddresses.Item(indexAddr) 'this allows us to look at the details of the selected TAPI device
If Left(objCrtAddress.AddressName(), Len("IP Office")) = "IP Office" Then 'If the TAPI device's name begins with 'IP Office' then we have found what we are looking for
'the actual device will have a name like IP Office Ext #### and will change based on the extension, so we truncate
bFound = True
Set objCrtAddress = Nothing 'Clear the current object...not sure why to do this, but the API help code said it is a good practice
End If
If bFound = True Then Exit For
Next indexAddr
Set gobjAddress = objcollAddresses.Item(indexAddr) 'Set an object for the device
Set gobjCall = gobjAddress.CreateCall(sNumToCall, 1, 8) 'make the call. The '1'(LINEADDRESSTYPE_PHONENUMBER ) ids this as a phonenumber call, the '8' (TAPIMEDIATYPE_AUDIO ) ids this as a audio media type call.
'Connect the call; False means that the call is made asynchronously.
gobjCall.Connect (False) 'This actually makes the call happen - YEA!!!
Obviously, this is a pretty simple (and lacking in error check/control) example, but it is really pretty straight forward to get this type of functionality into your Notes apps, if you have the hardware/software telephony components available. The cost of the Avaya IP Office system was pretty reasonable for functionality of this type, and I am sure something like an Asterisk type telephony system would be even less costly.
This kind of functionality really helps 'sell' Notes apps to your line of business users.
This may be old hat for someone out there, but it was very new and very cool for me recently.
I just purchased a new telephone system, an Avaya IP Office 500, and have a mixture of hard and soft phones, all running over IP. One area of interest for me in this purchase was the ability to integrate some of our Notes apps with the phone system, to have an 'Easy Dialer' capability.
I thought it would be easy enough to do, and sure it was...here is a document action button script I have cleaned up to publish...
Dim wkspace As New NotesUIWorkspace 'Setup to get a handle to the current document
Dim uidoc As NotesUIDocument
Set uidoc = wkspace.CurrentDocument
sNumToCall = uidoc.Document.phonenumber(0) 'this grabs the phone number to call from the current document
If Len(sNumToCall) <> 4 Then 'If it is an internal number (4 digits) then don't do anything to the number
If Left(sNumToCall,2) <> "9," Then 'Check to see if it starts with an outside line 'escape code', if not prefix to the number
sNumToCall = "9," & sNumToCall 'Clearly, if it is a long distance number or a toll free, then we need to add a '1' for the long distance escape code, but we will handle that later
End If
End If
Dim gobjTAPI As Variant 'the base TAPI 3 object
Dim gobjAddress As Variant 'this represents a placeholder TAPI device we will use to place the call
Dim objCollAddresses As Variant 'this represents all of the TAPI devices on the machine
Dim objCrtAddress As Variant 'this is THE TAPI device we will use for the call
Set gobjTapi = createobject("tapi.tapi.1") 'Create the base object
Call gobjTapi.Initialize 'Initialize the object (std call)
Set objCollAddresses = gobjTapi.Addresses 'Get a collection of the TAPI devices available for the call
bFound = False 'Set a check flag
For indexAddr = 1 To objCollAddresses.Count 'Loop through the TAPI devices to find the one we want to use (my IP Office Phone Manager Pro softphone)
Set objCrtAddress = objCollAddresses.Item(indexAddr) 'this allows us to look at the details of the selected TAPI device
If Left(objCrtAddress.AddressName(), Len("IP Office")) = "IP Office" Then 'If the TAPI device's name begins with 'IP Office' then we have found what we are looking for
'the actual device will have a name like IP Office Ext #### and will change based on the extension, so we truncate
bFound = True
Set objCrtAddress = Nothing 'Clear the current object...not sure why to do this, but the API help code said it is a good practice
End If
If bFound = True Then Exit For
Next indexAddr
Set gobjAddress = objcollAddresses.Item(indexAddr) 'Set an object for the device
Set gobjCall = gobjAddress.CreateCall(sNumToCall, 1, 8) 'make the call. The '1'(LINEADDRESSTYPE_PHONENUMBER ) ids this as a phonenumber call, the '8' (TAPIMEDIATYPE_AUDIO ) ids this as a audio media type call.
'Connect the call; False means that the call is made asynchronously.
gobjCall.Connect (False) 'This actually makes the call happen - YEA!!!
Obviously, this is a pretty simple (and lacking in error check/control) example, but it is really pretty straight forward to get this type of functionality into your Notes apps, if you have the hardware/software telephony components available. The cost of the Avaya IP Office system was pretty reasonable for functionality of this type, and I am sure something like an Asterisk type telephony system would be even less costly.
This kind of functionality really helps 'sell' Notes apps to your line of business users.






Comments
I would post a pertinent comment, but haven't read that post up there because it looks hard.
Posted by Jaq at 11:35:05 PM on 04/30/2008 | - Website - |