Random app is not defined frontend JS error

I seem to have found a satisfactory solution on my own. I tweaked the code from https://github.com/freshworks/marketplace-sample-apps/blob/master/Demo-Apps/twilio_sms_freshdesk/app/scripts/app.js#L41

The condition readystate == “interactive” never fired for what I could see in the logs (the only readystate value I could log was "complete) so I updated the condition and it fixed my issue

document.onreadystatechange = function () {
  if (document.readyState === "complete") renderApp();

  function renderApp() {
    var onInit = app.initialized();

    onInit.then(getClient).catch(function(error){
      console.error('RC app failed to initialize');
      console.error(error);
    });

    function getClient(_client) {
      window.client = _client;
      RCAppinitialize();
    }
  }
};```