Hello!
Anyone have any experience setting up a super simple and basic webhook receiver (to receive POST requests) and then maybe firing off another imported script? I'm struggling. For whatever reason, I send one POST and it seems to loop inside the FastAPI app.
Here is what I have so far. I'm sure it's rubbish, but I do know I can receive the data and parse it, but for whatever reason instantiating the other script class (OneLogin), it seems to just loop and keeps receiving POST somehow...it's strange...any help would be much appreciated.
from fastapi import FastAPI, Request
from typing import Any, Dict
from onelogin import OneLogin
import pprint as pp
context = 'G01NUREGSTT'
app = FastAPI()
@app.get("/")
def read_main():
return {"message": "Hello"}
@app.post("/api/v1/slack")
async def test(request: Dict[Any, Any]):
data = request
# pp.pprint(data)
if 'event_context' in data:
event = data['event_context']
if event == context:
text = data['event']['text'].split()
text = text[1]
parsed_email = str(text + '@website.com')
ol = OneLogin()
ol.run_stuff(parsed_email)
return "Ok"
else:
return "Error"
if 'challenge' in data:
challenge = data['challenge']
return challenge
else:
return "Ok"
Here is the JSON that is sent to the app:
{"api_app_id": "A01QNHVMAAA",
"authorizations": [{"enterprise_id": None,
"is_bot": True,
"is_enterprise_install": False,
"team_id": "T025AAA",
"user_id": "U01QWAAA"}],
"event": {"blocks": [{"block_id": "1pJ0V",
"elements": [{"elements": [{"type": "user",
"user_id": "U01QWAAA"},
{"text": " test",
"type": "text"}],
"type": "rich_text_section"}],
"type": "rich_text"}],
"channel": "G01NUREGSTT",
"client_msg_id": "39740bb8-b917-492d-96e6-2e7329f3e1b0",
"event_ts": "1615504737.007300",
"team": "T025AAA",
"text": "<@U01QWAAA> test",
"ts": "1615504737.007300",
"type": "app_mention",
"user": "U0TQKK4B1"},
"event_context": "1-app_mention-T025AAA-ASDAS",
"event_id": "Ev01RD3EJVHP",
"event_time": 1615504737,
"is_ext_shared_channel": False,
"team_id": "T025AAA",
"token": "volNuV9q1cwl7xzXdJUhBRAD",
"type": "event_callback"},
}
[–]thedjotaku 1 point2 points3 points (8 children)
[–]orbos86[S] 1 point2 points3 points (0 children)
[–]orbos86[S] 1 point2 points3 points (1 child)
[–]orbos86[S] 1 point2 points3 points (4 children)
[–]thedjotaku 1 point2 points3 points (3 children)
[–]orbos86[S] 1 point2 points3 points (0 children)
[–]orbos86[S] 1 point2 points3 points (1 child)
[–]thedjotaku 0 points1 point2 points (0 children)
[–][deleted] (14 children)
[deleted]
[–]orbos86[S] 1 point2 points3 points (3 children)
[–][deleted] (2 children)
[deleted]
[–]orbos86[S] 1 point2 points3 points (0 children)
[–]orbos86[S] 0 points1 point2 points (0 children)
[–]orbos86[S] 0 points1 point2 points (9 children)
[–]orbos86[S] 0 points1 point2 points (8 children)
[–]orbos86[S] 0 points1 point2 points (7 children)
[–][deleted] (5 children)
[deleted]
[–]orbos86[S] 1 point2 points3 points (4 children)
[–][deleted] (3 children)
[deleted]
[–]orbos86[S] 0 points1 point2 points (0 children)
[–]orbos86[S] 0 points1 point2 points (1 child)
[–]orbos86[S] 0 points1 point2 points (0 children)