How To Build Bots For Business

Alex Bunardzic, May 25, 2017

About the presenter

Holistic software developer

Holistic?

Taking all aspects of software development into consideration

50% analysis,

50% process,
50% engineering

Analysis: measure twice, cut once

Process: continuous delivery

Engineering: purity in programming (no unwanted side effects)

Analysis, process and engineering are not considered in isolation

These three activities influence and inform each other, resulting in 150% yield

Fighting two principal enemies of quality software delivery:

1. Hidden assumptions

2. Tight coupling with operational interfaces

Mobile First

Peak App?

Is the App Boom over?

49% Mobile Users Have Downloaded 0 Apps Per Month

Source:

http://www.comscore.com/Products/Audience-Analytics/MobiLens

Month Average Ending June 2016

Mobile Apps Are Frustrating

  • Difficult to discover
  • Difficult to evaluate before deciding whether to buy the app or not to buy it
  • Time consuming to download and install
  • Difficult to configure
  • Once installed, difficult to find on the mobile device
  • Once evaluated, difficult (impossible?) to get your money back
  • If retained, difficult to keep up with inevitable upgrades

Is there an alternative?

Instant Messaging/Chat

Majority of users are spending a lot of their digital minutes chatting

Follow the Market!

Customers are used to chatting with friends, family, coworkers

It would be convenient if they could chat with services as well

Chatbots! (bots for short)

Conversational Commerce

Advantages/benefits of Conversational Commerce

Convenient

Nothing to download

Nothing to install

Nothing to configure

No need to authenticate (the user is already authenticated on the channel)

Nothing to learn (users already know how to text back-and-forth)

Nothing to purchase (texting is the same for any client)

Nothing to upgrade (texting does not require beefier and beefier clients)

Easy to cancel any eventual subscription

Voice-activated

Advantages over GUI 

Example: I need to set my alarm clock

Using traditional app:

Step 1: Unlock my phone

Step 2: Find and open the Clock app

Step 3: Activate the Alarm tab

Step 4: Find the '+' function and activate the Add Alarm

Step 5: Scroll up/down to pick the  alarm hour

Step 6: Scroll up/down to pick the  alarm minute

Step 7: Make sure you picked AM instead of PM!

Voila!

Doing the same alarm setup using Conversational User Interface (CUI):

"Siri, wake me up tomorrow morning at 6:30"

Advantages/benefits for the business

No need to invest in AngularJs, React, MobX, Acid-reflux and all that jazz

Text is text, voice or typed/read

Screenless User Interface

Snappy responses are less of an issue with bots

It's OK if a bot takes a bit of time to respond

Most bots available on the market today are focused on

individual users

This universally accepted approach is clearly setting bots for a failure

Current state of NLP technology is immature, resulting in bots that are confusing and frustrating to use

Even the simplest of bot interactions quickly deteriorate, leaving users disenchanted

Following my last question, the conversation died and the bot became permanently unresponsive

This fiasco is caused by the misplaced focus on trying to serve human users by pretending to be yet another human

(the casual tone of the conversation and the faux human avatar)

People are fickle

People keep changing their minds in the middle of conversation

Even fairly experienced human experts often face challenges when fielding customer requests

Bots stand little, or no chance dealing with all the quirks and foibles humans throw at them

The state of AI would have to advance significantly before we could rely on bots to serve finicky users

In the meantime?

Focus on building

bots for business!

Why?

Bots for business are easier to tame

Also, bots for business are very helpful to the businesses

Much more likely to get funding when building something that helps the business

Two families of bots

1. Concierge

2. Butler

Concierge

Loyal to the Corporation

Butler

Loyal to the Individual

Butler

  • Focused on learning about its owner's habits
  • Focused on detecting recurring behavioural patterns
  • Trained to respect the owner's preferences

Butler Bot

  • Stars in many Hollywood movies
  • Needs heavy duty AI

Concierge

  • Focused on learning about the corporate goals
  • Focused on consistent customer service
  • Trained to detect business opportunities (i.e. up-sell/cross-sell)
  • Sets the tone of the conversation

Concierge Bot

Establishes the conversational protocol

Concierge Bot

Doesn't necessarily need beefy AI

Conversation with a

narrow focus

Example: Medical Receptionist

Typical experience with a Medical Receptionist (Concierge)

Typical experience with a Medical Receptionist (Concierge)

  • Receptionist sets the tone of the conversation

Typical experience with a Medical Receptionist (Concierge)

  • Receptionist sets the tone of the conversation
  • Establishes the conversational protocol

Typical experience with a Medical Receptionist (Concierge)

  • Receptionist sets the tone of the conversation
  • Establishes the conversational protocol
  • Asks for pertinent information (name, insurance, phone, date of birth)

Typical experience with a Medical Receptionist (Concierge)

  • Receptionist sets the tone of the conversation
  • Establishes the conversational protocol
  • Asks for pertinent information (name, insurance, phone, date of birth)
  • Impervious to any attempts to spark up irrelevant conversation

Typical experience with a Medical Receptionist (Concierge)

  • Receptionist sets the tone of the conversation
  • Establishes the conversational protocol
  • Asks for pertinent information (name, insurance, phone, date of birth)
  • Impervious to any attempts to spark up irrelevant conversation
  • If a visitor refuses to comply, receptionist may ask them to leave

Concierge Bot model requires rudimentary NLP

Challenges

Challenges

Even rudimentary NLP is a huge challenge!

Google Assistant

What do businesses value?

What do businesses value?

  • Predictability

What do businesses value?

  • Predictability
  • Coherent behaviour

What do businesses value?

  • Predictability
  • Coherent behaviour
  • Consistent behaviour

What do businesses value?

  • Predictability
  • Repeatability
  • Coherent behaviour
  • Fully controllable behaviour

Four Levels of Communication Protocol

Four Levels of Communication Protocol

  1. Command protocol

Four Levels of Communication Protocol

  1. Command protocol
  2. Keyword protocol

Four Levels of Communication Protocol

  1. Command protocol
  2. Keyword protocol
  3. Structured phrase protocol

Four Levels of Communication Protocol

  1. Command protocol
  2. Keyword protocol
  3. Structured phrase protocol
  4. Free form (informal) protocol

Command protocol

Command protocol

  • CLI (Command line interface)

Command protocol

  • CLI (Command line interface)
  • Escape syntax ('/', forward slash, or '@' or '!' etc.)

Command protocol

  • CLI (Command line interface)
  • Escape syntax ('/', forward slash, or '@' or '!' etc.)
  • Example: '/help', or '@help', or '!help' and so on

Command protocol

  • CLI (Command line interface)
  • Escape syntax ('/', forward slash, or '@' or '!' etc.)
  • Example: '/help', or '@help', or '!help' and so on
  • Globally scoped (same meaning regardless of context)

Good example: Git

Conversation context

Keyword protocol

Keyword serves to alert the bot that the context of the conversation has changed

Example: @doctor

  • User may interrupt the conversation by mentioning the keyword @doctor

Example: @doctor

  • User may interrupt the conversation by mentioning the keyword @doctor
  • The bot will realize that @doctor is not found in the list of commands

Example: @doctor

  • User may interrupt the conversation by mentioning the keyword @doctor
  • The bot will realize that @doctor is not found in the list of commands
  • The bot will find @doctor in the list of keywords

Example: @doctor

  • User may interrupt the conversation by mentioning the keyword @doctor
  • The bot will realize that @doctor is not found in the list of commands
  • The bot will find @doctor in the list of keywords
  • The bot was trained to switch the conversation context upon hearing @doctor and will pick the appropriate subsequent question, such as "would you like me to schedule doctor's appointment?" etc.

Structured phrase protocol

Less formal than keyword protocol

Less predictable/controllable/repeatable than keyword protocol

Useful for enhancing natural flow of the conversation

To be used judiciously and sparringly

Free form (informal) protocol

Bot will receive many messages that do not contain commands, keywords, nor structured, predefined phrases

How to cope with free-form messages?

Honesty is the best policy?

Being 100% honest and replying with "I don't know"

Copout

Better to meet the user halfway

Fake it till you make it?

Risks and Pitfalls

Prank calls

Malicious calls

Messages that don't contain commands, keywords or predefined structured phrases must be scrubbed

How?

Protocall

curl --data "content=Some word or phrase" http://protocall.herokuapp.com/sentiments/find

If everything else fails -- humour :)

Addendum: show us some code!

Bad code first ;)

What's wrong with that code?

Let me count the ways...

  • Difficult to find
  • Difficult to read
  • Difficult to reason about
  • Difficult to modify (very difficult!)
  • Difficult to troubleshoot
  • Difficult to debug
  • Difficult to document
  • Difficult to estimate the impact of a simple change

Is there a better way?

Implementing deterministic conversational workflow in Ruby

Simplified scenario

  • User (shopper) asks the bot to see the catalog
  • The bot messages back with the catalog
  • User picks an item and sends it to the bot as a message
  • Bot checks if the user chose an existing item in the catalog, or if the user said something unrelated

"The process of software development is breaking down large problems into smaller problems, building components that solve those smaller problems, then composing those components together to form a complete application." -Eric Eliott

Bot Architecture

Two Layers

Commodity layer

Core competence layer

Commodity Layer

  • Messaging channels (SMS, Messenger, WhatsApp, Slack, etc.)
  • Natural Language Processing/Understanding (NLP/NLU)
  • Computing infrastructure (servers, clients, message queues...)

Core Competence Layer

  • Business application domain-specific code
  • Business entities
  • Business operation

Business Operation

  • Dispatching
  • Authentication/authorization
  • Validation
  • Business rules/processing logic
  • Persistence
  • Response

Business Entities

  • User
  • Conversation
  • Context

Conversation

  • Belongs to User
  • Remembers messages received from the User
  • Remembers replies to the User
  • Declares the next step
  • Drives the workflow

Next  step?

Determined by the business logic

How is next  step implemented?

If using imperative approach

More desirable to implement next step using declarative approach

Compartmentalize processing logic into isolated components

Similar to REST and HATEOAS

In REST isolated components are implemented as resources

HATEOAS provides the next step

Building blocks (i.e. components that solve smaller problems)

Use case driven: each use case encapsulates one component

1. Create a component ProcessCatalogSelection

Declare next step to be "TakeItemSelection"

2. Create a component TakeItemSelection

Declare next step to be "TakeItemQuantity"

And so on...

How to execute this workflow?

Create a main driver component:

Entry with a single method: dispatch

The main engine runs on two lines of code:

1. clas = next_step.constantize
2. clas.new(params)

OK, but where is the next step coming from?

next_step = user.conversations.last.next_step

https://medium.com/bots-for-business

Questions?

  • https://twitter.com/alexbunardzic

  • https://medium.com/alex-bunardzic

Copy of deck

By Alex Bunardzic

Copy of deck

  • 743