Is it possible to capture the current URL address ...
# 🤝help
s
What I Need To capture the current URL where the chatbot is embedded when chatting with user. Scenario A user clicks on an ad that directs the user to a website. The link embedded in this ad has UTM parameters. The Chatbot is embedded on the the website. The Chatbot captures the current URL to parse out the UTM parameters During the interaction with chatbot, the user provides their name and email. Subsequently, the chatbot sends both the lead data and the UTM parameters to the CRM. I'm assuming this code could be written into the HTML of the website but is there is a way to capture this type of channel information within botpress natively?
r
Good question. I tried adding parameters to window.botpressWebChat.init but either it didn't work or I just didn't figure out how to access those added parameters from inside the bot.
s
Learned it not currently possible. I posted a feature request if you want to upvote it there https://discord.com/channels/1108396290624213082/1133803997896134718
s
I want the same feature. @straight-wolf-37371 do you think we can use Botpress API so that front end can create a conversation and send an initial message with the url?
s
Hmmm.... Let me make sure I understand. You thinking something like this? 1. User lands on webpage with the bot 2. Some HTML code or something sends a message to chatbot through API as an initial message 3. Perhaps use a hook or execute or whatever you want to process the message and send the URL to wherever you need it to go
s
yeah something like that. If code in a webpage can send message to the specific conversation that the user is having.
s
@famous-zoo-73118 What do youi think about this?
f
That could be a good workaround for now, you could trigger the bot from your page's code and send in the trigger message some kind of internal code that identifies the website and that can be detected in the start node of your bot's flow and then do custom logic based on the code match.
~~For example:
Copy code
js
window.botpressWebChat.sendPayload({type:'text', text:"WS1"})
... where
WS1
is an internal code for your website. Then in the start node of your bot you can check if the incoming message matches one of the internal codes you define. Not the most elegant solution, but should work for now while this is not available as an official feature.~~ Please see my revised answer below for a better implementation of this solution: https://discord.com/channels/1108396290624213082/1133770315873398794/1136041731280863434
s
Oh there is a Webchat Trigger. Thanks for the example. I'll try it out!
ok so Trigger is in Beta. https://discord.com/channels/1108396290624213082/1121833577659768893 I requested an access.
f
event.payload.text === 'start'
Is this the right syntax to check in the botpress triggers to initiate the conversation?
f
Yes, you can use
event.payload.yourCustomAttribute
BTW, as a revision to my original answer, it will be better to use
.sendEvent()
as it won't appear as if the user sent a message. So, from the page the webchat is embedded on, you can call:
Copy code
js
window.botpressWebChat.sendEvent({ type:'trigger', websiteCode:"WS1" })
And then in your bot just add an Event > Message from channel card into your workflow, then in that card select the "Trigger" option from the "Trigger On" dropdown, and then connect a new node to that trigger and you can now use the
event.payload.websiteCode
variable to know which the code of the website your bot was opened on, so you could add an Execute Code card there with this code:
Copy code
js
session.websiteCode = event.payload.payload.websiteCode
And then anywhere in your bot you can simple use the
session.websiteCode
variable to know which website your bot is running on 🚀

https://cdn.discordapp.com/attachments/1133770315873398794/1136042350825701537/image.png

https://cdn.discordapp.com/attachments/1133770315873398794/1136045815673143337/image.png

e
Amazing @famous-zoo-73118 !!!
4 Views