kenken999 commited on
Commit
6e9fd94
1 Parent(s): a83d2be
Files changed (1) hide show
  1. mysite/routers/fastapi.py +28 -1
mysite/routers/fastapi.py CHANGED
@@ -52,6 +52,24 @@ def include_routers(app):
52
  logger.error(f"An error occurred: {e}")
53
  from datetime import datetime
54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  #from routers.webhooks import router
56
  def setup_webhook_routes(app: FastAPI):
57
  from polls.routers import register_routers
@@ -85,6 +103,10 @@ def setup_webhook_routes(app: FastAPI):
85
 
86
  webhook_url = os.getenv("chat_url")
87
  token = os.getenv("token")
 
 
 
 
88
  thread_name=""
89
  #return
90
  #url = github(token,foldername)
@@ -93,6 +115,11 @@ def setup_webhook_routes(app: FastAPI):
93
  if event["type"] == "message" and event["message"]["type"] == "text":
94
  user_id = event["source"]["userId"]
95
  text = event["message"]["text"]
 
 
 
 
 
96
  #logger.info("------------------------------------------")
97
  first_line = text.split('\n')[0]
98
  #logger.info(f"User ID: {user_id}, Text: {text}")
@@ -204,7 +231,7 @@ def setup_webhook_routes(app: FastAPI):
204
  #########################################################################
205
 
206
  title = f""" 質問内容を元に答えを出します {promps}"""
207
- subtitle = f"""ユーザー{user_id} から申し込みがありました \r\n 質問内容 {text}"""
208
  link_text = "データを確認する"
209
  link_url = "https://kenken999-php.hf.space/diamondprice_list.php"
210
  #test_set_lide(subtitle, text)
 
52
  logger.error(f"An error occurred: {e}")
53
  from datetime import datetime
54
 
55
+
56
+ def get_user_profile(user_id, access_token):
57
+ url = f'https://api.line.me/v2/bot/profile/{user_id}'
58
+ headers = {
59
+ 'Authorization': f'Bearer {access_token}'
60
+ }
61
+
62
+ response = requests.get(url, headers=headers)
63
+ if response.status_code == 200:
64
+ profile = response.json()
65
+ user_name = profile.get('displayName')
66
+ user_thumbnail = profile.get('pictureUrl')
67
+ return user_name, user_thumbnail
68
+ else:
69
+ print(f"Failed to get user profile: {response.status_code}, {response.text}")
70
+ return None, None
71
+
72
+
73
  #from routers.webhooks import router
74
  def setup_webhook_routes(app: FastAPI):
75
  from polls.routers import register_routers
 
103
 
104
  webhook_url = os.getenv("chat_url")
105
  token = os.getenv("token")
106
+
107
+
108
+
109
+
110
  thread_name=""
111
  #return
112
  #url = github(token,foldername)
 
115
  if event["type"] == "message" and event["message"]["type"] == "text":
116
  user_id = event["source"]["userId"]
117
  text = event["message"]["text"]
118
+ user_name,thmbnail = get_user_profile(user_id,token)
119
+
120
+ logger.info("Received Headers: %s", user_name)
121
+ logger.info("Received Headers: %s", thmbnail)
122
+
123
  #logger.info("------------------------------------------")
124
  first_line = text.split('\n')[0]
125
  #logger.info(f"User ID: {user_id}, Text: {text}")
 
231
  #########################################################################
232
 
233
  title = f""" 質問内容を元に答えを出します {promps}"""
234
+ subtitle = f"""ユーザーID {user_id} \r\n から申し込みがありました \r\n 質問内容 {text}"""
235
  link_text = "データを確認する"
236
  link_url = "https://kenken999-php.hf.space/diamondprice_list.php"
237
  #test_set_lide(subtitle, text)