Understanding BJS Commands
What are Commands?
Commands are the fundamental building blocks of every bot created on Bots.Business. A command is triggered when a user sends a specific keyword or message to your bot (e.g., /start or /help).
Command Components
Each command can have multiple components to define its behavior:
- name - The command name (e.g., /start)
- help - Help text describing the command
- aliases - Secondary names that trigger the same command
- answer - The response the bot sends
- keyboard - Custom keyboards for user interaction
- scenarios - Simple logic flows
Your First BJS Command
Here's a simple /start command example:
JAVASCRIPT
Bot.sendMessage("👋 Welcome to My First Bot!\n\nThis bot is powered by Bots.Business.\nUse /help to see available commands.");
Advanced Command Logic
For more complex functionality, you can use BJS (Bot JavaScript) to add logic to your commands:
JAVASCRIPT
// Store user information
User.setProperty("first_visit", Date.now());
// Conditional responses
var visitCount = User.getProperty("visit_count") || 0;
User.setProperty("visit_count", visitCount + 1);
if (visitCount === 0) {
Bot.sendMessage("Welcome first-time visitor!");
} else {
Bot.sendMessage("Welcome back! This is your " + (visitCount + 1) + " visit.");
}
📚 Source
This tutorial is based on the official Bots.Business Documentation. Visit their site for the most up-to-date information and advanced guides.