Site icon BotFlo

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):

Exit mobile version