Last active
August 17, 2016 09:20
-
-
Save caherrerapa/3f76c29181451c56cc61edd9ae9adb1e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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