Custom step

The Custom step shows a web page of your own inside the conversation and takes the step’s answer from it. Use it for any input the other step types do not offer: a product configurator, a color or size picker, a seat map, a signature pad. Anything you can build as a web page can answer the bot, with one line of JavaScript.

The page is shown in an inline frame in the bot. It works in the bot on your website and on the bot’s own page. The messaging channels (Messenger, WhatsApp, Telegram, Viber, Instagram and the others) cannot show a web page in the conversation, so a bot that runs there should use other step types.

Add the step

Add a step to your bot and choose Custom. Its settings, under Step settings:

  • URL: the address of your page, for example https://example.com/configurator. The visitor’s browser loads it, so it must be reachable from the internet, over https://. It can hold bot variables, for example https://example.com/configurator?email={{email}}, and it can differ per language of the bot.
  • Default value: a starting value for your page, optional. It is added to the URL as the parameter default, and it can hold variables too.
  • Hide the step, under Advanced settings: hides the step’s texts, responses and answer from the chat transcript.

Your page must allow being shown in a frame on another site. A page that sends X-Frame-Options: DENY or SAMEORIGIN, or a Content-Security-Policy whose frame-ancestors leaves out your website and the bot’s page, shows up empty. The same holds for the Fold-out step.

Answer the step from your page

When the visitor is done, your page sends the answer to the bot with postMessage to its parent window:

window.parent.postMessage(JSON.stringify({
  action: 'answer',
  data: { value: 'blue-m', text: 'Blue, size M' }
}), '*')
  • value: the answer’s value, what your own systems need (an id, a code, a JSON string).
  • text: the answer as people read it: in the conversation’s transcript, in the results and in emails.

The message must be a string, so send it through JSON.stringify: an object sent as it is gets ignored. The bot only accepts messages from the frame of its own Custom step, so another frame on the same page cannot answer it.

After the answer, the frame is marked as answered and the conversation goes on with the step’s next step. The visitor can press Redo on it to answer again.

Fit the frame to your page

The frame starts small. Your page can set its size, at any time and as often as it needs:

window.parent.postMessage(JSON.stringify({
  action: 'resize',
  data: { height: '500px' }
}), '*')

height and width take a CSS length ('500px', '100%'); send only the one you want to change.

Read the default value

The Default value, with its variables filled in, reaches your page as the default parameter of its address:

var defaultValue = new URL(window.location.href).searchParams.get('default')

A complete example

A page that shows the default value and answers with a button:

<!doctype html>
<html>
  <body>
    <p id="default"></p>
    <button onclick="answer('blue-m', 'Blue, size M')">Blue, size M</button>
    <script>
      var defaultValue = new URL(window.location.href).searchParams.get('default')
      document.getElementById('default').innerText = 'Default: ' + (defaultValue || 'none')

      function answer(value, text) {
        window.parent.postMessage(JSON.stringify({ action: 'answer', data: { value: value, text: text } }), '*')
      }

      window.parent.postMessage(JSON.stringify({ action: 'resize', data: { height: '200px' } }), '*')
    </script>
  </body>
</html>

Use the answer later

The answer is stored with the response like any other answer. Later steps, conditions and response actions use it through the step’s code name, as any bot variable:

  • {{custom}}: the answer’s text;
  • {{custom.value}}: the answer’s value.

Here custom stands for your Custom step’s code name. A chat text “You chose {{custom}} ({{custom.value}})” shows “You chose Blue, size M (blue-m)” after the example above.

Edit this page