BUILD A MESSENGER BOT

A part of Hack the Castle 2018

Cetrez Logoo Created with Sketch.

About Cetrez

 

Cetrez is a digital innovation company.

 

We exist to accelerate our clients’ advantage in their digital journey.

 

Hack The Castle

Part of Cetrez Academy

hack.cetrez.com

Cetrez Logoo Created with Sketch.

Todays agenda

 

  • Getting started with bot development
  • What makes a bot good
    • Common patterns and gotchas
  • Make your bot smarter with NLP/NLU AI
Cetrez Logoo Created with Sketch.

Getting started

 

  • Messenger Platform
    • Step by step Wizard
  • Set up a page
    • Unpublished for testing
  • Test out the node example
Cetrez Logoo Created with Sketch.

Local tunnel

Handle the frequent crashes

#!/usr/bin/env sh

DEFAULT_DOMAIN="$USER-$HOSTNAME"
SUBDOMAIN="${1:-$DEFAULT_DOMAIN}"
# Only lower case alpha numeric characters 
# are allowed for lt
SUBDOMAIN=$(echo $SUBDOMAIN | \
    tr '[:upper:]' '[:lower:]' | \
    tr -cd '[[:alnum:]]')

until lt --port 5000 --subdomain $SUBDOMAIN
do
    echo "# Restarting tunnel #"
    # Avoid restarts from flooding the CPU
    sleep 0.5
done
Cetrez Logoo Created with Sketch.

Start building

 

  • Use the language of your choosing
    • Python for us
  • Flask based library FBMQ
  • Example server quick start
    • default.json ⇒ config.py
CONFIG = {
    'FACEBOOK_TOKEN': 'pageAccessToken',
    'VERIFY_TOKEN': 'validationToken',
    'SERVER_URL': 'https://sub.localtunnel.me'
}
{
    "appSecret": "…",
    "pageAccessToken": "…",
    "validationToken": "…",
    "serverURL": "https://sub.localtunnel.me"
}
Cetrez Logoo Created with Sketch.

Stupid bot

 

  • Requires exact matches
    • Annoying!
  • Levenshtein distance
    • Built into Python
    • Rough matches
  • Fuzzy matching
    • Partial string similarity
    • Out of order tokens
Cetrez Logoo Created with Sketch.

Getting fuzzy

 

from fuzzywuzzy import fuzz, process

# …

process.extractOne(
    text, 
    special_keywords.keys()
)
Cetrez Logoo Created with Sketch.

Be a nice bot

Make your bot's chat interface feel more natural, don't confuse your user.

 

Exemplar: Kilian Valkhof ​
A Messenger Adventure
 
Game loop

6 things I learned

  • People send stickers
  • Users answer rhetorical questions
  • No delay feels mechanical
  • Use Quick replies
  • Set up a Dev bot
  • Get the Facebook Pages app
Cetrez Logoo Created with Sketch.

Delays

 

Natural delays make gives your bot depth

 

  • Use typing indicators and read receipts 
  • Split replies
  • 30 ms / letter + random
    • Base delay on previous message if multiple
Cetrez Logoo Created with Sketch.

Use quick replys

 

Guide the user towards known functions

 

  • Enhances discoverability
  • Less confusion
  • Traceable 
Cetrez Logoo Created with Sketch.

Stickers

 

Your users will send stickers to your bot

 

  • Handle them as replies
  • Different sizes have their own ID
    • Three sizes
Cetrez Logoo Created with Sketch.

Templates

Use templates to enable richer content replies

  • Receipt
  • Airline
    • Boarding passes
  • Media
  • Button
    • HTML, Phone, Buy
  • List
    • 2-4 items
  • Generic
    • Carousel
Cetrez Logoo Created with Sketch.

AI

Train your own models

 

NLP/NLU as a Service

Cetrez Logoo Created with Sketch.

rasa.ai

Cetrez Logoo Created with Sketch.

wit.ai

 

Cetrez Logoo Created with Sketch.

Chatfuel

Cetrez Logoo Created with Sketch.
Cetrez Logoo Created with Sketch.

Questions?

hack.cetrez.com

Friday, February 2

18:00

Saturday February 3

08:00 – 23:00

Cetrez Logoo Created with Sketch.
Cetrez Logoo Created with Sketch.

Build a Messenger bot

By Alexander Hultnér

Build a Messenger bot

A part of Hack The Castle 2018

  • 2,540