An embeddable JavaScript widget is a piece of code that can be integrated into different web applications to provide specific functionality. In the context of the Autoflow project (https://github.com/pingcap/autoflow/), the embeddable JavaScript widget is used to enable conversational search capabilities.
The Autoflow project utilizes various key technologies and dependencies, including TiDB, LlamaIndex, DSPy, Next.js, shadcn/ui, Redis, FastAPI, Nginx, Supervisor, JSON-file, and others. The Dockerfile exposes Port 3000.
The widget interacts with the backend system to provide conversational search capabilities through the use of APIs and data transmission between the frontend and backend.
There are several options for integrating the embeddable JavaScript widget into web applications:
- Iframe Embedding: This method involves embedding the widget within an iframe, allowing it to be integrated into various web applications. The following example demonstrates iframe embedding:
<iframe src="https://your-autoflow-widget-url.com" width="300" height="200" frameborder="0" scrolling="no"></iframe>
Source: How to embed Twine stories in WordPress
- WordPress Plugin: A WordPress plugin can be developed to simplify the integration process. This plugin would handle the embedding process, making it easier for WordPress users to implement the widget. Here’s an example of a WordPress plugin that embeds the widget:
function embed_twine_shortcode($atts) {
$atts = shortcode_atts(
array(
'story' => '',
'aheight' => '500',
'autoscroll' => 'true',
'ascroll' => 100,
),
$atts,
'embed_twine'
);
$content = embed_twine_buildParentPage($atts['story'], $atts['aheight'], $atts['autoscroll'], $atts['ascroll']);
return $content;
}
add_shortcode('embed_twine', 'embed_twine_shortcode');
Source: Embed Twine plugin for WordPress
- JavaScript Integration: The widget can also be integrated using JavaScript. This method involves adding a script tag to the web application’s HTML, which references the widget’s JavaScript file. Here’s an example of JavaScript integration:
<html>
<head>
<script src="https://your-autoflow-widget-url.com/widget.js"></script>
</head>
<body>
<!-- Widget container -->
<div id="autoflow-widget-container"></div>
<!-- Initialize the widget -->
<script>
window.onload = function() {
AutoflowWidget.init({
container: 'autoflow-widget-container',
story: 'your-story-url',
aheight: '500',
autoscroll: true,
ascroll: 100,
});
};
</script>
</body>
</html>
These are some of the possible options for integrating the embeddable JavaScript widget into web applications. The choice of integration method depends on the specific requirements and constraints of the target web application.