https://discord.gg/botpress logo
Kd id and indexing
# 🤝help
c
im trying to make a workflow from n8n to botpress, where new pages will be sent to my bots knowledge base frequently, where do i find my kb id? Also, under my knowledge base it says it will recrawl sites every day but it has not done it for a few days.
l
Good morning @curved-easter-40611 !
After selecting your desired KB, you can locate the KB ID in the url. In my case: kb-1aa0dc748a
c
okay thank you!
and for the recrawl issue?
l
@wide-umbrella-5226 he is an n8n expert maybe he can suggest some ideas!
lampy is having trouble making a workflow from n8n to botpress, where the workflow will send new sites to the bots knowledgebase,
w
expert is a big word
but i'll take a look of course
c
can i dm?
w
if you want, sure
i've been developing the solution for a few hours now but i hit a snag that i'm not able to fix myself
what lampy needs to do in n8n is upload a file to the kb, which is the website using upsertFile https://botpress.com/docs/api-reference/files-api/openapi/upsertFile
it has two steps: 1. i query https://api.botpress.cloud/v1/files with a few parameters like tokens, the file's name and size, and others stuff - that returns a URL where i'm supposed to upload that file 2. i query that url with my file and i upload it
but i can't upload the file because i get an error "SignatureDoesNotMatch The request signature we calculated does not match the signature you provided. Check your key and signing method" from the server botpress hosts its files in
c
Thanks for the help @wide-umbrella-5226 What's the correct API endpoint URL to upload files to a knowledge base from a third-party service like n8n
w
i managed to upload the files finally but there's no content in them
c
ohh nice
howd u do that
json: { "key": "{{ $json.loc }}", "fileSize": 0, "index": true, "tags": { "source": "sitemap" }, "accessPolicies": ["public_content"], "customMetadata": { "title": "{{ $json['image:image'] ? $json['image:image']['image:title'] : 'Page from OraBLISS' }}", "pageUrl": "{{ $json.loc }}" } } Does this look right? https://cdn.discordapp.com/attachments/1427994207116591195/1428093322374807664/image.png?ex=68f13f0c&is=68efed8c&hm=6b32920cff23f6c1396766fb263343205bce099a2a89a092c1953f2f66c0b267& https://cdn.discordapp.com/attachments/1427994207116591195/1428093322831990886/image.png?ex=68f13f0c&is=68efed8c&hm=b6cd5aafee395ce7be101a7a8abebf0fb3467de5c9b2e86787126d370d508fed&
w
no not really
but wait i think i almost got it finally
give me just a little more time
c
sure! thx
w
well i managed to fix everything but i have bad news
seems like this specifically is not doable in n8n because of the filesizes
the final put request works with a few thousand bytes, but anything larger crashes n8n's internal memory because of circular structure conversion
c
hmm okay, i see and thanks for the help
is there no way to add urls to the knowledge base automatically
surely that is possible, for example if a site launches a new product
and then you dont have to add the new product site manually but the bot or a worklflow does it
w
the only way i could find in the api documentation is that way unfortunately
c
Alright but thanks so much for the help
w
no worries
i'm gonna keep trying a bit later
c
And also Does the Botpress Files API support accepting URLs that it will then crawl? Or is there a separate "crawl/ingest URL" endpoint in Botpress? For example making a workflow where the bot will recrawl the entire sitemap
Or does the urls and files
act the same
w
doesn't seem like it unfortunately
at least not directly in the documentation
the only solution i could find was to download the pages as binary data then pass them to botpress
but they're too large and n8n crashes
all i could manage after 5 hours
c
okay i see, great work!!
w
@curved-easter-40611 found out a way to do it finally
first, after splitting your urls, plug one into a HTTP REQUEST (you can import this directly into n8n)
Copy code
json
{
  "name": "send to botpress",
  "nodes": [
    {
      "parameters": {
        "method": "POST",
        "url": "https://webhook.botpress.cloud/f93d8c01-a579-4249-97d6-2b953a99a7cf",
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "url",
              "value": "https://botpress.com/docs/api-reference/files-api/how-tos/creating-files"
            }
          ]
        },
        "options": {
          "response": {
            "response": {
              "responseFormat": "text"
            }
          }
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1296,
        0
      ],
      "id": "f0e6a004-6773-4793-9ba3-4f685c65cbf2",
      "name": "HTTP Request"
    }
  ],
  "pinData": {},
  "connections": {},
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "dca5cae2-f75b-48af-b3cf-250694bd285b",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "2772eca4be40436370723280c492a89f01d8babeff3d3c0c8db94c69c88ca5ed"
  },
  "id": "7vGIMdfp8cImeVD3",
  "tags": []
}
then, set a webhook trigger in botpress
and paste your webhook integration_id into the field above, as well as change the url you want to send
after that, connect your botpress webhook trigger to an execute code card
Copy code
javascript
const externalUrl = event.payload.body.url;

const response = await axios.get(externalUrl);
const htmlContent = response.data;

let text = htmlContent
  .replace(/<script[\s\S]*?>[\s\S]*?<\/script>/gi, '')
  .replace(/<style[\s\S]*?>[\s\S]*?<\/style>/gi, '')
  .replace(/<!--[\s\S]*?-->/g, '')
  .replace(/<head[\s\S]*?>[\s\S]*?<\/head>/gi, '')
  .replace(/<noscript[\s\S]*?>[\s\S]*?<\/noscript>/gi, '')
  .replace(/<\/?(?:div|p|br|tr|li|ul|ol|section|article|header|footer|h\d)[^>]*>/gi, '\n')
  .replace(/<\/?[^>]+>/g, '')
  .replace(/ /gi, ' ')
  .replace(/&/gi, '&')
  .replace(/"/gi, '"')
  .replace(/'/gi, "'")
  .replace(/</gi, '<')
  .replace(/>/gi, '>')
  .replace(/\r?\n\s*\r?\n/g, '\n')
  .replace(/[ \t]+/g, ' ')
  .replace(/\n{2,}/g, '\n')
  .trim();

const urlObj = new URL(externalUrl);
const domainName = urlObj.hostname.replace('www.', '');
const timestamp = new Date().toISOString().split('T')[0];
const uniqueKey = `${domainName}/${timestamp}-${Math.random().toString(36).substr(2, 9)}.md`;


const file = await client.uploadFile({
  key: uniqueKey,
  content: text, 
  index: true,
  contentType: 'text/markdown',
  accessPolicies: ["public_content"],
  tags: {
    source: "knowledge-base",
    kbId: "kb-default",
    dsType: "web-page",
    pageUrl: externalUrl,
    favicon: `https://www.google.com/s2/favicons?sz=64&domain=${urlObj.hostname}`,
    title: urlObj.pathname.split('/').pop() || domainName
  }
});

return { success: true, fileUrl: file.url, fileId: file.id };
paste that into the execute code block
and boom you're done
it's not very clean but it works... hope you enjoy the results of 6 hours of pain
at least until they open an endpoint to upload websites or reveal the required body for doing it this way
@loud-crowd-60573 guess i might be an n8n expert after all
w
@wide-umbrella-5226 The idea of passing a URL to a webhook is good, but I don't think you need to purge HTML because the KB accepts HTML
Copy code
ts
const file = await client.uploadFile({
  ...
  content: htmlContent,
  contentType: 'text/html',
  ...
});
@curved-easter-40611 have you try adding a sitemap file as website and use re-crawling https://botpress.com/docs/learn/reference/knowledge-base/add-sources#re-crawling
c
wow your the goat
thanks
i got it all set up now
yes and i have it as recrawl every day but its been three days and it has not recrawled yet
w
oh yeah I'm purging it mostly because it's gonna increase filesize, and since it's being indexed also gonna take up vector database limits
and it's gonna create more chunks and make the retrieval worse probably
c
thanks again bro, it all works now and the sites are loading up in my knowledge base, ive been struggling with this the past few days so u clutched up big time
w
message has been deleted
c
@white-nest-40686 do you have a solution for this?
w
Try doing it manually and verify whether it updates, if you haven't already
c
Removing and adding? Because i can’t manually make them recrawl or can I
l
I told you 😎
w
try using Add Pages button you should see the url of your site click on Discover Pages button
6 Views