Modern Web 2016
Using Golang to build smart IM Bot
Evan Lin @LinkerNetworkshttp://goo.gl/IYv1BU
About Me
• Cloud Architect @ Linker
Networks
• Top 10 Taiwan Golang open
source contributor (github
award)
• Developer, Curator, Blogger
Agenda
• What is IM Bot
• Introduce Golang
• Build Line Bot
• Build FB Bot
• Build a smart IM Bot
• Future
• Q&A
Instant Message Bot
What is IM?
(Instant Messenger)
What is IM Bot?
How to choose
programming language
• Easy to Write
• Fast in Run and
Compile
• Powerful Concurrency
• Powerful Built-in
Toolchain
Pokemon GO
Programming GO
What is Go(lang)
• Create by Google
• Design by
• Ken Thompson
• Rob Pike
• Robert Griesemer,
• Feature:
• Compiled
• Statically Typed
• Garbage Collection
Why Golang
• GO Fast!
• Compile Fast!
• Run Fast!
Go is Fast
Why Golang
• Make programming
fun again.
gofmt / goimport
Before we look code
Before we look code (cont)
After file save..
Go Vet
Analysis on source code and reports
suspicious constructs.
Go Lint
Coding style suggestions
GoRoutine:
Multiple Thread in C
GoRoutine:
Multiple Thread in Go
GoRoutine and Channel:
Multiple Thread in Go
GoRoutine and Channel:
Multiple Thread in Go
GoRoutine and Channel:
Multiple Thread in Go
https://talks.golang.org/2014/gocon-tokyo.slide
Golang - HTTPS Server
Golang - HTTPS Server
Supported
HTTP/2
After Go 1.6
Golang - Built-In Test
Golang - Built-In Benchmark Test
GoMobile
Original Work Flow
Golang
Sample Console
Sometime Failed
Work
Failed on Some Model
GoMobile
Using Golang in Mobile
Golang
GoMobile
Package


Golang
Sample Console
Go Playground:
Write A snippet Go code online
https://play.golang.org/
Go JSON Tutorial
Go JSON Tutorial
Go JSON Tutorial
Golang IDE
(Integrated Development Environment)
Golang IDE
(Integrated Development Environment)
VIM-GO
Golang IDE
(Integrated Development Environment)
Visual Studio Code Go Extension
Let’s build IM Bot.
Wait!
What is IM Bot working
flow?
IM Bot Working Flow:
HTTPS Webhook
How to prepare HTTPS
server?
• Prepare a machine with
public IP
• Install related OS and
runtime for your
programming language
• Purchase CA signed for
SSL Key ($$)
• Run a HTTPS Webserver
(Apache or Go native
Web Server)
Introduce Heroku
(Platform As A Service)
Free-tier
Heroku
(Platform As A Service)
• Free-tier:
• USES AN ACCOUNT-
BASED POOL
• OF FREE DYNO HOURS
• SLEEPS AFTER 30 MINS OF
INACTIVITY
• CUSTOM DOMAINS
• HTTPS connection (for
non-custom domains)
• Support one click deploy
IM Bot Working Flow
(update)
HTTPS Webhook
Build IM Line Bot
Step 1: Request Line Bot Trial Account
Apply Line Bot trial account here
(Only 1 per Line Account)
Step 2: Deploy to Heroku by
one click
Link : https://github.com/kkdai/LineBotTemplate
Step 2: Deploy to Heroku by
one click
Remember this address
Step 3. Fill your Heroku App
Callback address to Line Bot
• Copy your app
address from
Heroku to Line
Dashboard.
• It will be something
like “https://
xxxxxx.herokuapp.
com:443/callback”
Fill your app dress here
Step 4. Get related Line Bot
info for Heroku App setting
• Need copy
following
variable:
• Channel ID
• Channel Secret
• MID
Need copy those three
Step 5. Fill your Line Bot
Information to Heroku Variables
• In Heroku [Dashboard] ->
[Settings]-> [Config
Variables]
• Create following variables:
• ChannelID
• ChannelSecret
• MID
• Fill with you just got from
Line Bot Dashboard.
Send a Image to user
Parse bot request to received result
Send a Image to user
Make sure it is text message not operation
Send a Image to user
Send image to who text to the bot
“Hello” message from Line
Bot
Hello
Send a “Hello” message when add bot as
friend
Determine the operation type
Send a “Hello” message when add bot as
friend
Get request from ID, this is only way for now
Example: PetNeedMe
https://github.com/kkdai/LineBotPetNeedMe
Build Facebook Bot
Step 1: Deploy to Heroku
Link : https://github.com/kkdai/FBBotTemplate
Remember this address
Step 2: Create Facebook
Page
Step 3: Create App for
Messenger
• Create new app
“Web App”
• Select new
product
“Messenger”
Step 4: Create App Token
• Select generate
token.
• Need a “Page”
Step 5: Paste token to
Heroku Variable
Step 6: Setup Page
Subscription for Messenger Bot
https://APP_ADDRESS.herokuapp.com/webhook
Token we just generate
Step 7: Select a Page for
your Webhooks
Step 8: Select a Page for
your Webhooks
Example: PetNeedMe
Build A Smart IM Bot
IM ?
IM Bot 10 years ago
“ ”
: https://briian.com/2536/msn-bot.html
IM Bot 10 years later
“Fugle ”
• Left Brain
• Logical
• Verbal
• Language
?
?
?
?
?
?
?
?
?
?
?
Intent: ??
Entity: ??
?
Intent: Check Weather
Entity: ??
?
Intent: Check Weather
Entity: Taipei
Use LUIS to build smart
Bot
Use LUIS to build smart
Bot
LUIS
Other Natural Language
Processing Tool
Future
Future :
Bot to Bot (No more API)
Future :
Customer Service Bot
http://www.mobile01.com/topicdetail.php?f=383&t=4078424
Future :
For Your Website and Business
Future :
For Your Website and Business
Future :
How About Build Right Brain?
We are Hiring..

1. NFV/SDN Expert
2. Data Engineer
http://weekly.codetengu.com/
Go
Call For Speaker

Modern Web 2016: Using Golang to build a smart IM Bot