Welcome to Hands for Bots, a powerful JavaScript library for crafting hybrid conversational user interfaces, which unites conversational, graphical and other components. This guide will walk you through the essentials of setting up and using Hands for Bots in your web projects.
Hands for Bots simplifies the process of integrating conversational interfaces with minimal configuration. All quick start options activates function calls plugin. Let's dive into some quick start examples:
This example sets up a text-based chatbot using RASA as the back-end conversational engine:
import Bot from "./handsforbots/Bot.js";
let bot_settings = {
quick_start: "text",
engine: "rasa",
language: "en-US",
engine_endpoint: "http://localhost/rasa/webhooks/rest/webhook",
};
const bot = new Bot(bot_settings);
Explanation:
-
quick_start: "text"
: This option instructs Hands for Bots to automatically include the core text input and output plugins, creating a basic text chat interface. -
engine: "rasa"
: Specifies RASA as the backend engine. -
language: "en-US"
: Sets the language for the chatbot interface. This is not about the language on back end assistants. -
engine_endpoint
: In this example, the URL of your RASA server's REST webhook endpoint.
Here's how you can create a voice-enabled chatbot using RASA:
import Bot from "./handsforbots/Bot.js";
let bot_settings = {
quick_start: "voice",
engine: "rasa",
language: "en-US",
engine_endpoint: "http://localhost/rasa/webhooks/rest/webhook",
};
const bot = new Bot(bot_settings);
Explanation:
-
quick_start: "voice"
: Hands for Bots automatically includes the core voice input and output plugins. -
The rest of the settings are identical to the text chatbot example.
To combine both text and voice capabilities:
import Bot from "./handsforbots/Bot.js";
let bot_settings = {
quick_start: "text_and_voice",
engine: "rasa",
language: "en-US",
engine_endpoint: "http://localhost/rasa/webhooks/rest/webhook",
};
const bot = new Bot(bot_settings);
Explanation:
quick_start: "text_and_voice"
: Hands for Bots will include both the text and voice plugins, providing a comprehensive CUI.
Remember to adjust the language
and engine_endpoint
to match your setup. You can explore more advanced configurations and customization options in the Development section of the documentation.
Hands for Bots empowers your chatbot to interact directly with your web application through custom commands or function calls. This allows for a wide range of actions, such as:
-
Navigating within your website
-
Displaying image galleries
-
Setting markers on a map
-
Triggering animations
Important: You don't need to tightly integrate these functions with the Hands for Bots core. The library provides a simple mechanism for calling them.
To invoke a custom function, you'll need to structure the command as a JSON object within the chatbot's response. Here's the general format:
For standard JavaScript functions:
{
"action": "FunctionName", // Function name only
"params": ["param1", "param2", {"param3": "value"}] // Array of parameters (optional)
}
For methods of Hands for Bots plugins:
{
"action": "ClassName.MethodName", // Plugin's class and method name
"params": ["param1", "param2", {"param3": "value"}] // Array of parameters (optional)
}
Note:
- The
params
array is optional. You can pass a single parameter (string, object, etc.) or omit it entirely if the function doesn't require arguments.
To trigger the custom command, include the JSON object, enclosed within the special delimiters [•
(open) and •]
(close), at the end of the chatbot's text response.
Example for RASA (domain.yml):
responses:
utter_open_gallery:
- text: "Here's our gallery: [•{'action': 'displayGallery', 'params': ['summer-collection']}•]"
utter_set_marker:
- text: "Marking your location on the map... [•{'action': 'MapPlugin.setMarker', 'params': {'lat': 40.7128, 'lng': -74.0060}}•]"
// Example function to display an image gallery
function displayGallery(collectionName) {
// Logic to fetch and display images based on the collection name
console.log(`Displaying gallery for: ${collectionName}`);
}
// ... (Hands for Bots initialization code) ...
let bot_settings = {
// ... (your settings) ...
};
const bot = new Bot(bot_settings);
When the RASA chatbot sends the response utter_open_gallery
, Hands for Bots will extract the JSON command and call the displayGallery
function, passing "summer-collection" as the parameter.
Let's say you have a custom "MapPlugin" with a setMarker
method:
// In Plugins/Output/MapPlugin/MapPlugin.js
export default class MapPlugin {
// ... (other plugin code) ...
setMarker(coordinates) {
// Logic to set a marker on the map using the provided coordinates
console.log(`Setting marker at:`, coordinates);
}
}
The response utter_set_marker
in your RASA domain.yml will invoke the setMarker
method of the MapPlugin
.
If you're eager to get your hands dirty with Hands for Bots, our Docker playgrounds provide a ready-made environment for experimentation.
-
Download the repository: https://github.com/alexlana/handsforbots
-
Navigate to the examples directory: Using your terminal, enter the
./handsforbots/examples/
folder. -
Start the Docker containers: Run
docker-compose up -d
to start the necessary services (RASA, Vite, etc.). -
Access the playground: Open http://localhost/ in your browser.
-
You can modify the Hands for Bots code in the
./handsforbots/
directory. -
The Vite development server serves the front-end code from
./examples/vite/
. -
The RASA project is located in
./examples/rasa/
.
To update your chatbot with changes to your RASA project, follow these steps:
-
Access the RASA container: Run
docker exec -it t4b-bot sh
to open a shell within the container. -
Train your model: Inside the container, execute
rasa train
to retrain the RASA model. -
Exit the container: Type
exit
to leave the container shell. -
Restart the RASA container: Run
docker rm -f t4b-bot
followed bydocker-compose up -d
to restart the RASA container with the updated model.
Your trained model will be saved outside the Docker container in the ./examples/rasa/models/
directory.
When you're done with the playground, stop the containers using:
-
docker rm -f t4b-duckling
-
docker rm -f t4b-actions
-
docker rm -f t4b-bot
-
docker rm -f t4b-vite
-
docker rm -f t4b-webserver
Important: This playground setup is intended for local development and experimentation. Do not use it for production deployments.
Let's move on to understanding the core components and plugin system of Hands for Bots in the Development guide.