Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Dial with Vonage from the Address Book' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Dial with Vonage from the Address Book
Authored by: pat2man on Apr 01, '05 03:08:40PM
Sorry, that code was an old version of what I was working on. Try this:



(*

 Automatic Vonage Dialer v0.5
 Major Changes by Patrick Tescher, pat2man@comcast.net
 
 Based on:
  Automatic Vonage Dialer v0.2
  Aaron Freimark, abf@mac.com
  March 16, 2004
	
  Put this script into your "Address Book Plugins" folder in your ~/Library folder.
  Only works in the US with this version

*)

property keyName : "Vonage"

-- The lines below are correct for the U.S.
property myCountryCode : "1"
property myLongDistanceCode : "1"
property myIntlAccessCode : "011"


using terms from application "Address Book"
	on action property
		return "phone"
	end action property
	
	on action title for pers with fone
		return "Dial with Vonage"
	end action title
	
	on should enable action for pers with fone
		if label of fone contains "fax" then return false
		return true
	end should enable action
	
	on perform action for pers with fone
		set theKey to GetKeyNamed(keyName)
		
		-- set theKey to myVonageKey
		if theKey is null then
			set theKey to CreateKey(keyName)
		end if
		
		tell application "Keychain Scripting"
			set myVonageLogin to account of theKey
			set myVonagePassword to password of theKey
		end tell
		set NumberList to GetNumbers(myVonageLogin, myVonagePassword)
		if (count of NumberList) is greater than 1 then
			set myVonageNumber to GetDefaultNumber(comment of theKey, NumberList)
			if myVonageNumber is null then
				set myVonageNumber to SelectNumber(NumberList)
			end if
		else
			set myVonageNumber to item 1 of NumberList
		end if
		
		set theNumber to (value of fone) as string
		
		-- Add the long distance or international access code if it's not already there.
		set numToDial to InsertLDCodes(theNumber)
		
		--Uncomment the following two lines to confirm the number
		--display dialog "So you want me to call?" default answer numToDial buttons {"OK"}
		--set numToDial to text returned of the result
		
		--Erase everything that's not a digit from the phone number
		set cleanedNumber to CleanTheNumber(numToDial)
		
		set theURL to "https://secure.click2callu.com/tpcc/makecall?"
		set theURL to theURL & "username=" & myVonageLogin
		set theURL to theURL & "&password=" & myVonagePassword
		set theURL to theURL & "&fromnumber=" & myVonageNumber
		set theURL to theURL & "&tonumber=" & cleanedNumber
		
		
		
		-- Use curl to hit the URL and dial the number  
		--set errorCode to do shell script "curl \"" & theURL & "\""
		display dialog "curl \"" & theURL & "\""
		
		--If there was an error, return a message.
		if (characters 1 thru 3 of errorCode) as string is not equal to "000" then
			display dialog "Error: " & errorCode buttons {"OK"}
		end if
		
	end perform action
	
end using terms from


on InsertLDCodes(theNumber)
	
	if (characters 1 thru 2 of theNumber) as string = "+" & myCountryCode then
		-- The number was formatted correctly.
		return theNumber
	end if
	
	if character 1 of theNumber = myLongDistanceCode then
		-- Domestic long distance with LD access code
		return theNumber
	end if
	
	if character 1 of theNumber = "+" then
		--  international number, add prefix
		return myIntlAccessCode & " " & theNumber
	end if
	
	--  local number, must add the LD code for Vonage
	return myLongDistanceCode & " " & theNumber
	
end InsertLDCodes

on CleanTheNumber(numToDial) -- remove punctuation from a string, leaving just the number
	set theDigits to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
	set cleanedNumber to ""
	repeat with i from 1 to length of numToDial
		set j to (character i of numToDial)
		if j is in theDigits then set cleanedNumber to cleanedNumber & j
	end repeat
	return cleanedNumber
end CleanTheNumber

on GetKeyNamed(keyName)
	
	tell application "Keychain Scripting"
		try
			tell current keychain
				get some generic key whose name is keyName
				return result
			end tell
		on error
			return null
		end try
	end tell
end GetKeyNamed

on CreateKey(keyName)
	tell application "Address Book"
		display dialog "Enter Username" default answer "username" buttons {"OK"} default button "OK"
		set myVonageLogin to text returned of the result
		display dialog "Enter Password" default answer "password" buttons {"OK"} default button "OK"
		set myVonagePassword to text returned of the result
		display dialog "Enter Vonage Number" default answer "15555555555" buttons {"OK"} default button "OK"
		set myVonageNumber to text returned of the result
		(* set VonageNumbers to GetNumbers(myVonageLogin, myVonagePassword)
		if (count of VonageNumbers) is 1 then
			set myVonageNumber to item 1 of VonageNumbers
		else
			set myVonageNumber to null
		end if *)
	end tell
	tell application "Keychain Scripting"
		tell current keychain
			make new generic key with properties 
					{name:keyName, account:myVonageLogin, password:myVonagePassword, comment:"Default Number: " & myVonageNumberreturn result
		end tell
	end tell
end CreateKey

on GetDefaultNumber(comments, VonageNumbers)
	set theNumber to null
	repeat with currentWord in VonageNumbers
		if currentWord is in comments then
			set theNumber to currentWord
		end if
	end repeat
	return theNumber
end GetDefaultNumber

on GetNumbers(login, pass)
	set theURL to "https://secure.click2callu.com/tpcc/getnumbers?"
	set theURL to theURL & "username=" & login
	set theURL to theURL & "&password=" & pass
	set errorCode to do shell script "curl \"" & theURL & "\""
	return words in errorCode
end GetNumbers

on SelectNumber(NumberList)
	tell application "Address Book"
		display dialog "Choose a number" buttons NumberList
		return button returned of result
	end tell
end SelectNumber




[ Reply to This | # ]