Adding Multiple JS Injections in Netsapiens

Adding Multiple JS Injections in Netsapiens

Loading External JavaScript Scripts into Netsapiens

This guide covers two methods for loading multiple external JavaScript files into Netsapiens portal.



Method 1: UI Config Trick

This method leverages how Netsapiens processes UI config values by injecting multiple script tags through a single configuration entry.


How It Works

Netsapiens takes the UI config value and renders it as a <script> tag in the page. By carefully formatting the value, you can inject multiple script tags at once.


Configuration

In your UI config, enter the following value (replace URLs with your actual script URLs):

YOUR_FLOWBOT_JS_URL"></script><script src="ANY_OTHER_JS_URL


Result

The above configuration will be rendered in the HTML as:

<script src="FLOWBOT_JS_URL"></script>
<script src="ANY_OTHER_JS_URL"></script>
Info

⚠️ Important Note

While this method works for loading multiple scripts, the configuration becomes increasingly difficult to manage and maintain as you add more files. The string quickly becomes monstrous and error-prone with many nested script tags. For loading more than 2-3 scripts, consider using Method 2 instead.



Method 2: Dynamic Script Loading

This method involves loading external scripts dynamically from within another script that's already included in Netsapiens Portal page.


Implementation

Add the following JavaScript code to a script that's already loaded in Netsapiens:

(function() {
'use strict';

const FLOWBOT_SCRIPT_URL = 'YOUR_FLOWBOT_JS_URL_HERE';

function loadFlowbot() {
const script = document.createElement('script');
script.src = FLOWBOT_SCRIPT_URL;
script.async = true;

script.onload = function() {
console.log('Flowbot widget loaded successfully');
};

script.onerror = function() {
console.error('Failed to load Flowbot widget from:', FLOWBOT_SCRIPT_URL);
};

document.head.appendChild(script);
}

function init() {
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', loadFlowbot);
} else {
loadFlowbot();
}
}

init();
})();


Info

⚠️ CSP Considerations

Content Security Policy (CSP) may block dynamically loaded scripts if the Netsapiens portal has strict CSP headers configured. If you encounter issues with scripts not loading:

  • Check the browser console for CSP violation errors
  • Verify that the external script domain is whitelisted in the CSP policy
  • Contact your administrator to add the required domains to the CSP script-src directive



Comparison

FeatureMethod 1: UI ConfigMethod 2: Dynamic Loading
Ease of Setup✅ Very Easy⚠️ Moderate
Multiple Scripts✅ Yes✅ Yes
Error Handling❌ No✅ Yes
Conditional Loading❌ No✅ Yes
CSP sensitive✅ No❌ Yes
Code Required✅ No❌Yes
Multi-file Support❌ Poor✅ Excellent


Recommendations

  • Use Method 1 when you need a quick, configuration-only solution for loading simple scripts
  • Use Method 2 when you have exising JS imported into NS portal and need more control, error handling, or conditional loading logic
    • Related Articles

    • Embedding FlowbotAI in Netsapiens

      This article explains how to enable FlowbotAI’s native Netsapiens integration inside the Netsapiens Office Manager Portal (OMP). Once enabled, Service Partners can activate, auto-provision, manage, and support FlowbotAI agents directly in their OMP — ...
    • Agent Reaction After Tool Calls

      FlowbotAI Agent Reactions After Tool Calls When an agent calls a tool, you can control what happens next: should the agent speak immediately, stay silent and listen, or speak only in specific situations. This helps you avoid awkward “double talk” ...
    • Zapier Worfkflow Integration

      Flowbot Agent Connector – Zapier Integration Guide The Flowbot Agent Connector allows you to integrate your Flowbot Voice Agents with over 8,000+ apps in the Zapier ecosystem. Automate everyday tasks like creating tickets, updating CRMs, sending ...
    • Explore Custom Tools

      What “Custom Tools” mean in FlowbotAI Custom tools give your FlowbotAI agent the ability to communicate with systems outside the call—anything you can do in a function (or API endpoint) can be exposed to the agent as a tool. Tools are the foundation ...
    • Knowledge (RAG) Overview

      Give your agent access to your KB, product docs, playbooks, and internal procedures—without stuffing everything into the prompt. Why RAG matters (especially in production) Large language models know a lot about the world, but they won’t reliably know ...