Virtual-Coffee / webhooks

Repo/Netlify App for responding to various webhooks
1 stars 2 forks source link

Make `participant.joined` and `participant.left` retry logic into a background function #20

Closed ebanner closed 5 months ago

ebanner commented 5 months ago

Make participant.joined and participant.left retry logic into a background function

Fixes https://github.com/Virtual-Coffee/webhooks/issues/15

This change makes it so we fire off a request to the participant joined/left retry logic in a background function then return immediately to zoom so zoom doesn't send a retry request

Currently, we perform retry logic within the initial zoom request, which is ostensibly causing zoom to time out

This PR is a WIP

Glaring TODO

Don't hardcode my local URL as APP_HOST

https://github.com/Virtual-Coffee/webhooks/pull/20/files#diff-fd3a3971ff32072dc258467648a607790c47e180b8b82e0b426b53c9ea9d8afeR101

ebanner commented 5 months ago

Hm, actually I'm a bit confused why the call to the background function isn't returning immediately

CALLING handle-participant-joined-background
◈ Rewrote URL to /.netlify/functions/handle-participant-joined-background
Request from ::1: POST /.netlify/functions/handle-participant-joined-background
◈ Queueing background function handle-participant-joined-background for execution
Response with status 202 in 1 ms.
PRINTING REQUEST FROM handle-participant-joined-background
{
  "payload": {
    "account_id": "dkurTIDzTnmj2IvieCpGGA",
    "object": {
      "uuid": "HBhOvHtqRii2FwJjyBcwng==",
      "participant": {
        "user_id": "16778240",
        "user_name": "Eddie B",
        "participant_user_id": "MRL6VzvZRQGOJCCvrgTKww",
        "id": "MRL6VzvZRQGOJCCvrgTKww",
        "join_time": "2024-04-30T20:36:14Z",
        "email": "edward.banner@gmail.com",
        "participant_uuid": "973BEB67-0F15-1F27-2802-98709162FB1F"
      },
      "id": "9904589180",
      "type": 4,
      "topic": "Eddie B's Personal Meeting Room",
      "host_id": "MRL6VzvZRQGOJCCvrgTKww",
      "duration": 0,
      "start_time": "2024-04-30T20:36:15Z",
      "timezone": "America/New_York"
    }
  },
  "event_ts": 1714509377831,
  "event": "meeting.participant_joined"
}
EXITING IMMEDIATELY FROM zoom-meeting-webhook-handler

I feel like the EXITING IMMEDIATELY should be printed right away, not after the background function completes

It's weird because it does say Response with status 202 in 1 ms. immediately. But that's something that's just getting printed internally by netlify, not via console.log()

So this current code as it stands could still be blocking 🤔

ebanner commented 5 months ago

Oh nevermind. We good 👍

I put a long timeout in the background function to test it and got it to print in the expected order

CALLING handle-participant-joined-background
◈ Rewrote URL to /.netlify/functions/handle-participant-joined-background
Request from ::1: POST /.netlify/functions/handle-participant-joined-background
◈ Queueing background function handle-participant-joined-background for execution
Response with status 202 in 0 ms.
EXITING IMMEDIATELY FROM zoom-meeting-webhook-handler
Response with status 200 in 277 ms.
PRINTING REQUEST FROM handle-participant-joined-background
{
  "payload": {
    "account_id": "dkurTIDzTnmj2IvieCpGGA",
    "object": {
      "uuid": "PyNS75lIQby+Jg9MeKEKTQ==",
      "participant": {
        "leave_time": "2024-04-30T20:55:44Z",
        "user_id": "16778240",
        "user_name": "Eddie B",
        "registrant_id": "",
        "participant_user_id": "MRL6VzvZRQGOJCCvrgTKww",
        "id": "MRL6VzvZRQGOJCCvrgTKww",
        "leave_reason": "left the meeting. Reason : Host ended the meeting.",
        "email": "edward.banner@gmail.com",
        "participant_uuid": "BF89AE4D-053B-7FF7-239B-6C2BACE2337B"
      },
      "id": "9904589180",
      "type": 4,
      "topic": "Eddie B's Personal Meeting Room",
      "host_id": "MRL6VzvZRQGOJCCvrgTKww",
      "duration": 0,
      "start_time": "2024-04-30T20:55:02Z",
      "timezone": "America/New_York"
    }
  },
  "event_ts": 1714510547173,
  "event": "meeting.participant_left"
}
found room instance rechs8vV9QampWqeH
Successfully send message 1714510558.246159 in conversation C04C5AVUMQF
◈ Done executing background function handle-participant-joined-background