Skip to content

Commit

Permalink
update HttpResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
duri0214 committed May 3, 2024
1 parent aa6a90d commit d85df90
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions linebot/views.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
"""views.py"""

import json

from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt

from .models import LinePush


@csrf_exempt
def callback(request):
"""ラインの友達追加時に呼び出され、ラインのIDを登録する"""
if request.method == 'POST':
request_json = json.loads(request.body.decode('utf-8'))
events = request_json['events']
line_user_id = events[0]['source']['userId']
if request.method == "POST":
request_json = json.loads(request.body.decode("utf-8"))
events = request_json["events"]
line_user_id = events[0]["source"]["userId"]

# webhook connection check at fixed id 'Udea...beef'
if line_user_id != 'Udeadbeefdeadbeefdeadbeefdeadbeef':
if line_user_id != "Udeadbeefdeadbeefdeadbeefdeadbeef":
# follow || unblock
if events[0]['type'] == 'follow':
if events[0]["type"] == "follow":
LinePush.objects.create(line_user_id)
# block
if events[0]['type'] == 'unfollow':
if events[0]["type"] == "unfollow":
LinePush.objects.filter(line_user_id).delete()

return HttpResponse()
return HttpResponse("ok")

0 comments on commit d85df90

Please sign in to comment.