yuripeyamashita
commited on
Commit
•
0a39678
1
Parent(s):
6a17841
Update app.py
Browse files
app.py
CHANGED
@@ -20,6 +20,7 @@ def api():
|
|
20 |
try:
|
21 |
payload = get_payload_dict(request.get_json())
|
22 |
print(payload)
|
|
|
23 |
# res_text = opai.private_translate_api(payload.get("msg_text"))
|
24 |
# send_text(payload.get("token"), res_text)
|
25 |
except:
|
@@ -31,7 +32,8 @@ def get_payload_dict(raw_payload):
|
|
31 |
print(raw_payload)
|
32 |
token = raw_payload.get("events", [{}])[0].get("replyToken")
|
33 |
sender_type = raw_payload.get("events", [{}])[0].get("source", {}).get("type", "user")
|
34 |
-
|
|
|
35 |
msg_type = raw_payload.get("events", [{}])[0].get("message", {}).get("type")
|
36 |
msg_id = raw_payload.get("events", [{}])[0].get("message", {}).get("id")
|
37 |
msg_text = raw_payload.get("events", [{}])[0].get("message", {}).get("text")
|
@@ -39,7 +41,8 @@ def get_payload_dict(raw_payload):
|
|
39 |
|
40 |
payload = {"token": token,
|
41 |
"sender_type": sender_type,
|
42 |
-
"
|
|
|
43 |
"msg_type": msg_type,
|
44 |
"msg_id": msg_id,
|
45 |
"msg_text": msg_text,
|
@@ -59,6 +62,11 @@ def send_text(token, text):
|
|
59 |
]
|
60 |
})
|
61 |
|
|
|
|
|
|
|
|
|
|
|
62 |
|
63 |
if __name__ == "__main__":
|
64 |
app.run(host="0.0.0.0", port=7860)
|
|
|
20 |
try:
|
21 |
payload = get_payload_dict(request.get_json())
|
22 |
print(payload)
|
23 |
+
get_username(payload.get("groupId"), payload.get("userId"))
|
24 |
# res_text = opai.private_translate_api(payload.get("msg_text"))
|
25 |
# send_text(payload.get("token"), res_text)
|
26 |
except:
|
|
|
32 |
print(raw_payload)
|
33 |
token = raw_payload.get("events", [{}])[0].get("replyToken")
|
34 |
sender_type = raw_payload.get("events", [{}])[0].get("source", {}).get("type", "user")
|
35 |
+
group_id = raw_payload.get("events", [{}])[0].get("source", {}).get("groupId")
|
36 |
+
user_id = raw_payload.get("events", [{}])[0].get("source", {}).get("userId")
|
37 |
msg_type = raw_payload.get("events", [{}])[0].get("message", {}).get("type")
|
38 |
msg_id = raw_payload.get("events", [{}])[0].get("message", {}).get("id")
|
39 |
msg_text = raw_payload.get("events", [{}])[0].get("message", {}).get("text")
|
|
|
41 |
|
42 |
payload = {"token": token,
|
43 |
"sender_type": sender_type,
|
44 |
+
"group_id": group_id,
|
45 |
+
"user_id": user_id,
|
46 |
"msg_type": msg_type,
|
47 |
"msg_id": msg_id,
|
48 |
"msg_text": msg_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__":
|
72 |
app.run(host="0.0.0.0", port=7860)
|