serJD commited on
Commit
d14a2df
·
1 Parent(s): 09372ef

another try reading webhook json

Browse files
Files changed (1) hide show
  1. app.py +19 -1
app.py CHANGED
@@ -15,6 +15,7 @@ from specklepy.api import operations
15
  from specklepy.objects.geometry import Polyline, Point
16
 
17
  from huggingface_hub import webhook_endpoint, WebhookPayload
 
18
 
19
  import requests
20
  import datetime
@@ -213,7 +214,24 @@ streams = {
213
 
214
  # Function to run on button click
215
  @webhook_endpoint # Define a unique endpoint URL
216
- async def update_streams():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
217
  print("trying to print request msg")
218
  speckle_token = os.environ.get("SPECKLE_TOKEN")
219
  notion_token = os.environ.get("NOTION_TOKEN")
 
15
  from specklepy.objects.geometry import Polyline, Point
16
 
17
  from huggingface_hub import webhook_endpoint, WebhookPayload
18
+ from fastapi import Request
19
 
20
  import requests
21
  import datetime
 
214
 
215
  # Function to run on button click
216
  @webhook_endpoint # Define a unique endpoint URL
217
+ async def update_streams(request: Request):
218
+ # Read the request body as JSON
219
+ payload = await request.json()
220
+
221
+ # Extract data from the payload
222
+ stream_id = payload.get('streamId')
223
+ user_id = payload.get('userId')
224
+ activity_message = payload.get('activityMessage')
225
+
226
+ # Accessing nested data in the 'event' object
227
+ event_name = payload['event']['event_name']
228
+ old_data = payload['event']['data']['old']
229
+ new_data = payload['event']['data']['new']
230
+
231
+ # Example of using the extracted data
232
+ print(f"Event Name: {event_name}")
233
+ print(f"Old Stream Name: {old_data['name']}")
234
+ print(f"New Stream Description: {new_data['description']}")
235
  print("trying to print request msg")
236
  speckle_token = os.environ.get("SPECKLE_TOKEN")
237
  notion_token = os.environ.get("NOTION_TOKEN")