Home / DialogFlow ES / Get your DialogFlow agent to initiate the conversation before user types a message
DialogFlow ES | REST API

Get your DialogFlow agent to initiate the conversation before user types a message

First published: Aug 2017 | Last Updated: May 2022

So let us understand the question:

When you work with Dialogflow you notice that it follows the “user types something -> agent replies with an answer” sequence. Suppose you wish to get the agent to say something before the user types anything, how do you do it?


In the example bot, the message appears in the chat window BEFORE the user types a message

In my CourseBot (seen above), I initiate the conversation by using the same ideas described on this page.

Dialogflow Built In Welcome Events

When you click inside the Event textbox in Dialogflow, you will notice in the autocomplete a bunch of CHANNEL_WELCOME events.

As you type out the word WELCOME, Dialogflow will autocomplete with the list of WELCOME events which are already available in Dialogflow (note: this might look different now when compared to when I created this GIF)

What are these welcome events?

In principle, this is the feature you should use to initiate conversations on different channels.

Take a look at this page in the documentation, for example:

Welcome events for different channel integrations

The reason I say “in principle”, is because I haven’t been able to successfully implement the bot automatically sending a message at the start of the conversation for some of the channels.

Here is a little report card.

The general WELCOME event: NO

So if you add the regular WELCOME event into an intent, will it fire the corresponding intent automatically in the 1-click web demo integration?

No, it doesn’t. More on this later in this article.

Google Assistant welcome event: YES

The GOOGLE_ASSISTANT_WELCOME event works as expected. In the Actions on Google simulator, you will notice that as soon as you type

“Talk to <my test app>”

If you have an intent marked as GOOGLE_ASSISTANT_WELCOME, the response in that intent will automatically show up in your simulator.

Slack welcome event: NO

I also tried the Slack welcome event, and couldn’t get the conversation to start automatically.

Telegram welcome event: YES

So this is a bit more nuanced, because in Telegram there isn’t a button which says “Start chatting with this bot” (to the best of my knowledge), so you actually need to type the keyword /start. When you do that, the corresponding TELEGRAM_WELCOME event fires, and the intent’s response comes back as expected.

Other Channels

Here is the remaining list. I couldn’t get the FB Messenger welcome event to work either, but reading up stuff online tells me others have successfully managed it, so its quite possible I did something wrong here.

If you have tried it out, and would like to help me fill this out, please leave a comment under the post (plus any additional tips to get them to work, if you know of them).



FACEBOOK_WELCOME: (According to Eduardo’s comment below, it can be done by following the instructions on Facebook’s documentation. Check the link in the comment)



Using a custom integration

However, when you start building out custom integrations (that is, you don’t use the 1-click integration from the Dialogflow console, but rather use the REST API to put together your own integration), you will be able to not only initiate the conversation with the user on any channel, but you can also get many other benefits. I have listed these benefits here.

Example of a custom integration initiating the conversation

In my custom website chatbot (I have now removed it from my website), I initiate the conversation with the user.

But this is only possible because I use a custom integration, and the system works as below:

(Note that the above image shows the overall custom website bot’s architecture. In the case of initiating the conversation, you need to send a message to the user before step 1, just as the chat window loads)

Push notifications

Another somewhat related question is sending push notifications in Dialogflow. A push notification is an “out-of-band” message sent by your agent to the user.

Since you can only respond when a request comes through, implementing push notifications in Dialogflow is also not supported natively.

So if you need to send push notifications, you need to follow the system described in this post.

Can you initiate the conversation from the webhook?

Since the webhook code is only executed after an intent triggers, and an intent (usually) triggers only when user sends a message to your Dialogflow agent, it follows that you cannot initiate the conversation from your webhook code.

A couple of things to note here:

  • you CAN use the webhook code to trigger an event using a feature called followup events, but you can’t use it to initiate a conversation because there is nothing to trigger the webhook code in the first place (I am simplifying it a bit here, but the takeaway is that it cannot be done as of this writing)
  • the custom integration code that I have described earlier resides outside of your Dialogflow agent while the webhook resides inside (or as part of) your Dialogflow agent – at least, that’s a good way to visualize it. So using custom integration code to initiate the conversation isn’t the same thing as using webhook to initiate a conversation.

An Example: Dialogflow Messenger

The Dialogflow Messenger integration allows you to add a chatbot to your website.

The interesting thing about the Dialogflow Messenger is that it can not only initiate the chat, but you can customize it so that it shows a different message on different pages of your website.

I will explain how in the rest of this article.

We start by creating a new Dialogflow ES agent.

Here is what the Default Welcome Intent looks like. Notice that it already has the Welcome event.

Now we will create a new intent called course-welcome. Add an event called course-welcome into the intent.

Then we will add another intent called app-welcome. The event for this intent is app-welcome.

By using these event names in the “intent” parameter of the Dialogflow Messenger embed code, we can trigger these three different intents, and corresponding show three different chat prompts based on user context.

This is the default embed code for the Dialogflow Messenger. Notice that it includes the Welcome event by default.

Now let us use different versions of the embed code in different pages. I simulate this by creating a dummy website with three pages on my local computer.

You can see the output of the different HTML files

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
<body style="background-color: lightgray">
<script src="https://www.gstatic.com/dialogflow-console/fast/messenger/bootstrap.js?v=1"></script>
welcome.html chat prompt
<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
<body style="background-color: lightgray">
<script src="https://www.gstatic.com/dialogflow-console/fast/messenger/bootstrap.js?v=1"></script>
course.html chat prompt
<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
<body style="background-color: lightgray">
<script src="https://www.gstatic.com/dialogflow-console/fast/messenger/bootstrap.js?v=1"></script>
app.html chat prompt

<— End of article —>

This website contains affiliate links. See the disclosure page for more details. 
Check out the Learn Dialogflow ES and Learn Dialogflow CX courses if you would like to learn Dialogflow in depth.
"The magic key I needed as a non-programmer"

The custom payload generator was the magic key I needed (as a non-programmer) to build a good demo with rich responses in DialogFlow Messenger. I've only used it for 30 minutes and am thrilled. I've spent hours trying to figure out some of the intricacies of DialogFlow on my own. Over and over, I kept coming back to Aravind's tutorials available on-line. I trust the other functionalities I learn to use in the app will save me additional time and heartburn.

- Kathleen R
Cofounder, gathrHealth

Similar Posts

  • Hi,
    I have a question pls, How can I send a value from another app to my dialogflow agent. it’s urgent, Please.

    • Dialogflow does not support out of band push notifications like what you are trying to do. The agent has to initiate the communication if it wants to receive a response.

  • Hey,
    I have integerated dailogflow with servicenow. and I have made a voice assistant android app which is connected to dailogflow. Can you tell me how can i do user authentication. (I don’t want to do it with gmail. I want to do it with servicenow username & pass). Thanks in Advance

  • I am able to test Facebook welcome event. I have created separate intent by name Welcome_Event and added ‘Facebook Welcome’ event and added text response for ‘Facebook Messenger’ channel. Now if i click on ‘Get Started’ button in Facebook messenger I can see the ‘Welcome_Event’ intent getting fired and correct welcome message!

  • Can DialogFlow initiate a message to any user (in particular, in telegrams) on some Action (for example, send a reminder by time)? In the documentation, it seems to be described as https://dialogflow.com/docs/events/custom-events. I tried using different (via POST request or WebHook) methods, but I only get the response to ACTION in the response to the request: detectIntent, although I specify same session on which the telegram user is connected. But the user does not receive anything in the telegrams on the event, no message. Why?

  • Hi Arvind,
    How can i send value in fulfilment and use globally for all function in fulfilment .is there any way to send value in fulfilment when chatbot button is click.Please suggest if any node js example exist please let me know.

    • That would be an entire course. If this is very urgent, you can get in touch via my contact form for paid 1-on-1 Skype consultation.

  • Hi Aravind,

    Hope you are doing good.
    I’m working on creating a chatbot using Dialogflow and FB messenger integration, wherein I have a requirement to get a picture as response from user and I need to save this picture.
    Can you suggest how this can be achieved?

  • Hi Arvind,
    I want to use integrated web demo iframe. Is there any way, in which i can pass the user name and password silently and authenticate it with the help of webhook and then fetch the profile and fetch the name and it should appeare when looged-in user open the chatpot – “Hi Ankur”

  • Aravind, this works perfectly for me, but I don’t understand how to use the API response.
    Would the response text be displayed somewhere automatically ? How and where are we supposed to print the text in our application (say, Web demo of DialogFlow)

    • You need to build out your own chat UI for a website chatbot. Dialogflow’s built in web demo integration doesn’t support this. As for other channels like FB and Slack, you will need to do build out a custom integration and also figure out how to use their APIs to push messages into the chat window. You can expect it to be quite a bit of work.

  • Hi, i try this in postman and i get the json response. But is there a way to see how i get the message from the bot in real time once i call this intent through the event?

    • It is quite reasonable to assume the response via Postman will be exactly the same that comes back if you were to use it inside your actual app. I would recommend building out the API call in the programming language of your choice, and look at the response object coming back. It will have the intent response (and all the associated info) and you can proceed to your next step.

  • Hi, Aravind! If I got it right, we have no options how to write to a FB or Telegram user without user’s request. However, it depends on using one-click integration. If I use custom integration with Telegram, FB Messenger – I can use events(as push notifications) only by:
    1. Generating and using SessionId.
    2. Having SenderId.
    How do you think – is it enough?

    • In theory, that is correct. I know for sure that it works for website chatbots, where I have direct experience. I am not sure if there are many people who have actually accomplished push notifications from Dialogflow to Telegram, FB Messenger etc. Be sure to read this article. Also ask on StackOverflow to verify if your approach will work (although I think you are on the right track). Finally, if you do get it working, please leave a comment below. I think many people might come to you for help at that point. 🙂

    • Hi Kirill…I am a student in Spain trying to develop a bot using Dialogflow, Firebase and Telegram. I have been trying for a while to get my Telegram bot to initiate a conversation periodically if the user doesn’t do so for a few days, do you know if this is possible? if so, could you please help me? I am desperate

    • You need to generate your own sessionID, and then (depending on your goal) make sure you use the same sessionID for a given session when interacting with the REST API.

  • Hello, I saw in your previous answer to Jon you highlighted there is no Push Notification concept in Dialogflow. In this case, can you kindly suggest me how I can exploit this feature with a Google Home device?
    Thanks in advance for your help.

      • Hello Aravind, thanks a lot for your prompt response.
        I think the new “notifications” feature won’t be usefull for my specifc purpose.

        Anyhow my previous question was intended about: how I can exploit the feature related to run an intent by invoking relevant “event” through call REST api (as per your example here above … “https://api.api.ai/v1/query?v=20150910&e=event_name&timezone=Europe/Paris
        &lang=en&sessionId=1234567890”) in order to experience the final effect on a “screen-less” device as Google Home speaker ?
        Finally,since my agent has been migrated to V2 API, I kindly request you how to submit the equivalent HTTP Rest invokation above with API V2 version (or if it is really needed…)

        Thanks again for your patience and I’m sorry for my bad english and for the previous misunderstanding.

  • Hi, I want to notify user that ‘user typing…’ before response displays in Dialogflow chatbot. Is it possible to implement using dialogflow event? Or any other way we can do it?

  • Great article. I’ve been looking for this capability for years! Is there a way you could use IFTTT to trigger the Event? For example if I unlocked my door using a smart lock that could send an IFTTT message could this trigger the event?

    • One important thing to remember when you do this is that the “response” from Dialogflow (that is, whatever is in the Response field inside the specific intent) will automatically be sent back to the requesting app. That is, there isn’t any concept of “push notifications” in Dialogflow. If you aren’t thinking of push notifications, then it will work OK.

    • In theory, you should be able to set up a scheduled task which runs a script at a particular time. The task will call Dialogflow’s REST API and invoke the corresponding Event using the /query endpoint. Would that work for your use case?