Bot

Rafael Casuso

Dev

Intro

B

O

T

D

E

V

E

L

O

P

M

E

N

T

_

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:​

  • Limited options                                                                       
  • Simple flows: Classification Decission Tree
  • Language Processing:
    • ​Keywords
    • Regexp

Visual interface:

  • Cards                                                                                                
  • Buttons

Bot Development_

PHASE TWO_

 

User account login and integration with back-end services.

Medium intelligence:​

  • More flexible options with intents and entities (variables)               
  • Medium flows: Regression Decission Tree
  • Natural Language Processing:
    • ​Progressive study of Intents and Entities
    • NLP API Services like Wit.ai

Visual and Language interface:

  • Cards & Buttons                                                                                        
  • Conversations

Bot Development_

PHASE THREE_

 

User account login and deep integration with back-end services, including message persistence.

High intelligence:​

  • Advanced conversational flows                                                            
  • Large amount of Intents and Entities
  • Natural Language Processing:
    • Neural networks-based tech like LUIS
    • Advanced syntatic engine for expressions

Language interface:

  • Advanced Conversations                                                                          

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:

  1. Persistence Datasource, Cognitive Services, Other Services
  2. Internal API
  3. Business Logic, Communication,
    External API and Messaging Adapters

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

B

O

T

F

R

A

M

E

W

O

R

K

S

_

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

THANK YOU

Bot Development Introduction

By Rafael Casuso Romate

Bot Development Introduction

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.

  • 1,000
Loading comments...

More from Rafael Casuso Romate