Rafael Casuso Romate
Lead Front-End Engineer with more than 10 years of experience architecting and developing software. Machine Learning, Natural Language Processing, Bot Development and Reactive Fullstacks are some of his areas of expertise.
Rafael Casuso
Bot Development_
PLANNING_
Write down your functional requirements as features in
natural language.
Separate them into phases (more on this later)
Visualize your main interactive flows, according
to the bot intelligence and the phase
Bot Development_
PHASE ONE_
No user account login nor deep back-end integration.
Low intelligence:
Visual interface:
Bot Development_
PHASE TWO_
User account login and integration with back-end services.
Medium intelligence:
Visual and Language interface:
Bot Development_
PHASE THREE_
User account login and deep integration with back-end services, including message persistence.
High intelligence:
Language interface:
Bot Development_
PROGRAMMING GUIDELINES_
Your best choice is a modularized, decoupled and abstract design.
Multi-tier and multi-layer architecture (more on this later).
BDD avoids unnecessary code and increases solidity.
CI detects early problems and CD enables quick DCs.
Document-Oriented Persistence works best.
Object-Oriented Programming works best.
Multi-language support from start.
Messages are key, normalize them and store them.
Beware framework coupling.
Bot Development_
ARCHITECTURE_
Tiers and Layers:
Three tiers must be deployed, maintained and
evolved independently, isolated in separated
machines/containers.
Further division can be explored, like a more resilient microservices
infrastructure.
Cognitive Services
Persistance
Datasource
Other
Datasources
Composed API
Business Logic
Communications
Messaging Adapter
Messaging Adapter
Messaging Adapter
External API
Bot Development_
1
2
3
/**
* POST /messages
*
* Create a message which persists it to the server.
*
* @arg string from Account._id for a private message.
* @arg string to Account._id for a private message.
* @arg string content The message text.
* @returns object Message
*/
router.post('/', function(req, res) {
new req.db.Message({
from: req.body.from,
to: req.body.to,
content: req.body.content,
created: new Date().getTime()
}).save(function (err, message) {
if (err) {
return next(err);
}
res.send(message);
});
});
//Internal API
//Message POST Example
const Booking = class Booking {
constructor(options) {
//Validate options
this.serviceId = options.serviceId;
this.userId = options.userId;
this.date = options.date;
}
save(){
return request.post({
url: config.currentApiHost + '/bookings',
body: {
serviceId: this.options.serviceId,
userId: this.options.userId,
date: this.options.date
},
json: true
})
}
fetch(){
if (this.id) {
return request.get(config.currentApiHost + '/bookings/' + this.id)
} else {
throw "Booking must be saved before retrieved";
}
}
}
//Business Logic Layer
//Booking Class Example
const Message = class Message {
constructor(options) {
this.from = options.from;
this.to = options.to;
this.content = options.message;
this.id = options.id || null;
}
save() {
if (this.id) {
return request.put({
url: config.currentApiHost + '/messages/' + this.id,
body: {
from: this.from,
to: this.to,
message: this.content
},
json: true
})
} else {
return request.post({
url: config.currentApiHost + '/messages',
body: {
from: this.from,
to: this.to,
message: this.content
},
json: true
})
}
}
fetch() {
if (this.id) {
return request.get(config.currentApiHost + '/messages/' + this.id)
} else {
throw "Message must be saved before retrieved";
}
}
}
//Communications Layer
//Message Class Example
BOTKIT_
Intelligence: Based on keywords or patterns. and sending messages through both real-time and http APIs. Includes Conversation support (multi-message).
Features: Real-Time API (Websockets-based API for receiving events and sending messages as user), Incoming Webhooks (HTTP request with JSON payload), Slash Commands (Slack).
Platforms: Slack and Facebook Messenger.
Bot Frameworks_
BOTKIT EXAMPLE
BOTKIT EXAMPLE
MICROSOFT BOT FRAMEWORK_
Intelligence: Allows keywords, patterns but also access to LUIS (Language Understanding Intelligent Service) AI API. Multi-message support through Dialog System that uses routes and waterfalls.
Features: Bot Connector (Connects to several platforms, translation service, analytics), Bot Builder Node SDK (Dialog System, Buil-int Prompts - Functions to collect text, dates, numbers, etc -), Emulator (Windows).
Platforms: Skype, SMS, Slack and Telegram.
Bot Frameworks_
MICROSOFT BOT FRAMEWORK
MICROSOFT BOT FRAMEWORK EXAMPLE
FACEBOOK MESSENGER PLATFORM_
Intelligence: Allows keywords, patterns but also access to Wit.ai (NLP) AI API. Receives messages through Webhook Multi-message support through Dialog System that uses routes and waterfalls.
Features: Welcome Screen, Structured Templates (image, text and buttons), Wit.ai Bot Engine (train entities, intents and stories for NLP), Web Buttons to enable interaction, Customer Matching (connect with users through phone number).
Platforms: Facebook Messenger.
Bot Frameworks_
FACEBOOK MESSENGER PLATFORM
FACEBOOK MESSENGER FRAMEWORK EXAMPLE
By Rafael Casuso Romate
Recommended architecture, tips and a general overview for main frameworks of Bot Development. From the perspective of a Software Engineer currently developing Customer Service and Corporate Organization Software Robots.
Lead Front-End Engineer with more than 10 years of experience architecting and developing software. Machine Learning, Natural Language Processing, Bot Development and Reactive Fullstacks are some of his areas of expertise.