https://discord.gg/botpress logo
trouble locating clientToken and messagingURL in m...
# 🤝help
p
This has likely a tired question but I am struggling to find my clientToken and messagingURL for my app? I am getting 400 errors on my custom integration and the solution appears to point at missing clientToken and messagingURL values, however I cannot locate these values in the admin or BotpressStudio. All help files seem to point in circles and don't align with what I see. If anyone has insight that would be amazing. THanks in advance.
l
The userToken is generated by the Botpress backend when createUser() is called: This API call returns both: user.id (the userId) key (the userToken) @prehistoric-airline-35248
p
I have been looking for some sort of “manual embed”/webchat config from Botpress that includes clientToken + messagingUrl/hostUrl, then I can drop that URL into configScriptUrl. But no luck so far.
l
ah sorry - youre referring to clientToken
One moment!
p
yes clientToken! 🙂
Going to link some usefull docs while im researching!
p
thank you. I was thinking of the API as a fallback, as it requires a server-side proxy, if I can use a clientToken I can stay more light weight in my approach.
l
According to the docs: Messaging URL What you're looking for is likely the Webhook URL for the Chat API integration. This is the unique endpoint for your bot. You can find it by: - Going to your bot in the Botpress Studio. - Navigating to the Integrations tab. - Finding the Chat integration in your list of installed integrations and clicking on it to open its configuration. - The Webhook URL will be displayed there. The unique ID at the end of this URL is your webhookId. - The base URL for the Chat API is https://chat.botpress.cloud. Client Token This likely refers to the User Key (sent as an x-user-key header) used to authenticate your requests to the Chat API. There are two ways to get this key: So it seems I was on the right track: Call the createUser endpoint. The response will contain a token for that user, which you can then use as the x-user-key for all subsequent requests for that user. This is the only unauthenticated endpoint.
You can also : Sign your own JSON Web Token (JWT) using a secret Encryption Key that you set in the Chat integration's configuration. This gives you control over user creation and ensures that only your application can talk to the bot.
p
I am curious if I am running down the wrong path. All of this started because I was attempting to get my current multitenant bot to allow users dynamically add their own avatar from the my public config interface into their bot instance but I can customize other things such as color and name but not the avatar for some reason. I went down the path of creating my own UI with decent up front success and ran into this 400 issue that requires the values for clientToken/messagingURL or I need a heavier weight solution with the API or even JWT/PAT where I take on the overhead of some/all traffic (load/latency/cost) or additional service to maintain.
I thought pushing an avatar would be simple! haha
w
i'm chiming in with not a lot of help but i've messed around with the botpress backend a ton and i have no clue what a client token is
what exactly are you calling that needs it?
the JWT is for signing your own userKey when acting as the integration channel
p
a quick high level is this: Current embed/config (both the JS snippet and the JSON from the shareable link) only contain botId and clientId; no clientToken, messagingUrl, or hostUrl are present. When we load the page, Botpress logs “Chatbot is alive” and accepts createEvent, but every /messages POST to webchat.botpress.cloud/.../messages returns 400. No auth-related fields are in the config. We need the full webchat/manual embed config (or the equivalent API payload) that includes clientToken (and messagingUrl/hostUrl) so that the webchat transport will authorize /messages. The Studio UI only shows the shareable/embed two-line snippet; there is no option showing a tokened config. I do not necessarily want to proxy via PAT; we just need the proper webchat config for this bot. I am looking for the correct webchat embed/config URL for this bot that includes the clientToken (and messaging/host URLs), or find any instructions to retrieve it from the integrations/CLI.
w
for querying messages you're probably going to want to use the messaging api
which is a billion times simpler
you get one webhook for in and one for out, simple as
you just query the endpoint with your pat and bot id i think
also why are you posting to webchat.botpress.cloud and not chat.botpress.cloud
that is probably causing the 400
p
good point.. I might have to say because of my learning curve? Lol ! We were posting to webchat.botpress.cloud because the embed config we have is the webchat snippet (it only gives botId/clientId). Since it’s missing clientToken/messagingUrl, every /messages call 400s.
w
yeah i don't think you can query the webchat through the api like that
a simple setup for your in/out messages is to use the messaging api
trust me
p
Awesome, I will pivot
out of curiousity, per my earlier post, I was pursuing the custom ui for a number of reasons, but a key reason was I could not get the botpress ui to pull in a customer uploaded avatar, it only shows the fallback initials. is that a limitation or is that possible to pull in an avatar image from a database record that holds the url.
w
yes you can for sure
p
context is my bot is multitenant, I pass the business Id and it loads their config and handles their data
w
how were you doing it previously?
if the database you're using has an integration then it's pretty simpe
p
Webchat embed v3.3, using botpress global (works otherwise). I set the set configuration.botAvatar to a hosted image (e.g., Firebase). Even with that set, the widget shows the fallback avatar. CSP already allows our image host (firebasestorage) and Botpress domains. window.botpress.init({ botId: 'c3xxxxxxxxxxxxxxxxxxxxxxxxxxx', clientId: '…', configuration: { botAvatar: 'https://my.cdn.com/path/to/avatar.png', … // other settings } });
.bpw-bot-avatar, .bpw-message-avatar, .bpw-floating-button .bpw-avatar, .bpw-header .bpw-avatar { background-image: url('') !important; background-size: cover !important; background-position: center !important; color: transparent !important; } .bpw-bot-avatar img, .bpw-bot-avatar svg, .bpw-message-avatar img, .bpw-message-avatar svg { opacity: 0 !important; }
We build avatarStyles from branding.logoUrl and pass it as stylesheet to window.botpressWebChat.init along with avatarUrl/botAvatarUrl.
w
but it gets an accessible image file at the end right?
that you're passing to the window init
p
I also inject an and apply the background image via applyAvatarBranding() on mutation (same file), to force the avatar on header/message/fab nodes
w
since you're using a CDN is there a chance it's an authentication error?
it can't access the image
p
I can reach my image file from the web. I am not getting permissions issues.
w
hmm
i'll test it out here and get back to you in a bit
p
thank you!
w
oh nice
p
lol. gotta go with style!
w
it embeds so surely no auth issue
p
right
w
well i think i know the issue
what i'm not sure is how to fix it LOL
give me a few more
p
I started thinking maybe I would be better served to create a custom UI where I could do even cooler stuff for my customers and let botpress handle the traffic/load hence my original thread opener.
w
figured it out
Copy code
css
.bpHeaderContentAvatarImage{
    content: url("https://firebasestorage.googleapis.com/v0/b/ai-intelligent-support.firebasestorage.app/o/bot-branding%2FrkQT54r1RodadrNgT2YVPNIf6cJ2.jpg?alt=media&token=80d7fe02-552c-46a1-a8ff-973d1e380d97");
}

.bpMessageListMarqueeAvatarImage{
    content: url("https://firebasestorage.googleapis.com/v0/b/ai-intelligent-support.firebasestorage.app/o/bot-branding%2FrkQT54r1RodadrNgT2YVPNIf6cJ2.jpg?alt=media&token=80d7fe02-552c-46a1-a8ff-973d1e380d97");
}
try it out
that's a great alternative as well. you can also do the connection between the two services super easily using the messaging api
oh whoops i just noticed that's not an actual solution since you're multitenant
hold on
@prehistoric-airline-35248 "botAvatar": "https://firebasestorage.googleapis.com/v0/b/ai-intelligent-support.firebasestorage.app/o/bot-branding%2FrkQT54r1RodadrNgT2YVPNIf6cJ2.jpg?alt=media&token=80d7fe02-552c-46a1-a8ff-973d1e380d97" worked for me
p
testing that i.e. botAvatar: ${JSON.stringify(logoUrl)},
w
hell yeah babey
the trick is to do all custom css you need inside the webchat styler in the dashboard
then just access the embedded stylesheet and change it up
glad we got it working bro
message has been deleted
p
brilliant! Thank you immensely. Now I have to explain to my little daughter why you took pole position on the test chatbot config over her cute pink deployment.
huge thanks!
w
you're always welcome!!! feel free to tag me with any further questions
3 Views