Home / DialogFlow / Dialogflow Messenger tutorial
DialogFlow | Website Bots

Dialogflow Messenger tutorial

In this tutorial, I explain how to add a chatbot to your website using the Dialogflow Messenger integration.

What we will be building

The video below shows what we will be building in this tutorial.

Embed the chat widget into your website

Embedding the chat widget into your website is straight-forward.

Create your Dialogflow agent

Create a new Dialogflow agent, and remove the Welcome event from the Default Welcome Intent.

Add a new intent into your agent with the following information (note that it includes the Welcome event).

Add the script to your web page

Once you create your welcome intent, go to the Integrations pane, and select the Dialogflow Messenger integration.

Now copy the script into your clipboard.

Paste the script you copied into the <head> tag of your HTML page.

If you have a WordPress website, you cannot add JavaScript like this directly into your webpage.

In that case, use a plugin like Insert Headers and Footers and add the script into the “Scripts in Header” section.

Test the integration

When you open the page in your browser, you will now see the chat widget at the bottom right of your web page.

Now click on the welcome message, and you should see the below.

HTML and CSS customizations

The big advantage of using the Dialogflow Messenger integration (instead of the 1-click web demo) is that it is possible to customize the behavior of the chat widget using HTML and CSS customizations. You can check out the different customizations available in the documentation, and I also go over them in more detail in the Dialogflow Messenger Quickstart course.

For example, change the chat-title in your script within the df-messenger tag to “Dialogflow Messenger Bot”.

When you open the page, you will see the new title in your chat window. If you don’t provide any value for the chat-title attribute, the name of the Dialogflow agent will be used as default.

Rich responses

By far, the biggest feature of the Dialogflow Messenger integration is its support for rich responses such as links and images and buttons.

Let us go over these rich responses one by one.

Description type

The description type allows you to add multiple lines of text under a heading.

Create an intent called show.description.type as below:

To see the result, type the appropriate phrase into the chat widget.

Info type

The info type is similar to the card in the Google Assistant rich response, and it supports an image, a title and some text below the title.

Create a new intent in your Dialogflow agent called show.info.type. The image URL points to an image on my website.

Now check the result in the chat widget. You should be able to click anywhere inside the Info response type and a new browser tab will open and navigate to Google.com

Image type

You can also display images inside the web chat window in the Dialogflow Messenger. However, the image auto-resizes to fit the width of the window, so small images get expanded and look distorted. Larger images generally look better.

Photo credit: Unsplash

Add a new intent called show.image.type in your Dialogflow agent as below.

Now test the response in the chat widget.

Button type

Buttons are a good way to add a link to some page on your website. I don’t recommend using the “event” parameter in the button type, and I explain why in the Dialogflow Messenger Quickstart course.

Create an intent called show.button.type as below.

Now test it in your chat widget.

Suggestion Chips

Suggestion chips are good choices for representing buttons in your Dialogflow chat widget. I don’t recommend using it for links, though, and I explain why in the Quickstart course.

Create an intent called show.suggestion.chip.type as below.

Now test it inside your chat widget.

List Response Type

The list response type is an interesting one.

Compared to the other rich responses, it is more complex to implement. But it also provides some benefits you don’t have in other rich responses. Specifically, if you need a “listbox” style input – where the presented value has to be different from the underlying key – it is your only choice.

You need to add a second intent into your agent with the event PARALLEL as below.

Remember that you already have an intent called df-messenger-welcome with another event – the Welcome event.

Now add another intent in your agent as below:

Now you can test it in your chat widget. When you click on the second list item, it will trigger the parallel universe intent.

Accordion Type

The accordion type displays collapsible information.

Add another intent to your Dialogflow agent as below.

Now test it in your chat widget.

Do you notice something unusual?

Yes, the Accordion supports HTML content! 🙂

Learn More

In my free Dialogflow Messenger Bots course, I explain everything covered here in video and also explain how to build the following types of bots (clicking on the link takes you to a demo of the chatbot):

Move to next intent based on user clicking a button

Decision Tree Bot

Quiz bot

Checklist bot

Interactive Learning Bot

Related Posts

  • Hey,

    I have created a web page using google sites and I want to know how to embed the JavaScript into my web page.

    Thank you

    • I haven’t used Google Sites till now. And to be quite honest, I don’t think it is such a great choice for hosting your website these days in any case. Have you considered using something like GitHub Pages, which is also free?

  • Hi,

    I followed the exact same steps mentioned above however unable to generate rich response. Is it because my json in fulfillment is incorrect?