yuripeyamashita commited on
Commit
13edd55
1 Parent(s): 5f02930

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -20,9 +20,9 @@ def api():
20
  try:
21
  payload = get_payload_dict(request.get_json())
22
  print(payload)
23
- get_username(payload.get("group_id"), payload.get("user_id"))
24
- # res_text = opai.private_translate_api(payload.get("msg_text"))
25
- # send_text(payload.get("token"), res_text)
26
  except:
27
  pass
28
  return "", 200
@@ -62,10 +62,13 @@ def send_text(token, text):
62
  ]
63
  })
64
 
65
- def get_username(groupId, userId):
66
- url = f"https://api.line.me/v2/bot/group/{groupId}/member/{userId}"
67
- res = requests.get(url, headers={"Authorization": "Bearer " + LINE_CHANNEL_ACCESS_TOKEN})
68
- print(res.json())
 
 
 
69
 
70
 
71
  if __name__ == "__main__":
 
20
  try:
21
  payload = get_payload_dict(request.get_json())
22
  print(payload)
23
+ username = get_username(payload)
24
+ print(username)
25
+ send_text(payload.get("token"), f"{username}:{payload.get("msg_text")}")
26
  except:
27
  pass
28
  return "", 200
 
62
  ]
63
  })
64
 
65
+ def get_username(payload):
66
+ url = f"https://api.line.me/v2/bot/group/{payload.get("group_id")}/member/{payload.get("user_id")}"
67
+ try:
68
+ res_json = requests.get(url, headers={"Authorization": "Bearer " + LINE_CHANNEL_ACCESS_TOKEN}).json()
69
+ return res_json.get("displayName")
70
+ except:
71
+ return "Unknow"
72
 
73
 
74
  if __name__ == "__main__":