https://discord.gg/botpress logo
I need auth token for this request but I
# 💻developers
c
I need auth token for this request but I am using botpress iframe embedding link so its not sending the http cookie
l
you still here?
c
yes
l
alright
i dont really understand where a proxy server gets involved
can you explain your approach? ill let you know if it would work
i assume you're new to botpress
c
no I am not new
i used before but this problem is first time
before i didnt have security mesaure for api
// Server-side code (e.g., Express.js) const express = require('express'); const axios = require('axios'); const app = express(); app.use(express.json()); app.post('/proxy-api', async (req, res) => { try { // Forward the request to the actual API endpoint const apiResponse = await axios({ method: req.body.method || 'GET', url: req.body.url, data: req.body.data, headers: { // Forward the authentication cookie Cookie: req.headers.cookie } }); // Send the API response back to the client res.json(apiResponse.data); } catch (error) { res.status(500).json({ error: 'An error occurred' }); } }); app.listen(3000, () => console.log('Proxy server running on port 3000'));
like this
its gptd but idk its correct or wrong
or it works or npt
l
oh so you want to bounce the cookie back to javascript using an endpoint hosted on the same domain as the cookie
c
yes
but again security issue will be there
l
well i mean
the user has the cookie already
if you send it over an event to the webchat its probably not a huge security issue if they expire daily
the cookie will be stored on botpress servers for the duration of that conversation
c
okay so I can go with this approach?
l
proobably
c
can u explain lil bit
like
what are the things or hld
how it should happen
l
you can set up a webchat event trigger in your bot
c
trigger
when chat starts
c
it triiger automatically
l
no, you would need to send a custom event
that contains the cookie as the payload
then extract it with an execute code card
im unsure what the botpress webchat client API is give me a min
what exactly are you embedding in the iframe
c
when we publicsh
we get a iframe
right
that one i am using
l
your app is react based?
dude, just use the react client
c
its next based
l
im not very familiar with web dev but im pretty sure it would still work
c
okay
l
anyway, if you want to stick to scripts
c
are u working in botpress
what shoul i do
l
check out these docs
loading these scripts should create
window.botpress
within your iframe
the sendEvent method lets you send arbitrary events to the bot
which you can then listen for using your trigger
c
that arbitary event should contain cookie am i right?
l
yeah
im not 100% sure that this will work
but its the best i got if you want to execute your API calls from botpress cloud
other solutions are more complicated
c
okay I wil look into that
thank u so much for help
l
i tested it out and it works
the data structure of incoming webchat triggers is a bit weird
but essentially what you want to do
is setup something like this
create a webchat custom trigger
set the filter to this
extract the cookie like so
to whatever variable you want
and you're good to go
now send the event:
hope this helps
c
can u please explain this
I want particularly what will
happen
once user open the chat
based on what that trigger will happen
3 Views