optimistic-gold
optimistic-gold8mo ago

Voiceflow Snipet auto start?

I need some help regarding voiceflow snippet. My goal is to have a simple html with a text box and when i type something in it and hit enter, the voiceflow snippet should popup with the text from the textbox as a chat input. It works fine excpt that I should always click the 'start chat' button on the voiceflow widget to initiate it. Is there a way to automatically start the chat in the background ? Any parameter should be set in the snippet? Thanks all
No description
2 Replies
Tico | Voiceflow Assistant
You can automatically open the chat without requiring a user to click the “start chat” button. Once you load the Voiceflow chat widget, you can call the open() method to trigger the chat automatically. For example, you can update your snippet like this: -------------------------------------------------- <script type="text/javascript"> (function(d, t) { var v = d.createElement(t), s = d.getElementsByTagName(t)[0];
v.onload = function() { window.voiceflow.chat.load({ verify: { projectID: 'PROJECT_ID' }, url: 'https://general-runtime.voiceflow.com', versionID: 'production' }).then(() => { // Automatically open the chat after a brief delay (e.g., 1 second) setTimeout(function () { window.voiceflow.chat.open(); }, 1000); }); };
v.src = "https://cdn.voiceflow.com/widget/bundle.mjs"; v.type = "text/javascript"; s.parentNode.insertBefore(v, s); })(document, 'script'); </script> -------------------------------------------------- This code loads the widget and then, once it’s ready, it automatically opens the chat using window.voiceflow.chat.open(). You can adjust the timeout delay based on your needs. If you need to send text input from your text box directly to Voiceflow (without any additional actions afterward), after opening the chat you can use something like: -------------------------------------------------- window.voiceflow.chat.interact({ type: 'text', payload: { message: yourTypedText } }); -------------------------------------------------- For more details, you can check out the Web Chat API documentation. Hope this helps!
AyoEpic
AyoEpic4w ago
Thank you for this!

Did you find this page helpful?