 	DIRECT_MESSAGE: 0
 	GROUP_MESSAGE: 1
 
-	constructor: (@type, @sourceId, @destId, @message, @read = no) ->
-		if not (@type in [@DIRECT_MESSAGE..@GROUP_MESSAGE])
-			throw Error "Unknown message type: #{@type}"
-		@id = (String.fromCharCode(Math.floor(Math.random() * \
+	constructor: (type, @sourceId, @destId, @message, @read = no, @id) ->
+		if not (type in [@DIRECT_MESSAGE..@GROUP_MESSAGE])
+			throw Error "Unknown message type: #{type}"
+		@type = type
+		@id ?= (String.fromCharCode(Math.floor(Math.random() * \
 			(Options.phRand[1] - Options.phRand[0])) + Options.phRand[0]) for _ in [0..13]).join ''
 
 	toJSON: () ->

		destId: @destId
		message: @message
		read: @read

getMessageById = (id) ->
	return msg for msg in messageRegistry when msg.id is id

		onMessage: (msg, source) ->
			(return fail "group #{msg.group} does not exist") if not msg.group in groupIDs()
			source.sendMessage msg.target, "I invite you to join the group named #{msg.group}. \
				Use \"kc.join('#{msg.group}')\" to join. (generated by KentChat)", 0
			return succeed "invitation sent"
	}
	{
