A method of constructing a canonical gauge invariant quantum formulation for a non-gauge classical theory depending on a set of parameters is advanced and then applied to the theory of closed bosonic string interacting with massive background fields. Choosing an ordering prescription and developing a suitable regularization technique we calculate quantum guage algebra up to linear order in background fields. Requirement of closure for the algebra leads to equations of motion for massive background fields which appear to be consistent with the structure of string spectrum.