Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@sugyan
Created April 8, 2016 08:54
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 sugyan/d8cf954830a723fb1f3b22fc60462615 to your computer and use it in GitHub Desktop.
Save sugyan/d8cf954830a723fb1f3b22fc60462615 to your computer and use it in GitHub Desktop.
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