Getting user_id via chatbot iframe issue #12920

Closed
opened 2026-02-21 19:09:41 -05:00 by yindo · 6 comments
Owner

Originally created by @asrguru20 on GitHub (Apr 15, 2025).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

1.2.0

Cloud or Self Hosted

Cloud

Steps to reproduce

The user_id wont change if the user switches from none logged in to logged in or from a user to another user:

  • try to get the user_id variable via chatbot iframe embeded to a website and start a conersation
  • switch the user of the website and start new converstaion

this is also a bot reported in #17870 and https://github.com/langgenius/dify/pull/18035

✔️ Expected Behavior

if the user changes with new conversation the user id should also change

Actual Behavior

the user_id wont change if user changes

Originally created by @asrguru20 on GitHub (Apr 15, 2025). ### Self Checks - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [x] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version 1.2.0 ### Cloud or Self Hosted Cloud ### Steps to reproduce The user_id wont change if the user switches from none logged in to logged in or from a user to another user: - try to get the user_id variable via chatbot iframe embeded to a website and start a conersation - switch the user of the website and start new converstaion this is also a bot reported in [#17870 ](https://github.com/langgenius/dify/issues/17870) and https://github.com/langgenius/dify/pull/18035 ### ✔️ Expected Behavior if the user changes with new conversation the user id should also change ### ❌ Actual Behavior the user_id wont change if user changes
yindo added the 🐞 bugcloud labels 2026-02-21 19:09:41 -05:00
yindo closed this issue 2026-02-21 19:09:41 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Apr 15, 2025):

I found a similar unsolved discussion titled "Where do you get the user_id from?" which might be relevant to your issue [1].

To resolve the issue where the user_id does not update when switching users during a conversation in a chatbot iframe embedded on a website, ensure that both the user_id and conversation_id are obtained and passed correctly. When initializing the chatbot, use the chat-messages API endpoint to obtain these IDs together, as the iframe embedding generates a different user_id. You can pass dynamic parameters through the inputs field in the API request or the difyChatbotConfig object when using the iframe.

Example using the API request:

{
    "inputs": {"dynamic_param": "value"},
    "query": "Hello, how can I assist you?",
    "response_mode": "streaming",
    "conversation_id": "",
    "user": "abc-123"
}

Example using the difyChatbotConfig object:

window.difyChatbotConfig = {
    token: 'YOUR_TOKEN',
    inputs: {
        dynamic_param: 'value'
    }
};

Ensure that the user_id is updated correctly in these configurations when switching users [2].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

@dosubot[bot] commented on GitHub (Apr 15, 2025): <!-- Answer --> I found a similar unsolved discussion titled "Where do you get the user_id from?" which might be relevant to your issue <sup>[[1]](https://github.com/langgenius/dify/discussions/11138)</sup>. To resolve the issue where the `user_id` does not update when switching users during a conversation in a chatbot iframe embedded on a website, ensure that both the `user_id` and `conversation_id` are obtained and passed correctly. When initializing the chatbot, use the `chat-messages` API endpoint to obtain these IDs together, as the iframe embedding generates a different `user_id`. You can pass dynamic parameters through the `inputs` field in the API request or the `difyChatbotConfig` object when using the iframe. Example using the API request: ```json { "inputs": {"dynamic_param": "value"}, "query": "Hello, how can I assist you?", "response_mode": "streaming", "conversation_id": "", "user": "abc-123" } ``` Example using the `difyChatbotConfig` object: ```javascript window.difyChatbotConfig = { token: 'YOUR_TOKEN', inputs: { dynamic_param: 'value' } }; ``` Ensure that the `user_id` is updated correctly in these configurations when switching users <sup>[[2]](https://github.com/langgenius/dify/issues/14954)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.* --- <sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/16781314-7749-49d7-84d6-7dbc15e13850?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/16781314-7749-49d7-84d6-7dbc15e13850?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/16781314-7749-49d7-84d6-7dbc15e13850?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/16781314-7749-49d7-84d6-7dbc15e13850?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/16781314-7749-49d7-84d6-7dbc15e13850?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/16781314-7749-49d7-84d6-7dbc15e13850?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/16781314-7749-49d7-84d6-7dbc15e13850?feedback_type=other)</sup>
Author
Owner

@asrguru20 commented on GitHub (Apr 15, 2025):

I found a similar unsolved discussion titled "Where do you get the user_id from?" which might be relevant to your issue [1].

To resolve the issue where the user_id does not update when switching users during a conversation in a chatbot iframe embedded on a website, ensure that both the user_id and conversation_id are obtained and passed correctly. When initializing the chatbot, use the chat-messages API endpoint to obtain these IDs together, as the iframe embedding generates a different user_id. You can pass dynamic parameters through the inputs field in the API request or the difyChatbotConfig object when using the iframe.

Example using the API request:

{
"inputs": {"dynamic_param": "value"},
"query": "Hello, how can I assist you?",
"response_mode": "streaming",
"conversation_id": "",
"user": "abc-123"
}
Example using the difyChatbotConfig object:

window.difyChatbotConfig = {
token: 'YOUR_TOKEN',
inputs: {
dynamic_param: 'value'
}
};
Ensure that the user_id is updated correctly in these configurations when switching users [2].

To continue talking to Dosu, mention @dosu.

Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

I want to get user id from chatbot iframe embedded to my wordpress site via body tag:

<script> window.difyChatbotConfig = { token: 'CZCijLyaLL6RFV4X', baseUrl: 'http://****.**', systemVariables: { user_id: '2', }, } </script> <script src="http://ingpt.ir/embed.min.js" id="CZCijLyaLL6RFV4X" defer> </script> <style> #dify-chatbot-bubble-button { background-color: #1C64F2 !important; } #dify-chatbot-bubble-window { width: 24rem !important; height: 40rem !important; } </style>

can we use conersation_id in within chatbot iframe like:

systemVariables: {
user_id: '2',
conersation_id: '2'
},

@asrguru20 commented on GitHub (Apr 15, 2025): > I found a similar unsolved discussion titled "Where do you get the user_id from?" which might be relevant to your issue [[1]](https://github.com/langgenius/dify/discussions/11138). > > To resolve the issue where the `user_id` does not update when switching users during a conversation in a chatbot iframe embedded on a website, ensure that both the `user_id` and `conversation_id` are obtained and passed correctly. When initializing the chatbot, use the `chat-messages` API endpoint to obtain these IDs together, as the iframe embedding generates a different `user_id`. You can pass dynamic parameters through the `inputs` field in the API request or the `difyChatbotConfig` object when using the iframe. > > Example using the API request: > > { > "inputs": {"dynamic_param": "value"}, > "query": "Hello, how can I assist you?", > "response_mode": "streaming", > "conversation_id": "", > "user": "abc-123" > } > Example using the `difyChatbotConfig` object: > > window.difyChatbotConfig = { > token: 'YOUR_TOKEN', > inputs: { > dynamic_param: 'value' > } > }; > Ensure that the `user_id` is updated correctly in these configurations when switching users [[2]](https://github.com/langgenius/dify/issues/14954). > > _To continue talking to [Dosu](https://dosu.dev), mention [@dosu](https://github.com/dosu)._ > > Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/16781314-7749-49d7-84d6-7dbc15e13850?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/16781314-7749-49d7-84d6-7dbc15e13850?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/16781314-7749-49d7-84d6-7dbc15e13850?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/16781314-7749-49d7-84d6-7dbc15e13850?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/16781314-7749-49d7-84d6-7dbc15e13850?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/16781314-7749-49d7-84d6-7dbc15e13850?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/16781314-7749-49d7-84d6-7dbc15e13850?feedback_type=other) I want to get user id from chatbot iframe embedded to my wordpress site via body tag: <script> window.difyChatbotConfig = { token: 'CZCijLyaLL6RFV4X', baseUrl: 'http://****.**', systemVariables: { user_id: '2', }, } </script> <script src="http://ingpt.ir/embed.min.js" id="CZCijLyaLL6RFV4X" defer> </script> <style> #dify-chatbot-bubble-button { background-color: #1C64F2 !important; } #dify-chatbot-bubble-window { width: 24rem !important; height: 40rem !important; } </style> can we use conersation_id in within chatbot iframe like: systemVariables: { user_id: '2', conersation_id: '2' },
Author
Owner

@dosubot[bot] commented on GitHub (Apr 15, 2025):

To use conversation_id within the Dify chatbot iframe, you can include it in the systemVariables configuration. Here's how you can set both user_id and conversation_id:

<script>
 window.difyChatbotConfig = {
  token: 'CZCijLyaLL6RFV4X',
  baseUrl: 'http://****.**',
  systemVariables: {
   user_id: '2',
   conversation_id: '2'
  },
 }
</script>
<script
 src="http://ingpt.ir/embed.min.js"
 id="CZCijLyaLL6RFV4X"
 defer>
</script>
<style>
  #dify-chatbot-bubble-button {
    background-color: #1C64F2 !important;
  }
  #dify-chatbot-bubble-window {
    width: 24rem !important;
    height: 40rem !important;
  }
</style>

Make sure that the conversation_id is correctly managed and updated as needed, especially when switching users or starting new conversations. This setup should help in maintaining the correct session and user context within your WordPress site.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

@dosubot[bot] commented on GitHub (Apr 15, 2025): <!-- Answer --> To use `conversation_id` within the Dify chatbot iframe, you can include it in the `systemVariables` configuration. Here's how you can set both `user_id` and `conversation_id`: ```javascript <script> window.difyChatbotConfig = { token: 'CZCijLyaLL6RFV4X', baseUrl: 'http://****.**', systemVariables: { user_id: '2', conversation_id: '2' }, } </script> <script src="http://ingpt.ir/embed.min.js" id="CZCijLyaLL6RFV4X" defer> </script> <style> #dify-chatbot-bubble-button { background-color: #1C64F2 !important; } #dify-chatbot-bubble-window { width: 24rem !important; height: 40rem !important; } </style> ``` Make sure that the `conversation_id` is correctly managed and updated as needed, especially when switching users or starting new conversations. This setup should help in maintaining the correct session and user context within your WordPress site. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.* --- <sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/fbafdc82-ce09-45cc-87f0-c98e8e8e14a2?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/fbafdc82-ce09-45cc-87f0-c98e8e8e14a2?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/fbafdc82-ce09-45cc-87f0-c98e8e8e14a2?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/fbafdc82-ce09-45cc-87f0-c98e8e8e14a2?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/fbafdc82-ce09-45cc-87f0-c98e8e8e14a2?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/fbafdc82-ce09-45cc-87f0-c98e8e8e14a2?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/fbafdc82-ce09-45cc-87f0-c98e8e8e14a2?feedback_type=other)</sup>
Author
Owner

@crazywoola commented on GitHub (Apr 15, 2025):

Afaik, this PR https://github.com/langgenius/dify/pull/18035 intends to fix this problem.

@crazywoola commented on GitHub (Apr 15, 2025): Afaik, this PR https://github.com/langgenius/dify/pull/18035 intends to fix this problem.
Author
Owner

@amarczew commented on GitHub (Apr 24, 2025):

@crazywoola I just tested using the newest version (1.3.0) and this is not working yet. I send user_id and conversation_id, but chat is loaded as a new one. I also tested using a chat created after updating to newest version.

Do you have any ideas about possible issues?

@amarczew commented on GitHub (Apr 24, 2025): @crazywoola I just tested using the newest version (1.3.0) and this is not working yet. I send user_id and conversation_id, but chat is loaded as a new one. I also tested using a chat created after updating to newest version. Do you have any ideas about possible issues?
Author
Owner

@AlexSchouleur commented on GitHub (Nov 18, 2025):

Any update on this?

@AlexSchouleur commented on GitHub (Nov 18, 2025): Any update on this?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#12920