Wiki
universal-bot-framework / Usage
Congratulations! You made it so far! =)
Lets start with the usage of the boilerplate you installed.
As you can see in the codebase there are already some examples. It shows basic functionality of our Chatbot "Swelly" with static demo data. Checkout the our Chatbot to see how it works in reality:
Files
Now I am going to explain you what the different files are doing, and which of them you need to develop your first bot version.
/app.js
- does all the setup
/config/...
- you already know the config files from the installation
/constant/BOT.js
- here are all the constants and keys for the bot. Never use text directly in the source.
/controller/bot/[chatbotPlatform]/Listener.js
- initializes the bot instance and set up all the listener for incoming messages. After incoming message it calls the Handler.processMessage
function in the following file:
/controller/bot/Handler.js
- gets called from the Listener
and process the message. Basically its doing all the logic. It decides what to do with the message and what to send back. It calls the send functions in the following file:
/controller/bot/[chatbotPlatform]/Controller.js
- gets called from the Handler
. Here are all the sending functions with different payload, because every platform needs other data and has another UI to set up. If you add a new function, it has to be in every Controller of all chatbot platform folders.
/model/mongo/ChatBotUserSession.js
- Schema of a user session
Little example to make it clear how the incoming, processing, sending flow works.
User sends a message to chat:
- incoming message: "start"
- the eventlistener in Listener.js gets the message:
bot.on('message', function (chatBotUserId, message, req) { __processMessage(chatBotUserId, {action: message, message: true}, req); });
and creates a payload object with message asaction
- after that it calls
controller.Bot.Handler.processMessage()
from theHandler
- it checks the message/action and does all the logic
- then it calls the correct function in
[chatbotPlatform]/Controller.js
, in this case the message "start" calls...sendWelcomeMessage()
- this function sends back a message to the user in the correct format
Now implement your Logic in Handler.js
and the send back functions in the Controller.js
.
Thats it, have fun ;)
Updated