function domHTML(script, contact = {}, user = {}) { console.log(contact.first_name); console.log(user.name); let dom = ` <div class="main py-3 w-100"> <div class="container"> <div class="content"> ${script} </div> </div> </div>`; console.log(dom); //return dom;} let script = `Hey ${contact.first_name}, ${contact.first_name} this is ${user.name} giving you a quick call from the benefits office here in ${contact.state}. I'll have you have the phone here sec but they have me giving you a quick call because of a form you filled out requesting more information about the life insurance programs through the state of ${contact.state}. They have me, the field underwriter, calling to verify the information, I have DOB as ${contact.birthday} is that correct? Perfect, so ${contact.first_name} like I said I'm just the field underwriter they have calling to let you know your request has been processed.Estamos haciendo todo virtualmente ahora debido a covid. Toma alrededor de 10-15 minutos para obtener la información. Tome un bolígrafo y papel para las notas y eliminará esto para que no reciba más llamadas.
Quiero hacer que todas las variables se reemplacen con argumentos de función
Puede convertir su secuencia de script en una función que acepte argumentos y pasarla a domHTML , de esa manera la función de secuencia de script puede pasarle las variables de contact y user .
function domHTML(fn ,contact = {}, user = {}) { let theScript = fn(contact, user) let dom = ` <div class="main py-3 w-100"> <div class="container"> <div class="content"> ${theScript} </div> </div> </div>`; return dom; } function script(contact, user){ return `Hey ${contact.first_name}, ${contact.first_name} this is ${user.name} giving you a quick call from the benefits office here in ${contact.state}. I'll have you have the phone here sec but they have me giving you a quick call because of a form you filled out requesting more information about the life insurance programs through the state of ${contact.state}. They have me, the field underwriter, calling to verify the information, I have DOB as ${contact.birthday} is that correct? Perfect, so ${contact.first_name} like I said I'm just the field underwriter they have calling to let you know your request has been processed.` } const dom = domHTML(script, contact, user) console.log(dom)