Top Banner
Golang Taipei Gathering #16 Using Golang to build smart IM Bot Evan Lin @LinkerNetworks
65

Gopher Taiwan Gathering #16: Build a smart bot via Golang

Jan 21, 2017

Download

Internet

Evan Lin
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

Golang Taipei Gathering #16

Using Golang to build smart IM Bot

Evan Lin @LinkerNetworks

Page 2: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

About Me

• Cloud Architect @ Linker Networks

• Top 10 Taiwan Golang open source contributor (github award)

• Developer, Curator, Blogger

Page 3: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

How to choose programming language

• Easy to Write

• Fast in Run and Compile

• Powerful Concurrency

• Powerful Built-in Toolchain

Page 4: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

Pokemon GO

Page 5: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

Go is Fast

Page 7: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

gofmt / goimport

Page 8: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

Before we look code

Page 9: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

Before we look code (cont)

Page 10: Gopher Taiwan Gathering #16:  Build a smart bot via Golang
Page 11: Gopher Taiwan Gathering #16:  Build a smart bot via Golang
Page 12: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

After file save..

Page 13: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

GoMobileOriginal Work Flow

GolangSample Console

Sometime Failed

Work

Failed on Some Model

Page 14: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

GoMobileUsing Golang in Mobile

GolangGoMobilePackage

GolangSample Console

Page 15: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

Golang IDE(Integrated Development Environment)

Visual Studio Code Go Extension

Page 16: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

Build IM Line Bot

Page 17: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

Step 1: Request Line Bot Trial Account

Apply Line Bot trial account here (Only 1 per Line Account)

Page 18: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

Step 2: Deploy to Heroku by one click

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

Page 19: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

Step 2: Deploy to Heroku by one click

Remember this address

Page 20: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

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 21: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

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 22: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

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 23: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

Send a Image to user

Parse bot request to received result

Page 24: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

Send a Image to user

Make sure it is text message not operation

Page 25: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

Send a Image to user

Send image to who text to the bot

Page 26: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

“Hello” message from Line Bot

Hello

Page 27: Gopher Taiwan Gathering #16:  Build a smart bot via Golang
Page 28: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

Send a “Hello” message when add bot as friend

Determine the operation type

Page 29: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

Expect Result Actual Result

No “id” and “from” in “content”.We need use the value from “param[0]” to find who send the invitation

http://www.evanlin.com/line-bot-sdk-survey/

Page 30: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

Send a “Hello” message when add bot as friend

Get request from ID, this is only way for now

Page 32: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

Build Facebook Bot

Page 33: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

Step 1: Deploy to Heroku

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

Page 34: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

Remember this address

Page 35: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

Step 2: Create Facebook Page

Page 36: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

Step 3: Create App for Messenger

• Create new app “Web App”

• Select new product “Messenger”

Page 37: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

Step 4: Create App Token

• Select generate token.

• Need a “Page”

Page 38: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

Step 5: Paste token to Heroku Variable

Page 39: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

Step 6: Setup Page Subscription for Messenger Bot

https://APP_ADDRESS.herokuapp.com/webhook

Token we just generate

Page 40: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

Step 7: Select a Page for your Webhooks

Page 41: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

Step 8: Select a Page for your Webhooks

Page 42: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

Example: PetNeedMe

Page 43: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

你的 IM 機器人夠聰明嗎?

Page 44: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

IM Bot 10 years ago“有問必達”

圖片重灌狂人: https://briian.com/2536/msn-bot.html

Page 45: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

IM Bot 10 years later“Fugle股市小幫手”

Page 46: Gopher Taiwan Gathering #16:  Build a smart bot via Golang
Page 47: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

• Left Brain

• Logical

• Verbal

• Language

Page 48: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

台北天氣如何?

Page 49: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

台北天氣如何?台北有下雨嗎?

Page 50: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

台北天氣如何?台北冷嗎

?

台北天氣好嗎

?

台北天氣怎麼樣?

台北天空是什麼顏色?

台北有下雨嗎?

去台北需要帶傘嗎?

Page 51: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

台北天氣如何?Intent: ??

Entity: ??

Page 52: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

台北天氣如何?Intent: Check Weather

Entity: ??

Page 53: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

台北天氣如何?Intent: Check Weather

Entity: Taipei

Page 54: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

Use LUIS to build smart Bot

Page 55: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

Use LUIS to build smart Bot

Page 56: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

LUIS

Page 57: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

Other Natural Language Processing Tool

Page 58: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

Future

Page 59: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

Future : Bot to Bot (No more API)

\

Page 61: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

Future : For Your Website and

Business

Page 62: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

Future : For Your Website and

Business

Page 63: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

Future : How About Build Right Brain?

\

Page 64: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

\

We are Hiring..

1. Senior Data ScientistFr

2. Senior Front-end

Page 65: Gopher Taiwan Gathering #16:  Build a smart bot via Golang

歡迎訂閱 碼天狗

http://weekly.codetengu.com/