Files
directus/docs/reference/system/notifications.md
Jay Cammarano 25375cc481 Add notifications system and support user mentions in comments (#9861)
* v-menu de/activated onKeyDown. No List yet.

* v-list

* add user suggestion

* uuids replaced

* user-popover working

* avatars flex row with usernames in suggestions

* added space to end of uuid insert

* autofocus + move caret to end of last insert

* removed unnecessary setTimeout()

* fixed filter 500 with ids

* better fix

* New translations en-US.yaml (French) (#9907)

* New translations en-US.yaml (French) (#9912)

* New translations en-US.yaml (French) (#9916)

* New translations en-US.yaml (Russian) (#9918)

* New translations en-US.yaml (Swedish) (#9920)

* Email updates (#9921)

* add from name for emails

* updatd email template style

* reset password email copy

* updated logo to newest version

* update invite email copy

* decouple field template logic

* push up styling

* Start on new v-template-input

* Add notifications API endpoints

Squashed commit of the following:

commit 9d86721ef795d03bc55693c0f99bde8e269d60e9
Merge: b4458c19f 34131d06e
Author: rijkvanzanten <rijkvanzanten@me.com>
Date:   Mon Nov 22 09:27:43 2021 -0500

    Merge branch 'mentions' into mentions-api

commit b4458c19f7c54f18fa415fc04c63642c2f5a17b0
Author: rijkvanzanten <rijkvanzanten@me.com>
Date:   Thu Nov 18 18:34:04 2021 -0500

    Remove unused import

commit e6a9d36bbfdf95cb18d29336da61ecb14b677934
Author: rijkvanzanten <rijkvanzanten@me.com>
Date:   Thu Nov 18 18:28:31 2021 -0500

    Extract user mentions from comments

commit b3e571a2daa287e1740a050096913662a57e9861
Merge: c93b833d2 af2a6dd7f
Author: rijkvanzanten <rijkvanzanten@me.com>
Date:   Thu Nov 18 17:39:52 2021 -0500

    Merge branch 'mentions' into mentions-api

commit c93b833d2b848e306c434b370d4e4e11967e85d0
Author: rijkvanzanten <rijkvanzanten@me.com>
Date:   Thu Nov 18 17:35:45 2021 -0500

    Send emails w/ parsed MD

commit 64bbd6596f20a07028d2387d60e33dfe4f91c032
Author: rijkvanzanten <rijkvanzanten@me.com>
Date:   Thu Nov 18 16:18:16 2021 -0500

    Add notifications endpoint + permissions

commit fba55c02dc9c303a38b1b958350684cccd3dd82c
Author: rijkvanzanten <rijkvanzanten@me.com>
Date:   Thu Nov 18 15:33:28 2021 -0500

    Add system data for notifications

* push

* Make v-template-input work

* Add the two-way binding

* submit button posting, not clearing text area

* comment text area clearing on submit

* Replace insertion correctly

* Added scope support to LDAP group and user search (#9529)

* Added scope support LDAP group and user search

* Fixed linter screwing up my markdown

* Update docs/configuration/config-options.md

* Always return correct DN for user with sub scope

* Fix indeterminate meta and schema property in advanded field creation (#9924)

* Fix impossibility to save M2M (alterations not triggered) (#9992)

* Fix alterations refactor

* fix roles aggregate query (#9994)

* Update iis.md (#9998)

added the IIS URL Rewrite module as a requirement

* New translations en-US.yaml (English, United Kingdom) (#10001)

* Fix LDAP race condition (#9993)

* Fix input ui

* Revert changes to v-field-template

* Update mentions permissions

* Fix linter warnings

* Optimize sending flow

* Revert "Rename activity->notifications module (#9446)"

This reverts commit 428e5d4ea9.

* Add notifications drawer

* Update migrations

* Improve constraints

* Add email notifications toggle on users

* Add docs, fix graphql support

* Move caret-pos to devdeps

* Remove unused new triggerKeyPressed system

* Remove unused use-caret composable

Co-authored-by: Nitwel <nitwel@arcor.de>
Co-authored-by: Rijk van Zanten <rijkvanzanten@me.com>
Co-authored-by: Ben Haynes <ben@rngr.org>
Co-authored-by: Aiden Foxx <aiden.foxx@sbab.se>
Co-authored-by: Oreille <33065839+Oreilles@users.noreply.github.com>
Co-authored-by: Azri Kahar <42867097+azrikahar@users.noreply.github.com>
Co-authored-by: Paul Boudewijn <paul@helderinternet.nl>
2021-11-24 16:11:26 -05:00

8.3 KiB

pageClass
pageClass
page-reference

Notifications

Notifications allow you to send/receive messages to/from other users of the platform.

toc


The Notification Object

id integer
Primary key of the revision.

timestamp string
Timestamp in ISO8601 when the notification was created.

status string
Current status of the notification. One of "inbox", "archived".

recipient many-to-one
User that received the notification.

sender many-to-one
User that sent the notification, if any.

subject string
Subject line of the message.

message string
Notification's message content. Will be sent in the email.

collection string
Collection this notification references.

item string
Primary key of the item this notification references.

{
	"id": 2,
	"timestamp": "2021-11-24T13:57:35Z",
	"status": "inbox",
	"recipient": "3EE34828-B43C-4FB2-A721-5151579B08EA",
	"sender": "497a495e-5529-4e46-8feb-2f35e9b85601",
	"subject": "You were mentioned in articles",
	"message": "\nHello admin@example.com,\n\rijk@directus.io has mentioned you in a comment:\n\n> Hello <em>admin@example.com</em>!\n\n<a href=\"http://localhost:8080/admin/content/articles/1\">Click here to view.</a>\n",
	"collection": "articles",
	"item": "1"
}

List Notifications

List all notifications that exist in Directus.

Query Parameters

Supports all global query parameters.

Returns

An array of up to limit notification objects. If no items are available, data will be an empty array.

REST API

GET /notifications
SEARCH /notifications

Learn more about SEARCH ->

GraphQL

POST /graphql/system
type Query {
	notifications: [directus_notifications]
}
Example
query {
	notifications {
		id
		recipient
		subject
	}
}

Retrieve a notification

List an existing notification by primary key.

Query Parameters

Supports all global query parameters.

Returns

Returns the requested notification object.

REST API

GET /notifications/:id
Example
GET /notifications/42

GraphQL

POST /graphql/system
type Query {
	notifications_by_id(id: ID!): directus_notifications
}
Example
query {
	notifications_by_id(id: 42) {
		id
		sender
		recipient
		message
		subject
	}
}

Create a Notification

Create a new notification.

Query Parameters

Supports all global query parameters.

Request Body

A partial notification object.

Returns

Returns the notification object for the created notification.

REST API

POST /notifications
Example
// POST /notifications

{
	"recipient": "410b5772-e63f-4ae6-9ea2-39c3a31bd6ca",
	"subject": "Hi there!"
}

GraphQL

POST /graphql/system
type Mutation {
	create_notifications_item(data: create_directus_notifications_input!): directus_notifications
}
Example
mutation {
	create_notifications_item(data: { recipient: "410b5772-e63f-4ae6-9ea2-39c3a31bd6ca", subject: "Hi there!" }) {
		id
		recipient
	}
}

Create Multiple Notifications

Create multiple new notifications.

Query Parameters

Supports all global query parameters.

Request Body

An array of partial notification objects.

Returns

Returns the notification object for the created notification.

REST API

POST /notifications
Example
// POST /notifications

[
	{
		"collection": "directus_files",
		"recipient": "410b5772-e63f-4ae6-9ea2-39c3a31bd6ca",
		"message": "Hi there! You should check out these files"
	},
	{
		"collection": "articles",
		"recipient": "410b5772-e63f-4ae6-9ea2-39c3a31bd6ca",
		"message": "Hi there! You should check out these articles"
	}
]

GraphQL

POST /graphql/system
type Mutation {
	create_notifications_items(data: [create_directus_notifications_input!]!): [directus_notifications]
}
Example
mutation {
	create_notifications_items(
		data: [
			{
				collection: "directus_files"
				recipient: "410b5772-e63f-4ae6-9ea2-39c3a31bd6ca"
				message: "Hi there! You should check out these files"
			}
			{
				collection: "articles"
				recipient: "410b5772-e63f-4ae6-9ea2-39c3a31bd6ca"
				message: "Hi there! You should check out these articles"
			}
		]
	) {
		id
		recipient
	}
}

Update a Notification

Update an existing notification.

::: tip Email Notifications

Emails are only sent when the notification is created. Updated to an existing notification won't trigger a new notification email to be sent.

:::

Query Parameters

Supports all global query parameters.

Request Body

A partial notification object.

Returns

Returns the notification object for the updated notification.

REST API

PATCH /notifications/:id
Example
// PATCH /notifications/34

{
	"message": "This is my updated notification"
}

GraphQL

POST /graphql/system
type Mutation {
	update_notifications_item(id: ID!, data: update_directus_notifications_input): directus_notifications
}
Example
mutation {
	update_notifications_item(id: 32, data: { message: "This is my updated notification" }) {
		id
		message
	}
}

Update Multiple Notifications

Update multiple existing notifications.

Query Parameters

Supports all global query parameters.

Request Body

keys Required
Array of primary keys of the notifications you'd like to update.

data Required
Any of the notification object's properties.

Returns

Returns the notification objects for the updated notifications.

REST API

PATCH /notifications
Example
// PATCH /notifications

{
	"keys": [15, 64],
	"data": {
		"message": "Updated message!"
	}
}

GraphQL

POST /graphql/system
type Mutation {
	update_notifications_items(ids: [ID!]!, data: update_directus_notifications_input): [directus_notifications]
}
Example
mutation {
	update_notifications_items(ids: [15, 64], data: { message: "Updated message!" }) {
		id
		recipient
	}
}

Delete a Notification

Delete an existing notification.

Returns

Empty body.

REST API

DELETE /notifications/:id
Example
DELETE /notifications/34

GraphQL

POST /graphql/system
type Mutation {
	delete_notifications_item(id: ID!): delete_one
}
Example
mutation {
	delete_notifications_item(id: 32) {
		id
	}
}

Delete Multiple Notifications

Delete multiple existing notifications.

Request Body

An array of notification primary keys

Returns

Empty body.

REST API

DELETE /notifications
Example
// DELETE /notifications
[15, 251, 810]

GraphQL

POST /graphql/system
type Mutation {
	delete_notifications_items(ids: [ID!]!): delete_many
}
Example
mutation {
	delete_notifications_items(ids: [15, 251, 810]) {
		ids
	}
}