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

99
Modern Web 2016 Using Golang to build smart IM Bot Evan Lin @LinkerNetworks http://goo.gl/IYv1BU

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

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

Modern Web 2016

Using Golang to build smart IM Bot

Evan Lin @LinkerNetworkshttp://goo.gl/IYv1BU

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

About Me• Cloud Architect @ Linker

Networks • Top 10 Taiwan Golang open

source contributor (github award)

• Developer, Curator, Blogger

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

Agenda• What is IM Bot • Introduce Golang

• Build Line Bot

• Build FB Bot

• Build a smart IM Bot • Future

• Q&A

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

Instant Message Bot

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

What is IM? (Instant Messenger)

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

What is IM Bot?

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

How to choose programming language

• Easy to Write • Fast in Run and

Compile • Powerful Concurrency • Powerful Built-in

Toolchain

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

Pokemon GO

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

Programming GO

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

What is Go(lang)• Create by Google • Design by

• Ken Thompson • Rob Pike • Robert Griesemer,

• Feature:

• Compiled • Statically Typed • Garbage Collection

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

Why Golang

• GO Fast! • Compile Fast! • Run Fast!

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

Go is Fast

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

Why Golang

• Make programming fun again.

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

gofmt / goimport

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

Before we look code

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

Before we look code (cont)

Page 18: Modern Web 2016: Using Golang to build a smart IM Bot
Page 19: Modern Web 2016: Using Golang to build a smart IM Bot
Page 20: Modern Web 2016: Using Golang to build a smart IM Bot

After file save..

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

Go Vet Analysis on source code and reports

suspicious constructs.

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

Go Lint Coding style suggestions

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

GoRoutine: Multiple Thread in C

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

GoRoutine: Multiple Thread in Go

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

GoRoutine and Channel: Multiple Thread in Go

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

GoRoutine and Channel: Multiple Thread in Go

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

GoRoutine and Channel: Multiple Thread in Go

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

https://talks.golang.org/2014/gocon-tokyo.slide

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

Golang - HTTPS Server

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

Golang - HTTPS Server

Supported HTTP/2

After Go 1.6

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

Golang - Built-In Test

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

Golang - Built-In Benchmark Test

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

GoMobileOriginal Work Flow

Golang Sample Console

Sometime Failed

Work

Failed on Some Model

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

GoMobileUsing Golang in Mobile

GolangGoMobilePackage

Golang Sample Console

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

Go Playground: Write A snippet Go code online

https://play.golang.org/

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

Go JSON Tutorial

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

Go JSON Tutorial

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

Go JSON Tutorial

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

Golang IDE (Integrated Development Environment)

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

Golang IDE (Integrated Development Environment)

VIM-GO

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

Golang IDE (Integrated Development Environment)

Visual Studio Code Go Extension

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

Let’s build IM Bot.

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

Wait! What is IM Bot working

flow?

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

IM Bot Working Flow:

HTTPS Webhook

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

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)

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

Introduce Heroku (Platform As A Service)

Free-tier

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

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

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

IM Bot Working Flow (update)

HTTPS Webhook

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

Build IM Line Bot

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

Step 1: Request Line Bot Trial AccountApply Line Bot trial account here

(Only 1 per Line Account)

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

Step 2: Deploy to Heroku by one click

Link : https://github.com/kkdai/LineBotTemplate

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

Step 2: Deploy to Heroku by one click

Remember this address

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

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

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

Step 4. Get related Line Bot info for Heroku App setting

• Need copy following variable:

• Channel ID • Channel Secret • MID

Need copy those three

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

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.

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

Send a Image to user

Parse bot request to received result

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

Send a Image to user

Make sure it is text message not operation

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

Send a Image to user

Send image to who text to the bot

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

“Hello” message from Line Bot

Hello

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

Send a “Hello” message when add bot as friend

Determine the operation type

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

Send a “Hello” message when add bot as friend

Get request from ID, this is only way for now

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

Example: PetNeedMehttps://github.com/kkdai/LineBotPetNeedMe

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

Build Facebook Bot

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

Step 1: Deploy to Heroku

Link : https://github.com/kkdai/FBBotTemplate

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

Remember this address

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

Step 2: Create Facebook Page

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

Step 3: Create App for Messenger

• Create new app “Web App”

• Select new product “Messenger”

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

Step 4: Create App Token

• Select generate token.

• Need a “Page”

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

Step 5: Paste token to Heroku Variable

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

Step 6: Setup Page Subscription for Messenger Bot

https://APP_ADDRESS.herokuapp.com/webhook

Token we just generate

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

Step 7: Select a Page for your Webhooks

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

Step 8: Select a Page for your Webhooks

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

Example: PetNeedMe

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

Build A Smart IM Bot

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

IM ?

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

IM Bot 10 years ago “ ”

: https://briian.com/2536/msn-bot.html

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

IM Bot 10 years later “Fugle ”

Page 78: Modern Web 2016: Using Golang to build a smart IM Bot
Page 79: Modern Web 2016: Using Golang to build a smart IM Bot
Page 80: Modern Web 2016: Using Golang to build a smart IM Bot

• Left Brain • Logical • Verbal • Language

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

?

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

?

?

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

?

?

??

??

?

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

?Intent: ??

Entity: ??

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

?Intent: Check Weather

Entity: ??

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

?Intent: Check Weather

Entity: Taipei

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

Use LUIS to build smart Bot

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

Use LUIS to build smart Bot

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

LUIS

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

Other Natural Language Processing Tool

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

Future

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

Future : Bot to Bot (No more API)

\

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

Future : Customer Service Bot

http://www.mobile01.com/topicdetail.php?f=383&t=4078424

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

Future : For Your Website and Business

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

Future : For Your Website and Business

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

Future : How About Build Right Brain?

\

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

\

We are Hiring..

1. NFV/SDN Expert2. Data Engineer

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

http://weekly.codetengu.com/

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

Go Call For Speaker