Skip to content

Instantly share code, notes, and snippets.

@roger35972134
Last active December 15, 2017 09:01
Show Gist options
  • Save roger35972134/90e21f8dac3f92b7c2f1d177ef04846f to your computer and use it in GitHub Desktop.
Save roger35972134/90e21f8dac3f92b7c2f1d177ef04846f to your computer and use it in GitHub Desktop.
class CurrencyController < ApplicationController
require 'line/bot'
def client
@client ||= Line::Bot::Client.new { |config|
config.channel_secret = ENV["LINE_CHANNEL_SECRET"] # Your Channel secret
config.channel_token = ENV["LINE_CHANNEL_TOKEN"] # Your Channel token
}
end
# post '/webhook' do
def webhook
client
body = request.body.read
puts body
signature = request.env['HTTP_X_LINE_SIGNATURE']
unless client.validate_signature(body, signature)
error 400 do 'Bad Request' end
end
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
query = event.message['text']
res = Currency.search_by_abbreviation(query)
message = {
type: 'text',
text: res
}
client.reply_message(event['replyToken'], message)
end
end
}
"OK"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment