https://discord.gg/botpress logo
Setting webchat signing key for token verification
# 🤝help
b
I'm trying to start an existing conversation in the Webchat. In the window.botpress.init section I'm adding the conversationId and it also seems I need to provide userId and a userToken (though I can't find this documented anywhere). Something like this: window.botpress.init({ "botId": "", "conversationId": "", "user": { "userId": "", "userToken": "" }, ... }) Asking the docs bot, they say I need to set the webchatSigningKey in the dashboard. I can then use this secret along with the userId to sign a jwt which I'll pass in the init. The only thing is I cannot find anywhere to configure this secret in the dashboard... There are a load of webchat config options but they are mostly theme related. I've spent a while trying to find this and not been able to, however it's still possible I may have just missed it. Any help really appreciated! https://cdn.discordapp.com/attachments/1439994652286779452/1439995255033434167/image.png?ex=69441896&is=6942c716&hm=1d828186f2e866ef72083c232e63b904f5a4500173c1f0d3536581e586ba2d46&
The field doesn't seem to exist anywhere in these options ^
Neither is it anywhere here:
w
i'm fairly sure webchatSigningKey isn't a real thing
also, what do you mean by "start an existing conversation"? if you're accessing the chat through the same useragent as the last one, the conversation should continue normally
b
Basically, we're trying to pre-bake our bot conversations via the Chat API with some context details the bot needs to know when the user starts chats with it. So using the Chat API I'm fetching/creating a user, creating a conversation then sending the conversation a custom event that contains a payload of some context data. My hope is then that the user can at some point in the future chat with this bot, and all they need is the conversation Id and maybe some token. When I try to start an embeded chat providing the conversationId I get an error. When inspecting the error it's a 403 Forbidden with "You are not a participant of this conversation".
w
are you already using the chat api?
also, what front-end do you plan on using? the webchat, right?
b
Yes that part is working so far, I can provide a secret and then send jwt tokens
We're in the prototyping phase so I'm trying to work out the best option for this, so far the webchat seems ideal
w
the information you want to pre-bake, is it user-specific?
or is something the bot needs to know on every conversation
b
Yes, user-specific
w
then this'll probably help you a lot
b
Oh nice will give that a read, thanks
w
you can call `window.botpress.updateUser`to update the user data
which achieves the pre-baking you described
Copy code
js
window.botpress.on('webchat:initialized', () => {
  console.log('Webchat has been initialized. Loading user...');
  window.botpress.updateUser({
    data: {
      firstName: "james",
      lastName: "shelley",
      email: "james@shelley.com",
    },
  })
});
this snippet is an example you could use to update those variables when the webchat's initialized
b
Ok, but can I add any fields to the data object? We'll need quite a large object with custom fields
w
yes of course
then you just add a Get User Data block on your flow to get that payload with the custom fields
b
Ok cool. But to confirm, the method I outlined at the start isn't something that's possible currently? I can't init the bot using an already existing conversationId?
w
i don't use the webchat too often so i can't give you 100% certainty - but i can give you 90% that these types of actions are limited to the user scope instead of the conversation one
i'll take another look though
b
Nice ok thanks, and usually it uses user info from the userAgent to work out who's interacting with the bot?
w
i believe so
there may be a way to do what you initially described though it's a lot more handiwork
you could maybe try adding the new user to the existing conversation using the [addParticipant](https://www.botpress.com/docs/api-reference/chat-api/openapi/addParticipant) endpoint
another alternative (and what i do currently, which allows me to keep track of the users through channels) is to use the messagingAPI instead
when interacting with it, i get two sets of user and conversation ids - one for botpress, one for my internal use
so you can use those two combined with another identifier (like email or phone number) to match the user between platforms or conversations for example
b
oh interesting, is that a part of the Chat API, or separate?
w
the messagingAPI is separate - it's honestly 100x simpler than the chat api
no signing jwt tokens and stuff
you just have one endpoint for sending messages and one for receiving
b
ok will take a look and work out our options - thanks for your help!
w
you're welcome!! feel free to ping me with any other questions
2 Views