https://discord.gg/botpress logo
API KB indexing
# 🤝help
l
@little-jelly-95112 @wide-umbrella-5226
l
Hey
l
Hey!
message has been deleted
w
@little-jelly-95112 do you know what exactly is missing? i think you're overengineering this a bit since they're already indexed, they're already in the KB so the autonomous agent should have access to it
l
I'm just pushing my latest commit to link my execute code via github
It must be how I'm handing my info to the init() or something. Although I'm not getting errors.
w
what does the execute code do exactly?
l
Feel free to drop screenshots aswell please @little-jelly-95112 or copy paste any code that might be helpful
l
Okay.
thx
My execute code. It has some error checking and fallback, but you can see it's trying to get the info from userDataResult https://cdn.discordapp.com/attachments/1442907986631852132/1442909172642353172/message.txt?ex=692876e2&is=69272562&hm=3722ff8ad93f6169741b793cc55c83749989770b514d39cfe56aa7e6f63455b4&
w
this is from chatgpt right?
l
So, if I set the testing to true, it will use the KB shown. If I set it to false and run from my app, I get the default "vensasta.com". The domain doesn't matter, it's just a KB that exists. https://cdn.discordapp.com/attachments/1442907986631852132/1442909486867288084/image.png?ex=692725ad&is=6925d42d&hm=2ee0a9fd0ad3313a2d339387d6dc8feabb392ba9f02b36fade11191c32756709&
I used Claude Code to help rewrite something I built 1.5 years ago. I used a different webchat tool though.
Everything works 100% except the setting of the variable with the proper KB, although all logs indicate it is set.
I can provide my JSON structure from my init calls, etc... if that helps.
w
what exactly fails?
it isn't set or the value set is wrong
my honest opinion that you didn't ask for is that this is a bit overengineered maybe
doing these steps inside the autonomous node using a smart model will probably deliver great results
l
Let's just treat it like this. How do I get a webchat to start up with an API cloud KB file as the knowledge for the autonomous node.
That's all I need to know
Ignore everything else.
Like, a sample init() that will create a webchat that uses an existing cloud file uploaded by API
w
you don't really need an init i think
you can just query the kb api with your desired filters and save that to a variable
and give your AN access
l
I do need an init. I'm creating these pages dynamically.
Basic flow: 1. you enter a website 2. I scrape it and build a KB file 3. I upload that to botpress API as a file 4. I load a simple webpage 5. I init the webchat on that page with the new KB
Everything works, except "linking" the webchat with the KB file (even though it does exist)
w
and what exactly fails?
.
l
Can you show me this. How do I init a webchat with a cloud file via API call?
Appears to not be set
The execute code finds no data in the User Data and goes to the backup value
w
but is the data present in the user data?
if it is then you're probably accessing it wrong
i don't know what you mean by this
you're not going to start the webchat through the api call
l
botpress doesn't log anything before the workflow starts. I see the info being passed to the API, but I cannot see it being received.
w
it logs the events received
so you could check webchat:conversationStarted
the workflow's start is the first "message_created"
but you really don't need to start the bot with a custom kb
you can just immediately inject it
using client.searchFiles with the tags you want
l
Do you have an example of code that will make an API call to botpress and create a webchat on a page that uses a file stored in the API file cloud storage?
w
there is no such thing as create a webchat on a page through the api
you need the page to have the scripts inside it
the webchat is already created
what you COULD do is get the custom variables you're injecting
and call the kb search files using your custom ids and tags
l
Right, but I need to be able to pass the value for that from my program. I'm using the domain assocaited with the KB. It works if I hard-code in the workflow ... but I cannot use client-searchFiles if I don't have that value
w
or just grab the whole kb and save it
you could query
https://api.botpress.cloud/v1/files/search
GET with x-bot-id and your Bearer PAT
l
Before: My nodejs app knows the name of the KB file Transition: My nodejs app is init() ing the webchat with this info After: The workflow starts but does not seem to know the KB file
I can do this within the workflow? How do I retrieve the Bearer PAT in workflow?
w
yes
for the PAT (personal access token) you have to get to your botpress personal profile
not your bot settings
and generate the PAT
from what i can see in your code you're already calling searchfiles so you're going to do basically the same thing
l
So there is a unique PAT each time the workflow is ran?
w
through the files API
no
that's your botpress profile's pat
as stooky
l
I need a unique identifier to find the file.
It's a new file each time
w
your PAT is for authentication
not for file identifiers
it's a PERSONAL ACCESS TOKEN
l
I know, but I thought maybe you could use that per session to help identify the file. I'm using JWT PAT right now
w
well you could just give the file a custom tag
and then use that same tag when calling search files
Copy code
js
  query: 'whatever',
  tags: {
    customtag: 'customvalue',
  },
l
Whatever I do, I have to be able to pass it from my nodejs app into the workflow.
That seems to be the issue I'm running into.
w
well it's a simple api call
surely your app can do it
when uploading your scraped website just save it with a custom tag
like an id
then call searchfiles with your custom id and give it to your autonomous node
or literally delete your custom code and give the ID to your autonomous node retrieval model
l
So you're saying. 1. Create the KB 2. UPLoad 3. Create the webchat on the page 4. Make an API call that sets a variable within the workflow after webchat is initialized
w
3 and 4 are interchangeable depending on how you want to implement it
but that's a solution yes
l
The workflow doens't exist until the webchat is "mounted"
I didn't think you could alter a live workflow with an API call
w
oh boy do i have an api for you
l
Nice
the runtime api is just for that
never usethe chat api by the way
use the messaging api for your messaging needs
and the runtime for everything else
l
Cool, so for each unique instance I can call the runtime API to alter any of those unique instances.
I'll dig into it.
Thx.
I would like to know why I can't init with those variables though!!!
w
i think you're just initting it wrong maybe
the documentation is a bit messy sometimes
since you're passing the id maybe you're accessing it wrong then initting
or maybe you're not passing it at all
l
Can you paste me a clean init?
w
i believe i can
one minute
Copy code
js
window.botpress.init({
  "botId": "",
  "configuration": {
    "version": "",
    "botName": "",
    "botAvatar": "",
    "botDescription": "",
    "website": {},
    "email": {},
    "phone": {},
    "termsOfService": {},
    "privacyPolicy": {},
    "color": "",
    "variant": "",
    "headerVariant": "",
    "themeMode": "",
    "fontFamily": "",
    "radius": 0,
    "feedbackEnabled": false,
    "footer": "",
    "additionalStylesheetUrl": "",
    "soundEnabled": false,
    "proactiveMessageEnabled": false,
    "proactiveBubbleMessage": "",
    "proactiveBubbleTriggerType": "",
    "proactiveBubbleDelayTime": 0
  },
  "clientId": ""
});
l
const initConfig = { // Bot configuration (from Botpress dashboard) botId: '3809961f-f802-40a3-aa5a-9eb91c0dedbb', clientId: 'f4011114-6902-416b-b164-12a8df8d0f3d', // Styling configuration configuration: { botName: 'Custom Assistant', botDescription: 'I can assist you with your specific custom requests and provide tailored information.', color: '#3276EA', variant: 'solid', themeMode: 'light', fontFamily: 'inter', radius: 1 }, // THE CRITICAL PART: userData with domain info userData: { domain: domain, website: website, sessionID: sessionID, fileId: kbFileId || '' } }; bp.init(initConfig);
My userData is not getting through (or throwing errors)
w
youre using the wrong method i think
try window.botpress.updateUser
after the webchat intializes
l
Okay cool. I'll try that.
w
window.botpress.updateUser({ data: { domain: domain, website: website, sessionID: sessionID, fileId: kbFileId || '' },
l
I might have to cancel a few meetings today with this new info : )
w
Copy code
js
window.botpress.on('webchat:initialized', () => {
  console.log('Webchat has been initialized. Loading user...');
  window.botpress.updateUser({
    data: {
      firstName: newFirstName,
      lastName: newLastName,
      email: newEmail,
    },
  })
});
this shdould work
l
I really apprecaite the help here.
w
then for accessing it you call getbotpress user
Copy code
js
async function getBotpressUser() {
  const user = await window.botpress.getUser()
  console.log(user)
}

getBotpressUser();
l
thx
w
no problem!! feel free to ping me if you need any more help
l
I'm gald I randomly jumped into that AMA
Hey @wide-umbrella-5226 , sending this message as the first message into the chat worked ... but that's just ridiculous. I guess the execute code card fires against everything in the first message of the chat. https://cdn.discordapp.com/attachments/1442907986631852132/1442991683007676426/image.png?ex=6927723a&is=692620ba&hm=da2e3effdb53421ec70f14fcfc082d25a6d4c9017e0e93007a437f42ef31a429&
I'm still trying to figure out how to set proper variables using those APIs you sent me. It just seems like nothing happens in the workflow until the first message is sent.
w
well yes because the workflow only runs when the conversation starts
which is when a message is sent
that's why i offered this as an option
because it updates the user WHEN WEBCHAT INITIALIZES instead of when the conversation starts
l
I did try that route, but it did not seem to update my variables in the workflow.
w
did you try setting them though?
based on the event payload you get
after those variables are set on the .updateUser method you can use webchat get user data card i think -# ⚠ i don't really know if this works
i personally never used it since i don't use webchat
l
Got it working.
l
First time, janky. This time proper with user.data.
Thanks for the help.
Can also try it here (still very beta): http://mb.membies.com:3000/
3 Views