https://discord.gg/botpress logo
Is it possible to start a botpress conversation us...
# 🤝help
m
I want to call the botpress webhook when a form is submitted on my site and start a conversation (send a message to the user via the twilio integration). Is this possible? Or do I need to start a conversation first, then send its ID to my webhook, then call the botpress webhook with the relevant data?
l
Which Twillo integration
m
SMS one.
l
You can - you need keep one conversationId consistent that will you send along with the webhook from the form, when submitted. Attach a standard node originating from webhook trigger. then use an execute code card in which first to assign the conversationId to event.conversationID. Say event.payload.conversationid has the conversationdId then followed by event.conversationId = event.payload.conversationId (this will totally depend on how are sending the payload) const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; const authToken = 'your_auth_token'; const twilioNumber = '+15017122661'; const recipientNumber = '+15558675310'; const url = `https://api.twilio.com/2010-04-01/Accounts/${accountSid}/Messages.json`; const data = qs.stringify({ Body: 'Hello from Axios!', From: twilioNumber, To: recipientNumber }); const config = { auth: { username: accountSid, password: authToken }, headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }; axios.post(url, data, config) .then(response => { console.log('Message SID:', response.data.sid); console.log('Status:', response.data.status); }) .catch(error => { console.error('Error:', error.response ? error.response.data : error.message); });
m
And if I want to direct the conversation to the main autonomous node after receiving the webhook with conversationId?
l
this is tricky and depends if the user has ever interacted with your bot via SMS. If Yes (you should track the user and their conversationId) - in this case instead of sending a generic conversationId, you can pass the correct one and then connect it to the autonomous node If No - connecting it to the autonomous node wont help as the replies from the autonomous node will be received to the number which is tagged to the generic conversationId you passed, defeating the purpose
If No - when the user responds it will start the conversation from the Start Node and not the trigger node
m
Thank you for the detailed reply. So initiating a conversation via a website isn't feasible. Maybe something like.. when the user submits a form, send the user an SMS from our twilio number via API. When the user replies to that message, our bot starts convo. Maybe then send data to the bot or something.
l
Yes - it is not that is impossible to achieve, just that the bot needs to know if a text was sent to the user and if yes what was it - with that context it can start the conversation when the user replies to text
w
@limited-pencil-78283 I have a similar, but not identical, question -- in short, I have a web page with the botpress widget, and I'd like to both open a bot chat and send a webhook, when the user clicks a certain link. However, I cannot figure out how to get the
conversationId
and make it available to client-side JS (for the purpose of sending a webhook), before the first message is sent by the user to the bot. I've read the docs and watched the YouTube tutorial, but neither addresses this specifically. Is it possible to programmatically access
conversationId
before the first message is sent, and if so, how?
l
This is a bit tricky, since conversationId is not generated without a conversation. If you want to make a webhook call while opening the chat window on a link click, you will have to look at the session variable stored in application storage of your browser. If the browser has stored it and you know how to access it, you will have the conversation id for your conversation.
4 Views