A tiny JavaScript framework with powerful triggers, automatic unit conversion, dictionary lookups, and personality through random responses.
Simple API. Powerful behavior. Zero dependencies.
Match messages with powerful patterns. Use strings or arrays of patterns that share the same response. Full regex support included.
Add idle chatter and personality. Bot occasionally sends random phrases when no trigger matches (configurable chance).
Automatically detects temperatures, speeds, and distances in messages and replies with converted values (°F↔°C, mph↔km/h, miles↔km).
Users type define [word] and instantly receive definitions with part of speech and usage examples from a free public API.
Automatically retrieves local weather data based on the client IP when prompted.
Two ways to integrate. Both are production ready.
Fastest setup. Always up to date.
Add the bot framework to your website
<script src="https://iframe.chat/scripts/bot.js"></script>
Place it before your custom bot configuration script. The Bot constructor will be globally available.
Host the file yourself for complete control.
Download the exact source used by the hotlink:
Works great with any static hosting or even as an inline script.
Bot instance in a following <script> tag.
The bot will automatically attach to the Chattable Library's message events.
Create bots with just a few lines of code.
const myBot = new Bot("HelperBot", {
autoConvertUnits: true, // Enable automatic °F/°C, mph/kmh, miles/km conversion
dictionary: true, // Enable "define word" responses
weather: true, // Enable automatic local weather responses
chance: 10 // Set how often you want your bot to use it's random phrases (0-100)% default is always 10
});
The first argument is the display name shown when the bot sends messages. Options are optional but recommended.
// Single pattern
myBot.trigger("help", "Try saying hi, your current temp, define ephemeral, or ask about the weather...");
// Multiple patterns sharing the same response(s)
myBot.trigger(["hello", "hi", "hey", "sup"], [ // triggers are not case sensitive
"Hello $NAME! How can I help you today?",
"Hi $NAME!",
"Welcome, $NAME"
]);
// Regex power is fully supported
myBot.trigger("joke|funny", "Why did the developer go broke? Because he used up all his cache!"); //Regex autoflags 'igm'
$NAME is automatically replaced with the current user's name from Chattable in all bot outputs.
// Single phrase
myBot.random("Did you know I can convert units automatically?");
// Multiple phrases (one is chosen at random)
myBot.random([
"Having a good day so far?",
"Feel free to ask me to define any word!",
"Type 'define serendipity' to see what I can do."
]);
Random phrases are sent occasionally (roughly 1 in 10 messages) when no trigger matches.
Once instantiated, your bot is live and listening. No need to call any start method. It hooks into chattable.on("message", ...) automatically.
Type messages below to see triggers, unit conversion, dictionary, and random responses in action.
Triggers are evaluated in the order you register them. Put more specific patterns before general ones.
Patterns are turned into new RegExp(pattern, "igm"). Escape special characters if you want literal matches.
It gets replaced with chattable.user.name automatically in both trigger responses and random phrases.
Even if a trigger replies, unit conversion (if enabled) will still analyze the user's message and may send an extra message.
By design, the bot only processes messages where data.uid === chattable.user.uid. This prevents it from replying to everyone in a shared room.
Running a bot that spams the server can result in an automated temporary IP ban. Be courteous when scripting your bots.