LoginSignup
9
8

More than 5 years have passed since last update.

LINE bot と Annict API を使用してアニメ情報をお知らせする Bot を作成する

Posted at

LINE bot と Annict API を使用してアニメ情報をお知らせする Bot を作成する

  • お題 : LINE bot と Annict API を使って今期のアニメ一覧を取得する

LINE BOT 作成までの流れ

LINE Bussiness Center のアカウントを取得

Messaging API を Developer Trial で始める

LINE@ MANAGER

  • 下記のような管理画面が使用可能になる
    LINE_MANAGER.png

  • Bot 設定から「Webhook送信:利用する」と「自動応答メッセージ:利用しない」に変更しておく必要がある
    setting.png

システムの用意

  • Messaging API を使用した Bot の構成は以下のようになるのでシステム側を用意する必要がある(公式より)
    LINE_API_Arch.png

  • 今回はシステムを Heroku に用意

  • Messaging API のドキュメントは下記にある

  • メッセージのやりとりには channel secret と channel access token が必要になるので LINE Developer のページから確認する

developer.png

  • heroku の環境変数に登録しておくことで下記のように情報を取得可能
  • システムを用意したら LINE Developer ページから 「Webhook URL」 を登録しておく
message = {
  type: 'text',
  text: 'hello'
}
client = Line::Bot::Client.new { |config|
    config.channel_secret = ENV["LINE_CHANNEL_SECRET"]
    config.channel_token = ENV["LINE_CHANNEL_TOKEN"]
}
response = client.reply_message("<replyToken>", message)
p response

Annict API を使うまでの流れ

uri = URI.parse("https://api.annict.com/v1/works?fields=title&per_page=50&filter_season=2017-winter&sort_watchers_count=desc&access_token=#{ENV["ANNICT_ACCESS_TOKEN"]}")

LINE bot で試す

  • 「アニメ一覧」に反応して、上記 API を叩くようにする
    anime_list.png

  • これで録画漏れを防げる!!

参考リンク

9
8
1

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
9
8