LoginSignup
23
21

More than 5 years have passed since last update.

Go言語を使用して簡単なLineBotを作る

Posted at

2017.03.22にWoman Who Go#10でやった内容です。

こちらがトークした内容をオウム返しに返すBotを作ります :blush:

Line Developperに登録する

 1. Line Business Centerに登録する。https://business.line.me/ja/
Messaging APIを選択。

2.LINE @MANAGERにログインする。 https://admin-official.line.me/
  ここでアカウント情報を入力する。

3.Line developpersから登録したアカウントを編集する。
    webhook URLを ngrokを公式またはbrewでインストールし、 ngrok http 8080 の結果で帰ってくる、Forwarding元のURL https://xxxxxxxx.ngrok.io を登録する。
 Channel Secret と Channel Access Tokenは後ほど利用する。

↑↑↑ここまで準備↑↑↑

4.line sdkのgithubに移動
5. 上のリポジトリをgo getします。
6. line-bot-sdk-go/examples/echo_bot/server.go の内容を編集します。
7. 27、28行目をそれぞれ上のアクセストークンとシークレットに書き換えします。

bot, err := linebot.New(
        "461~~~~69c03dd",
        "AN6KWhu~~~~~~~DnyilFU=",
    )

58行目のポートをngrokでforwardしているポートと同じ番号にします。

    if err := http.ListenAndServe(":8080", nil);
  1. go run server.go をします。
  2. スマホでBotに話しかけてみましょう。

こんな感じで帰ってくれば成功です :thumbsup:
image1.PNG

23
21
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
23
21