-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
11 additions
and
8 deletions.
There are no files selected for viewing
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
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") |