# Plastic Free - next step
API Custom
- Aggiungere event listener
- Nei seguenti punti aggiungere l'event emitter (es:
- a -->`Event.emit('new:newsletter', { id: 1 })`
- b -->`Event.emit('new:user', { user_id: 1 })`
- il listener spara tramite consumer su SQS con il seguente payload
```json=
{
TODO 7 Payload
}
```
## notification-api-history-express
### GET /api/notifications/:user_id
Query params:
- **page**: number, opzionale, default=0, min=0
- **per_page**: number, opzionale, default=10, min=1, max=100
- **only_unread**: boolean, opzionale, default=false
- **type**: NotificationType, opzionale, default=all
```json=
# response
{
messages: [
{
text: string,
action: {
entity: NotificationType,
type: enumTypeMessage,
payload: {
chiave: valore,
}
},
read: boolean
},
...
],
pagination: {
totalCount: number
}
}
```
### PUT /api/notifications/:user_id/:message_id
```json=
# response
{
error: boolean
}
```
### DELETE /api/notifications/:user_id
```json=
# response
{
error: boolean
}
```
## Mongo schema
```json=
[
{
"_id": { "$oid": "62c7d3475c05f31d0cc0f508" },
// SQS info
"MessageId" : "44a1ec29-0e2c-4fa4-a508-dfcae7b94a3e", // unique
"ReceiptHandle" : "44a1ec29-0e2c-4fa4-a508-dfcae7b94a3e#379305ab-558f-417b-a184-e2f4fd4f5bf6",
"MD5OfBody" : "9a0a2b0aefd6ec7647ed51956ed23e4d",
// Message payload
"userId": 24, // index
"type": "expiring-subscriptions", // NotificationType
"text": {
"key": "user.expiring-subscriptions",
"payload": {}
}
"action": {
"entity": "subscriptions", // ActionEntity
"type": "redirect", // ActionType
"payload": {
"expiringDate": "2022-07-08"
}
},
"readAt": "2022-07-08 12:33:23", // nullable
"createdAt": "2022-07-08 10:33:23" // index
},
...
]
```
```typescript=
enum NotificationType {
NEW_REFERENT_CANDIDACY = 'new-referent-candidacy', // NT1
PENDING_REFERENT_CANDIDACIES = 'pending-referent-candidacy', // NT2
EXPIRING_SUBSCRIPTIONS = 'expiring-subscriptions', // NT3
CLEANUP_EVENT_MODIFIED = 'event-cleanup-modified', // NT4A
CLEANUP_EVENT_CANCELED = 'event-cleanup-canceled', // NT4B
UPCOMING_CLEANUP_EVENTS_REMINDER = 'upcoming-events-cleanup-reminder', // NT5
INTERNAL_ARTICLE = 'internal-article', // NT7
}
enum ActionEntity {
CANDIDACIES = 'candidacies',
SUBSCRIPTION = 'subscription',
EVENTS = 'events',
EVENT = 'event',
INTERNAL_ARTICLE = 'internal_article'
}
enum ActionType {
REDIRECT = "redirect"
POPUP = "popup"
}
```
## Gestione notifiche da CMS (messaggio da CMS a Notification trigger sqs)
```typescript=
{
"type": "", // NotificationType
"payload": {...}
}
// NT1
{
"type": "new-referent-candidacy",
"payload": {
"candidacy_id": 14
}
}
// NT2
{
"type": "pending-referent-candidacy",
"payload": {
"candidacy_ids": [1, 2, 3, 4, 5]
}
}
// NT3
{
"type": "expiring-subscriptions", // 14-07-2022: modificato da "subscriptions-expired"
"payload": {
"expired_at": "2022-08-12"
}
}
// NT4A
{
"type": "event-cleanup-modified",
"payload": {
"event_id": 1,
"old": {
"location_id": 4
"date": "2022-08-02",
"time": "13:00",
"meeting_point": "A san Siro"
},
"new": {
"location_id": 10
"date": "2022-08-02",
"time": "16:00",
"meeting_point": "A san Siro"
}
}
}
// NT4B
{
"type": "event-cleanup-canceled",
"payload": {
"event_id": 1
}
}
// NT5
{
"type": "upcoming-events-cleanup-reminder"
}
// NT6 // NON IN SPRINT!!!
{
"type": "weekly-events-cleanup-reminder"
}
// NT7
{
"type": "internal-article",
"payload": {
"internal_article_id": 1
}
}
```
## Gestione notifiche da Notification center coda messaggi
```json=
// NT1
{
"type": "new-referent-candidacy",
"user_id": 1,
"text": {
"key": "user.new-referent-candidacy",
"payload": {
"name": "Aldo"
}
},
"action": {
"entity": "dove-si-vede-la-singola-candidatura", // ActionEntity
"type": "redirect", // ActionType
"payload": {
"candidacy_id": 3
}
}
}
// NT2
{
"type": "pending-referent-candidacy",
"user_id": 1,
"text": {
"key": "user.pending-referent-candidacy",
"payload": {
"name": "Admin Aldo"
}
},
"action": {
"entity": "dove-si-vedono-le-candidature", // ActionEntity
"type": "redirect", // ActionType
"payload": {}
}
}
// NT3
{
"type": "expiring-subscriptions", // 14-07-2022: modificato da "subscriptions-expired"
"user_id": 1,
"text": {
"key": "user.expiring-subscriptions",// 14-07-2022: modificato da "user.expiring-subscriptions"
"payload": {
"name": "Alberto",
"expiration_date": "2022-08-08"
}
},
"action": {
"entity": "al-banner-in-dashboard", // ActionEntity
"type": "redirect", // ActionType
"payload": {}
}
}
// NT4A
{
"type": "event-cleanup-modified",
"user_id": 1,
"text": {
"key": "user.event-cleanup-modified",
"payload": {
"name": "Alberto"
"old_location": "Roma"
"old_start_date": "2022-08-03"
"location"?: "Milano"
"meeting_point"?: "A san Siro, nel parcheggio", // optional
"start_date"?: "2022-08-08",// optional
"start_time"?: "13:00" // optional
}
},
"action": {
"entity": "a-pagina-evento", // ActionEntity
"type": "redirect", // ActionType
"payload": {
"event_id": 4
}
}
}
// NT4B
{
"type": "event-cleanup-canceled",
"user_id": 1,
"text": {
"key": "user.event-cleanup-canceled",
"payload": {
"name": "Alberto"
"old_location": "Roma"
"old_start_date": "2022-08-03"
}
},
"action": {
"entity": "a-dettaglio-evento-eliminato", // ActionEntity
"type": "redirect", // ActionType
"payload": {
"event_id": 4
}
}
}
//NT5
{
"type": "upcoming-event-cleanup-reminder",
"user_id": 1,
"text": {
"key": "user.upcoming-cleanup-event-reminder",
"payload": {
"name": "Alberto"
"location": "Roma"
}
},
"action": {
"entity": "a-dettaglio-evento", // ActionEntity
"type": "redirect", // ActionType
"payload": {
"event_id": 4
}
}
}
//NT7
{
"type": "internal-article",
"user_id": 1,
"text": {
"key": "user.internal-article"
},
"action": {
"entity": "internal-article", // ActionEntity
"type": "redirect", // ActionType
"payload": {
"internal_article_id": 1
}
}
}
```
## Gestione notifiche da Notification center coda email
```json=
// Tutte le tipologie di email
{
"type": "new-referent-candidacy",
"email": "alberto.test@mail.com",
"subject": "Nuovo referente!"
"body": "Ciao Aldo, <br/>hai ricevuto una nuova candidatura per la tua regione. <br/> Dai un'occhiata alla piattaforma e ricorda di contattare il candidato entro 72h",
"unsubscribe": "https://plasticfreeonlus.it/poi-capiamo"
}
```
## Riposta parziale delle query per i messaggi su CMS (utile per i payload)
```json=
/*NT1 - nuovo referente*/
{
"text":
{
"key": "user.new-referent-candidacy",
"payload": null,
},
"action":
{
"entity": "candidacies",
"type": "REDIRECT",
"payload":[{
"key": "candidacy_id",
"value": 1
}]
}
}
/*NT2 - candidature in pending da più di 10 giorni*/
{
"text":
{
"key": "user.pending-referent-candidacy",
"payload": null,
},
"action":
{
"entity": "candidacies",
"type": "REDIRECT",
"payload": null,
}
}
/*NT3 - sottoscrizione in scadenza*/
{
"text":
{
"key": "user.expiring-subscriptions",
"payload": [{
"key": "expired_at",
"value": "2023-05-25"
}],
},
"action":
{
"entity": "subscription",
"type": "REDIRECT",
"payload": null
}
}
/*NT4A - modifica a evento di cleanup*/
{
"text":
{
"key": "user.event-cleanup-modified",
"payload": null,
},
"action":
{
"entity": "event",
"type": "REDIRECT",
"payload":[{
"key": "event_id",
"value": 1
}]
}
}
/*NT4B - cancellazione evento di cleanup*/
{
"text":
{
"key": "user.event-cleanup-canceled",
"payload": null,
},
"action":
{
"entity": "event",
"type": "POPUP",
"payload":[{
"key": "location",
"value": "Milano"
},{
"key": "start_date",
"value": "2023-05-25"
},{
"key": "start_time",
"value": "10:30"
},{
"key": "meeting_point",
"value": "in piazza"
},{
"key": "referent",
"value": "Mario Rossi"
}]
}
}
/*NT5 - reminder (24 ore prima) evento di clean up*/
{
"text":
{
"key": "user.upcoming-event-cleanup-reminder",
"payload": null,
},
"action":
{
"entity": "event",
"type": "REDIRECT",
"payload":[{
"key": "event_id",
"value": 4
}]
}
}
/*NT7 - reminder (24 ore prima) evento di clean up*/
{
"text":
{
"key": "user.internal-article",
"payload": null,
},
"action":
{
"entity": "internal-article",
"type": "REDIRECT",
"payload":[{
"key": "internal_article_id",
"value": 1
}]
}
}
```
## ECR repositories
```
559033801479.dkr.ecr.eu-central-1.amazonaws.com/notification-system/api-messages
559033801479.dkr.ecr.eu-central-1.amazonaws.com/notification-system/queue-emails
559033801479.dkr.ecr.eu-central-1.amazonaws.com/notification-system/queue-messages
559033801479.dkr.ecr.eu-central-1.amazonaws.com/notification-system/service
```