Last active
March 25, 2018 09:27
-
-
Save gyosit/fff0f2a399bbf03b4dad45ded1ba12f0 to your computer and use it in GitHub Desktop.
This file contains 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
post '/callback' do #POSTを受けるURL(後述) | |
body = request.body.read #上記のjsonを読み込む | |
events = client.parse_events_from(body) | |
events.each { |event| | |
case event | |
when Line::Bot::Event::Follow #フォローイベント | |
userid = event['source']['userId'] #userId取得 | |
user = User.new | |
user.UserId = userid | |
user.save | |
message = { type: 'text', text: '登録しました' } | |
client.push_message(user.userId, message) #push送信 | |
when Line::Bot::Event::Unfollow #フォロー解除(ブロック) | |
userid = event['source']['userId'] | |
user = User.find_by(userId: userid) | |
user.destroy | |
end | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment