Azure-Samples / contoso-real-estate

Intelligent enterprise-grade reference architecture for JavaScript, featuring OpenAI integration, Azure Developer CLI template and Playwright tests.
MIT License
858 stars 512 forks source link

feat: add realtime notification feature #431

Closed xingsy97 closed 6 months ago

xingsy97 commented 7 months ago

Summary

add realtime notification feature for portal powered by Azure Web PubSub For Socket.IO

This draft PR doesn't contain azure deployment code. So user have to use a pre-created Web PubSub resource, manually replace endpoint in packages/portal and add connection string in packages/realtime

How to use

  1. Create a Web PubSub For Socket.IO resource.
  2. Click key tab in resource portal, copy connection string.
  3. Rename .env.example under packages/realtime/ to .env. Then fill in copied connection string to variable WebPubSubConnectionString
  4. Copy the endpoint part in connection string (e.g. https://<resource-name>.webpubsub.azure.com). And use it replace the default endpoint in packages/portal/src/app/shared/realtime.service.ts:L14
  5. Follow original README to go on.

Feature specification

The realtime notification has four scenarios as cited below. See complete specification in the internal doc.

Use-case 1 – Anonymous user favorites a listing

Given an anonymous user is browsing the application. When an authenticated user clicks on the "Favorite" button for a listing named [listing-name]. Then a real-time notification is sent via Azure Web PubSub and Socket.io. And the notification message displayed is: "A user has favorited the listing [listing-name]."

Use-case 2 – Authenticated user favorites a listing

Given an authenticated user is logged into the application. When the user clicks on the "Favorite" button for a listing named [listing-name]. Then a real-time notification is sent via Azure Web PubSub and Socket.io. And the notification message displayed is: "Hurry up! Another user has favorited the listing [listing-name]."

Use-case 3 – Authenticated user has started a booking process but didn’t complete a payment

Given an authenticated user is logged into the application. When the user attempts to book a listing named [listing-name] but doesn't complete the payment process. Then a real-time notification is sent via Azure Web PubSub and Socket.io. And the notification message displayed is: "Hurry up! Another user has booked the listing [listing-name] but didn't complete the payment."

Use-case 4 – Authenticated user receives a notification about unavailable listing

Given an authenticated user is logged into the application. And the user has favorited a listing named [listing-name]. When the listing [listing-name] is booked by another user and becomes unavailable between the dates [dates]. Then a real-time notification is sent via Azure Web PubSub and Socket.io. And the notification message displayed is: "[Listing-name] in your favorites has been booked and it's no longer available between the dates [dates]."

Other reference

https://learn.microsoft.com/en-us/azure/azure-web-pubsub/socketio-migrate-from-self-hosted

anfibiacreativa commented 6 months ago

@manekinekko what's the current status? Can we proceed to merge without refactoring changes?

manekinekko commented 6 months ago

I was working on adding bicep/azd iac part of this PR, but I am hitting a blocking issue. I am going to merge this PR as-is and will add bicep/azd deployment in a different PR. Will also refactor code in a separate PR.

anfibiacreativa commented 6 months ago

I was working on adding bicep/azd iac part of this PR, but I am hitting a blocking issue. I am going to merge this PR as-is and will add bicep/azd deployment in a different PR. Will also refactor code in a separate PR.

Agreed. Can we merge before the event coming up?