今、何かメッセージを打つとおうむ返しするLINE BOTをRailsで作っているのですが動かなくて困っています。
LINEの公式でwebhook URL(https://hoge.herokuapp.com/callback)を登録して接続確認をすると、 Webhookが無効なHTTPステータスコードを返しました(期待されるステータスコードは200です)
と返ってきてしまいます。ただ、ソースコードを見る限り問題がなさそうなのですが、なぜ200が返ってこないのかわかりません。もしご存知の方がいらっしゃいましたら教えていただきたいです。ちなみにWebhook送信
は利用するになっています。
application_controller
class ApplicationController < ActionController::Base require 'line/bot' protect_from_forgery with: :null_session before_action :validate_signature def validate_signature body = request.body.read signature = request.env['HTTP_X_LINE_SIGNATURE'] unless client.validate_signature(body, signature) error 400 do 'Bad Request' end end end def client @client ||= Line::Bot::Client.new { |config| config.channel_secret = ENV['LINE_CHANNEL_SECRET'] config.channel_token = ENV['LINE_CHANNEL_TOKEN'] } end end
linebot_controller
class LinebotController < ApplicationController def callback body = request.body.read events = client.parse_events_from(body) events.each { |event| case event when Line::Bot::Event::Message case event.type when Line::Bot::Event::MessageType::Text message = { type: 'text', text: event.message['text'] } client.reply_message(event['replyToken'], message) end end } head :ok end end
routes
Rails.application.routes.draw do post '/callback' => 'linebot#callback' end
回答1件
あなたの回答
tips
プレビュー