Libs development
You can create own Lib. Now it is possible create lib only with Git importing.
Official Bots.Business repository available here​
You can store common code in the library.
See libraries in the Library Store. You can copy any free library and modify it.

Basic

For example: code in file libs\myLib.js:
1
function hello(){
2
Bot.sendMessage("Hello from lib!")
3
}
4
​
5
function goodbye(name){
6
Bot.sendMessage("Goodbye, " + name)
7
}
8
​
9
publish({
10
sayHello: hello,
11
sayGoodbyeTo: goodbye
12
})
Copied!
then you can use Lib in any bot's command:
1
Libs.myLib.hello()
2
Libs.myLib.sayGoodbyeTo("Alice")
Copied!

Commands capturing

It is possible to capture command with lib.
For example:
  • user type "Hi"
  • bot answer "Hello"
1
function onHiCommand(){
2
Bot.sendMessage("Hello");
3
}
4
​
5
on('Hi', onHiCommand );
Copied!
Master command "*" - for capture any text from user with lib
1
function onMasterCommand(){
2
/// input your code here
3
}
4
​
5
on('*', onMasterCommand );
Copied!
You can use all BJS functions in the Libs

Using HTTP

Lib can perform web requests. For example: get page from eample.com and send its content to user.
1
libPrefix = "myLib"
2
​
3
function load(){
4
HTTP.get( {
5
url: "http://example.com",
6
success: libPrefix + 'onLoading '
7
// headers: headers - if you need headers
8
} )
9
}
10
​
11
function onLoading(){
12
Bot.sendMessage(content);
13
}
14
​
15
on(libPrefix + 'onLoading', onLoading );
Copied!
on Bot command:
1
Libs.myLib.load();
Copied!
See more​
​
Last modified 2yr ago