Bots.Business - Help
  • Welcome
  • Getting started
  • Create bot from Google Table
  • App
    • Reset or Update Your Password
  • Commands
    • Answer
    • Aliases
    • Keyboard
    • Groups
    • Wait for answer
    • Auto Retry (AR)
  • Coding: BJS
    • Variables
    • Bot functions
    • Message broadcasting and editing
    • User functions
    • Properties
    • Always running commands
    • Error command: "!"
    • Lists
      • Migration from properties to list
    • Api functions
    • BB Admin functions
    • Admin Panel
    • Send HTTP request
    • Web App
    • Caching
    • Inline Bot
    • BJS Security
    • Good coding practices
    • Top errors
  • Git
    • Import bot from Git repository
    • Export bot to Git repository
    • Repository structure
    • File: bot.json
    • Automatic importing on Git push
  • Iterations. How to reduce theys?
  • Limitations
  • Cloud
  • Reports
  • Deep Linking - pass any params on Bot starting
  • How to link chat account with BB account?
  • BB Inspection
  • Protected bot
  • VS Code
  • How to...
  • Smart Bot
    • Overview
    • Lang File
    • SmartBot
    • SmartTasker
    • Amount Dialog
  • Libs
    • What it is - Libs?
    • Libs development
    • RefferalLib
    • ResourcesLib
    • Random
    • MembershipChecker (MCL)
    • Cooldown Lib
    • CurrencyConverter
    • Lang
    • TopBoardLib
    • QiwiPayments
    • Coinbase (CB)
    • CoinPayments (CP)
    • OxaPay
    • CryptoJS
    • CurrencyQuote
    • GoogleApp
    • GoogleTableSync
    • Guard
    • Webhooks lib
    • DateTimeFormat Lib
  • Store
    • BB Point Bot
    • Welcome bot
    • Help bot
    • SRB Demo Keyboard Tools
Powered by GitBook
On this page
  • Introduction
  • Setup
  • Creating an Instance of SmartBot
  • Handling Commands
  • Adding Params
  • is Alias method
  • Filling Content
  • Change language for user
  • Debugging
  • Best Practices
  • Conclusion

Was this helpful?

  1. Smart Bot

SmartBot

PreviousLang FileNextSmartTasker

Last updated 17 days ago

Was this helpful?

Introduction

SmartBot is a versatile tool designed to enhance bot interaction and management, particularly for multi-language support. This guide focuses on setting up and initializing SmartBot for your projects, ensuring a smooth start for beginners in programming.

We have bot demo: - free available in the Store.

Setup

You need setup Lang File. Please read

Creating an Instance of SmartBot

To use SmartBot, you first need to create an instance. This is typically done in the main bot file or where you handle your bot's logic.

Syntax:

let smartBot = new SmartBot(options);

You need to put this code:

  • in command - "@"

  • and create blank (because we need to track all commands we need blank "*" command)

Options:

  • params: Initial parameters for the bot.

  • defaultMarkdown: The default formatting style for messages (e.g., Markdown, HTML).

  • skip_cmd_folders: Don't process commands in this folders (it can be "Setup", "Admin" folders for example)

  • strict_params: Default - false. If true - error will be thrown if param not found but it is needed in Command's. It is good for debugging.

  • debug: A boolean flag for enabling debugging. Default: false.

Example:

let smartBot = new SmartBot({
  params: {
    balance: 0,
    name: user.first_name
  }
});

Handling Commands

SmartBot manages commands based on the language file. Use the handle method to process incoming commands and generate appropriate responses.

Example:

// command "@@"
smartBot.handle();

Adding Params

One of SmartBot's key features is its ability to handle dynamic content through variables.

Use the add method to include dynamic content in responses:

smartBot.add({ username: user.name, balance: user.balance });

// or it can be "set" method
// but with this method all another props will be deleted
// smartBot.set({ username: user.name, balance: user.balance });
...
// "/balance" commands
"/balance": {
   text: "Hello, {username}. Your balance: {balance}"
}
...

Params from options after SmartBot.run (or Bot.run) - are added automatically

Running other Command

Use the run method to execute another command within a command:

smartBot.run({
  command: "/anotherCommand"
});

// if you want edit mode:
smartBot.run({
  command: "/anotherCommand edit"
});

It is same method like Bot.run but current options will be passed automatically

is Alias method

let isAlias = smartBot.isAlias(message);

if(isAlias){
  // for example we can have alias "Cancel", "Exit" on button
  // so we just make exit from command
  return
}

// other code

Filling Content

The fill method replaces all vars like "{data}" in text with actual variable values:

let response = smartBot.fill("Hello, {username}, your balance is {balance}");

As a rule, there is no need to use this method - everything should happen automatically

You can use titles from Lang file like:

smartBot.fill(smartBot.params.YOUR_KEY_FROM_TITLES) It is possible because title was added as param

Change language for user

You can change language for user via this code:

// change user language to "en"
smartBot.setUserLang("en");
// or to "fr"
smartBot.setUserLang("fr");

// get current user language:
let lngCode = smartBot.getUserLang(); // it will be "fr" here

Debugging

If debug is set to true, SmartBot will provide detailed error messages, which is helpful for troubleshooting and ensuring your bot behaves as expected.

Best Practices

  • Keep Language Files Updated: Regularly update your language files to reflect changes in your bot's functionality.

  • Test Thoroughly: Always test your bot for various scenarios, especially after adding new features or making changes.

  • Handle Errors Gracefully: Ensure that your bot handles errors smoothly and provides helpful feedback to users.

Conclusion

Setting up and initializing SmartBot is a straightforward process. By carefully configuring your language files and utilizing the robust features of SmartBot, you can create an interactive and user-friendly bot experience. Remember to test extensively and update your language files as your bot evolves.

Prefer to use after all :

You can make "return" in command andwill be not run. It can be helpful in some case.

So we can use username and balance props for command in now:

You can define translation. Read about this .

Lang File
here
BBDemoTaskBot
here
BeforeAll
Master Command
command "@@"
"@@"-command