Automatically generates a messageId if there is not one.