Close chat in ichat

Hello I’m trying to make a script in applescript that will when someone says bye it will close that chat.
this is what i have tried

using terms from application "iChat"
	on message received themessage from theBuddy for theChat
		tell application "iChat"
			if themessage contains "bye" then
				close chat theChat
			end if
		end tell
	end message received
end using terms from

Mr. Gecko

Ok I have found a solution here it is.

using terms from application "iChat"
	on message received themessage from theBuddy for theChat
		tell application "iChat"
			if themessage contains "bye" or themessage contains "quit" or themessage contains "later" or themessage contains "cya" or themessage contains "see you" then
				send "Thank you for chatting see you later" to theBuddy
				set thewindow to front window
				close window (name of thewindow)
			end if
		end tell
	end message received
end using terms from

Great work! You should post this in Code Exchange, lots of folks might find this one useful!

Hi,

a suggestion for a more reliable specification of the chat window


using terms from application "iChat"
	on message received themessage from theBuddy for theChat
		tell application "iChat"
			if themessage contains "bye" or themessage contains "quit" or themessage contains "later" or themessage contains "cya" or themessage contains "see you" then
				send "Thank you for chatting see you later" to theBuddy
				close (1st window whose name contains full name of item 1 of (get participants of theChat))
			end if
		end tell
	end message received
end using terms from