Skip to content

Commit

Permalink
fix: try の設置
Browse files Browse the repository at this point in the history
  • Loading branch information
duri0214 committed May 3, 2024
1 parent e4ca4ce commit 3f8982f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions linebot/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ def callback(request):
"""ラインの友達追加時に呼び出され、ラインのIDを登録する"""
if request.method == "POST":
request_json = json.loads(request.body.decode("utf-8"))
events = request_json["events"]
print(f"events: {events}")
line_user_id = events[0]["source"]["userId"]
events = request_json["events"][0]
line_user_id = None
try:
line_user_id = events["source"]["userId"]
except IndexError:
print(f"events: {events}")
return HttpResponse("ng", status=400)

# webhook connection check at fixed id 'Udea...beef'
if line_user_id != "Udeadbeefdeadbeefdeadbeefdeadbeef":
Expand Down

0 comments on commit 3f8982f

Please sign in to comment.