Embedding In Websites
Dify Apps can be embedded in websites using an iframe. This allows you to integrate your Dify App into your website, blog, or any other web page.
When use Dify Chatbot Bubble Button embed in your website, you can customize the button style, position, and other settings.
Customizing the Dify Chatbot Bubble Button
The Dify Chatbot Bubble Button can be customized through the following configuration options:
window.difyChatbotConfig = {
// Required, automatically generated by Dify
token: 'YOUR_TOKEN',
// Optional, default is false
isDev: false,
// Optional, when isDev is true, default is 'https://dev.udify.app', otherwise default is 'https://udify.app'
baseUrl: 'YOUR_BASE_URL',
// Optional, It can accept any valid HTMLElement attribute other than `id`, such as `style`, `className`, etc
containerProps: {},
// Optional, If or not the button is allowed to be dragged, default is `false`
draggable: false,
// Optional, The axis along which the button is allowed to be dragged, default is `both`, can be `x`, `y`, `both`
dragAxis: 'both',
// Optional, An object of system variables that set in the dify chatbot
systemVariables: {
// key is the system variable name
// e.g.
// user_id: "YOU CAN DEFINE USER ID HERE",
// conversation_id: "YOU CAN DEFINE CONVERSATION ID HERE, IT MUST BE A VALID UUID"
},
// Optional, An object of inputs that set in the dify chatbot
inputs: {
// key is the variable name
// e.g.
// name: "NAME"
}
}Overriding Default Button Styles
You can override the default button style using CSS variables or the containerProps option. Apply these methods based on CSS specificity to achieve your desired customizations.
1.Modifying CSS Variables
The following CSS variables are supported for customization:
To change the background color to #ABCDEF, add this CSS:
2.Using containerProps
containerPropsSet inline styles using the style attribute:
Apply CSS classes using the className attribute:
3. Passing inputs
inputsThere are four types of inputs supported:
text-input: Accepts any value. The input string will be truncated if its length exceeds the maximum allowed length.paragraph: Similar totext-input, it accepts any value and truncates the string if it's longer than the maximum length.number: Accepts a number or a numerical string. If a string is provided, it will be converted to a number using theNumberfunction.options: Accepts any value, provided it matches one of the pre-configured options.
Example configuration:
Note: When using the embed.js script to create an iframe, each input value will be processed—compressed using GZIP and encoded in base64—before being appended to the URL.
For example, the URL with processed input values will look like this: http://localhost/chatbot/{token}?name=H4sIAKUlmWYA%2FwWAIQ0AAACDsl7gLuiv2PQEUNAuqQUAAAA%3D
Last updated