Skip to content

Instantly share code, notes, and snippets.

@gyosit
Last active March 25, 2018 09:27
Show Gist options
  • Save gyosit/fff0f2a399bbf03b4dad45ded1ba12f0 to your computer and use it in GitHub Desktop.
Save gyosit/fff0f2a399bbf03b4dad45ded1ba12f0 to your computer and use it in GitHub Desktop.
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