Libs development
You can store common code in the library.
See libraries in the Library Store. You can copy any free library and modify it.
For example: code in file libs\myLib.js:
function hello(){
Bot.sendMessage("Hello from lib!")
}
function goodbye(name){
Bot.sendMessage("Goodbye, " + name)
}
publish({
sayHello: hello,
sayGoodbyeTo: goodbye
})
then you can use Lib in any bot's command:
Libs.myLib.hello()
Libs.myLib.sayGoodbyeTo("Alice")
It is possible to capture command with lib.
For example:
- user type "Hi"
- bot answer "Hello"
function onHiCommand(){
Bot.sendMessage("Hello");
}
on('Hi', onHiCommand );
Master command "*" - for capture any text from user with lib
function onMasterCommand(){
/// input your code here
}
on('*', onMasterCommand );
You can use all BJS functions in the Libs
Lib can perform web requests. For example: get page from eample.com and send its content to user.
libPrefix = "myLib"
function load(){
HTTP.get( {
url: "http://example.com",
success: libPrefix + 'onLoading '
// headers: headers - if you need headers
} )
}
function onLoading(){
Bot.sendMessage(content);
}
on(libPrefix + 'onLoading', onLoading );
on Bot command:
Libs.myLib.load();
Last modified 3yr ago