gae/goでline messaging api を使う

17
GAE/GoLINE Messaging APIを使う 2016/11/13(日) @GAE/GoChat botハッカソン The Go gopher was designed by Renee French . The gopher stickers was made by Takuya Ueda. Licensed under the Creative Commons 3.0 Attributions license.

Upload: takuya-ueda

Post on 16-Apr-2017

696 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: GAE/GoでLINE Messaging API を使う

GAE/GoでLINE Messaging APIを使う

2016/11/13(日)@GAE/GoでChat botハッカソン

The Go gopher was designed by Renee French.The gopher stickers was made by Takuya Ueda.Licensed under the Creative Commons 3.0 Attributions license.

Page 2: GAE/GoでLINE Messaging API を使う

自己紹介

メルカリ/ソウゾウ

上田拓也twitter: @tenntenn■ Go歴 / GAE歴

Go:5〜6年くらい?

GAE:最近再開、GCPUG Tokyoのスタッフ

■ 業務GAE/Goでメルカリアッテを作ってます

Goのコミュニティを盛り上げる仕事

Gopherを描く仕事

Page 3: GAE/GoでLINE Messaging API を使う

LINE Bot Award

Page 4: GAE/GoでLINE Messaging API を使う

賞金1000万円!!!

Page 5: GAE/GoでLINE Messaging API を使う

便乗!

Page 6: GAE/GoでLINE Messaging API を使う

※このイベント(ハッカソン)は勝手にやってます。

運営にLINEさんは関係していません。

Page 8: GAE/GoでLINE Messaging API を使う

LINE Messaging API

■ 何ができるのか?

● https://devdocs.line.me/ja/● Webhook● Reply Message API● Push Message API● Get Content API● Get Profile API● Leave API

Page 9: GAE/GoでLINE Messaging API を使う

Botをどういう仕組みで作るのか?

GAELINE

メッセージ投稿 Webhook

メッセージ返信 Reply Message

Page 10: GAE/GoでLINE Messaging API を使う

Webhook (LINE Messaging API)

cli := urlfetch.Client(c)client := linebot.WithHTTPClient(cli)bot, err := linebot.New(secret, token, client)

■ クライアントの作成

■ リクエストのパース

events, err := bot.ParseRequest(req)

GAEのcontext.Context

*http.Request

Page 11: GAE/GoでLINE Messaging API を使う

■ データの取得

■ データの保存

Datastore (GAE)

var s []*Settingconst k = "Setting"datastore.NewQuery(k).GetAll(c, &s)

key := datastore.NewIncompleteKey(c, k, nil)s := &Setting{

Secret: ...,Token: ...,

}datastore.Put(c, key, s)

Page 12: GAE/GoでLINE Messaging API を使う

■ 保存する構造体

Datastore (GAE)

type Setting struct {Secret string `datastore:"secret"`Token string `datastore:"token"`

}

Page 13: GAE/GoでLINE Messaging API を使う

■ メッセージの返信

Reply (LINE Messaging API)

for _, event := range events {...rt := event.ReplyTokenmsg := linebot.NewTextMessage("Hi")res, err := bot.ReplyMessage(rt, msg).Do()...

}

イベントを1つずつ処理する

メッセージの送信

Page 15: GAE/GoでLINE Messaging API を使う

アイデア

■ 位置情報を使う?

● Google Maps API● Location Message

■ 画像を使う?

● Google Vision API○ 1000UNITまで無料なので気をつける

● Image Message● ImageMap Message

Page 16: GAE/GoでLINE Messaging API を使う

成果発表

Page 17: GAE/GoでLINE Messaging API を使う

Thank you!

twitter: @tenntenn Qiita: tenntennconnpass: tenntenn