Created
April 8, 2016 08:54
-
-
Save sugyan/d8cf954830a723fb1f3b22fc60462615 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 'sinatra' | |
require 'json' | |
get '/send' do | |
text = params[:text] | |
send(text) unless text.nil? | |
'OK' | |
end | |
post '/callback' do | |
logger.info(request.body.read) | |
end | |
def send(text) | |
uri = URI('https://trialbot-api.line.me/v1/events') | |
Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http| | |
headers = { | |
'Content-Type' => 'application/json', | |
'X-Line-ChannelID' => ENV['LINE_CHANNEL_ID'], | |
'X-Line-ChannelSecret' => ENV['LINE_CHANNEL_SECRET'], | |
'X-Line-Trusted-User-With-ACL' => ENV['LINE_MID'] | |
} | |
req = Net::HTTP::Post.new(uri.path, headers) | |
req.body = { | |
to: [ENV['TARGET_MID']], | |
toChannel: 1_383_378_250, | |
eventType: '138311608800106203', | |
content: { | |
contentType: 1, | |
toType: 1, | |
text: text | |
} | |
}.to_json | |
http.request(req) do |res| | |
logger.info(res.body) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment