display dialog using image data

How do I display image data with display dialog?
I am trying to take the image data from a buddy in Messages and display dialog using that image.


tell application "Messages"
	set image_data to image of buddy 1
end tell

set image_string to image_data as string
display dialog "Hello" with icon image_string

Unable to make data into string error returns as a consequence

Hi,

a bit class confusion

image_data is of class data and cannot be coerced to string.
icon doesn’t recognize string representation of an external icon.

The solution is to write the data into a temporary image file.
I added also error handling in case the buddy doesn’t have an image.


tell application "Messages"
	set image_data to image of buddy 1
end tell
set isValid to image_data is not missing value
set buddyImage to (path to temporary items folder as text) & "buddyImage.tiff"
if isValid and (writeFile from image_data into buddyImage) then
	display dialog "Hello" with icon (alias buddyImage)
else
	display dialog "Hello" with icon caution -- this line is executed when there is no image or writing the image fails
end if

on writeFile from theData into theFile
	try
		set fileDescriptor to open for access file theFile with write permission
		write theData to fileDescriptor
		close access fileDescriptor
		return true
	on error
		try
			close access file theFile
		end try
		return false
	end try
end writeFile

Thank you for the explanation of the need to write to a file, and for the applescript demonstration of that solution. That helped a lot.