Skip to content

Instantly share code, notes, and snippets.

@caherrerapa
Last active August 17, 2016 09:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caherrerapa/3f76c29181451c56cc61edd9ae9adb1e to your computer and use it in GitHub Desktop.
Save caherrerapa/3f76c29181451c56cc61edd9ae9adb1e to your computer and use it in GitHub Desktop.
require 'line/bot'
class CallbacksController < ApplicationController
def event_handler
signature = request.env['HTTP_X_LINE_CHANNELSIGNATURE']
unless client.validate_signature(request.body.read, signature)
error 400 do 'Bad Request' end
end
receive_request = Line::Bot::Receive::Request.new(request.env)
receive_request.data.each { |message|
case message.content
when Line::Bot::Message::Text
res = client.send_text(
to_mid: message.from_mid,
text: "Hola"
)
end
}
render :nothing => true, status: :ok
end
def client
client ||= Line::Bot::Client.new do |config|
config.channel_id = ENV.fetch('LINE_CHANNEL_ID')
config.channel_secret = ENV.fetch('LINE_CHANNEL_SECRET')
config.channel_mid = ENV.fetch('LINE_CHANNEL_MID')
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment