Pass form details to your bot
# đź“–tutorials
b
The website demo is available here: https://jsfiddle.net/GordyNumberOne/pysm1fg5 Let's simplify the tutorial for passing form details to a chatbot: Start by using the
custom payload
trigger instead of the usual
Conversation Start
trigger to initiate the chat when the form is submitted. To bring the trigger payload into your bot, use this code:
Copy code
jsx
const { name, email, linkedin, message, position } = event.payload.payload
Create a form on your website:
Copy code
html
<form id='myform'>
  <label for="name">Full Name:</label>
  <input type="text" id="name" name="name" required>
  <label for="email">Email:</label>
  <input type="email" id="email" name="email" required>
  <label for="linkedin">Linkedin URL:</label>
  <input type="text" id="linkedin" name="linkedin" required>
  <label for="message">Cover Letter/Message:</label>
  <textarea id="message" name="message" rows="7"></textarea>
  <button type="submit">Submit</button>
</form>
Embed your bot with this code, ensuring that the chat widget is hidden:
Copy code
html
<script>
  window.botpressWebChat.init({
    "composerPlaceholder": "Chat with bot",
    "botConversationDescription": "This chatbot was built with Botpress",
    "botId": "da359935-a341-4c1d-bc05-cbdbd10a5444",
    "hostUrl": "https://cdn.botpress.cloud/webchat/v1",
    "messagingUrl": "https://messaging.botpress.cloud",
    "clientId": "da359935-a341-4c1d-bc05-cbdbd10a5444",
    "lazySocket": true,
    "hideWidget": true,
    "useSessionStorage": true,
    "enableConversationDeletion": true,
    "showPoweredBy": true
  });
</script>
Use the form submission button to start the chat:
[SEE ATTACHED .txt FILE FOR CODE]
This code ensures that the bot widget is ready before sending the payload to the bot. Use
sendPayload
to match the bot's trigger for payloads. Now, you should be able to see the payload in the bot logs when everything works correctly. Happy bot building!
m
It happens so that yesterday as was working with this functionality. What I couldn't figure is if it's possible to see incomming trigger payloads in the Botpress studio. Documentation and some Youtube videos says that it's possible, but somehow I can't find how to do it.
@bumpy-butcher-41910 do you have a solution on how to deal with a situation when a chatbot is already in the state of waiting for "raw input", let's say from the previous conversation that hasn't ended? The problem with this situation seems to be that the bot is waiting for the raw input and you just send it a trigger payload and it doesn't (I assume) accept it and asks again in the chat for that raw input.
I know it's possible to initiate a new conversation, but is there a way to just end the current conversation and then send the trigger payload to the bot after the conversation ended?
f
@mammoth-lamp-91104 it is still in beta 🙂
Where is the trigger connected in your bot?
m
@famous-jewelry-85388 So I watched this video

https://youtube.com/watch?v=qLwe7C00xbg&t=346sâ–ľ

and in there logs have payloads that are incoming from the web. I personally don't see payloads in the logs and I can't figure out why is that. My setup is simple and it works as expected. I have custom trigger in a separate workflow. When I send the paylaod from web, it gets triggered and works as expected.
f
I am sorry, but can we move this discussion to #1111009377525186570 ? and mention me on it so we don't add information to the tutorial that is not related ot it?
j
im going to use this
thanks for the video !
hmmm
can you do this for changing a bots question towards a user ?
b
@jolly-policeman-82775
j
huh
@victorious-animal-91809