How to use Dialogflow Messenger user-id

The user-id is one of the attributes you can use in Dialogflow Messenger HTML customization.

In this tutorial, I will explain how it works.

Suppose you want to associate a logged in user for your web app with a user ID, so that you can (for example) get details about their account.

First, add the user-id into the HTML script for the Dialogflow Messenger embed code.

Here is an example:

Of course, normally, you would fetch this user-id from the server based on the logged-in user, and add it as one of the attributes of the df-messenger tag. For example, if you are using Python Flask, you might have something like user-id = {{ user_id }} in a Jinja template, and you will pass the server side user_id to your render_template method.

Now, when your Dialogflow Messenger bot calls the webhook, you will find that the JSON sent to the webhook will look like this (I just saved the entire request JSON object to a file on my webhook server, and copied and pasted the JSON and redacted some IDs):

About this website

BotFlo1 was created by Aravind Mohanoor as a website which provided training and tools for non-programmers who were2 building Dialogflow chatbots.

This website has now expanded into other topics in Natural Language Processing, including the recent Large Language Models (GPT etc.) with a special focus on helping non-programmers identify and use the right tool for their specific NLP task.

1 BotFlo was previously called MiningBusinessData. That is why you see that name in many videos

2 And still are building Dialogflow chatbots. Dialogflow ES first evolved into Dialogflow CX, and Dialogflow CX itself evolved to add Generative AI features in mid-2023