botpress / v12

Botpress OSS – v12
https://v12.botpress.com
GNU Affero General Public License v3.0
68 stars 83 forks source link

Assets folder #898

Closed eroncastro closed 3 years ago

eroncastro commented 4 years ago

Describe the bug When I change the url path in which my application will be running, I want it to be able to also server assets from that path.

In my case, I am having trouble with assets/modules/channel-web/inject.js It uses config.host, and I would like it to use config.host + '/bot'.

function init(config) {
  const host = config.host || window.ROOT_PATH || ''
  const botId = config.botId || ''
  const cssHref = host + '/assets/modules/channel-web/inject.css'
  injectDOMElement('link', 'head', { rel: 'stylesheet', href: cssHref })
  const options = encodeURIComponent(JSON.stringify({ config: config }))
  let iframeSrc = host + '/lite/' + botId + '/?m=channel-web&v=Embedded&options=' + options
  if (config.ref) {
    iframeSrc += '&ref=' + encodeURIComponent(config.ref)
  }
  const iframeHTML = '<iframe id="bp-widget" frameborder="0" src="' + iframeSrc + '" class="bp-widget-web"/>'
  injectDOMElement('div', 'body', { id: 'bp-web-widget', innerHTML: iframeHTML })

  const iframeWindow = document.querySelector('#bp-web-widget > #bp-widget').contentWindow
  function configure(payload) {
    iframeWindow.postMessage({ action: 'configure', payload: payload }, '*')
  }
  function sendEvent(payload) {
    iframeWindow.postMessage({ action: 'event', payload: payload }, '*')
  }
  function mergeConfig(payload) {
    iframeWindow.postMessage({ action: 'mergeConfig', payload: payload }, '*')
  }

  window.botpressWebChat.configure = configure
  window.botpressWebChat.sendEvent = sendEvent
  window.botpressWebChat.mergeConfig = mergeConfig
}
demogoran commented 4 years ago

Try to specify externalUrl in httpServer of botpress.config.json.

{ "$schema": "../botpress.config.schema.json", "httpServer": { "host": "localhost", "externalUrl": "http://localhost:3000/bot", "port": 3000,

...

config.host could be equal to externaUrl. Notice please, that it may require change of some paths inside project. Also it may cause a lot of bugs related to incorrect path. It's better to use subdomain instead.

You may get more info there https://botpress.io/docs/advanced/configuration

allardy commented 4 years ago

As @demogoran said, you simply need to update the externalUrl to serve a custom path. You can even put multiple folders down (eg: externalUrl: 'http://localhost:3000/my/bots).

Out of the box, it should work without issues. If you encounter some, please share them with us

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.