Ummm,
That's a bit of a puzzler.
iMessages are stored in the three Chat.db items in ~/Library/messages
If you also Save Chats (in the General Section of the Preferences) they are also stored in:-
~/Library/Containers/com.apple.iChat/Data/Library/Messages/Archive by date and time (further subfolders)
Both are used, depending on the type of chat to show the "History" of a chat/conversation if you have dismissed it from view.
In the Main window the Side bar has the list of Chat and Conversations that are open.
Mousing over the list reveals an "x" to the right of the preview text.
This can be used to "hide" that chat to conversation until either they send a new messages or you do.
The File Menu give you the option to Close the Window,
Close Conversation (what I have called "Dismiss" before) or you can
Delete Conversations using CMD and Backspace when the Chat or Conversation is highlighted.
The chat..db items are sql files in effect and cannot be edited with the Standard install items on a Mac.
The chat.db items also have a role in "history" of non iMessages chats that are Saved in the Archive folder.
Individual items can be deleted from Conversation/Chat by highlighting that one item then using the backspace.
From my limited testing a while back it seems items deleted in the Main window are deleted with the app making the "edits" if you like to the Chat.db items and Archive folder.
My testing was limited as I ran out of items I didn't mind losing.
I presume that the app has some way of counting the individual messages with a chat/Conversation.
However how that relates to the chat itself and where it might be in the list at any given moment, as ones with new messages pop to the top, makes me wonder if it is possible to get AppleScript to look inside a window of an open app.
I am not sure what to suggest.

9:47 pm Tuesday; March 15, 2016
iMac 2.5Ghz i5 2011 (El Capitan)
G4/1GhzDual MDD (Leopard 10.5.8)
MacBookPro 2Gb (Snow Leopard 10.6.8)
Mac OS X (10.6.8),
Couple of iPhones and an iPad