Add Options to Flow Notification Operation (#19033)

* add collection and item options to notification opperation

* Create stale-tips-relax.md

* fix formatting

---------

Co-authored-by: Rijk van Zanten <rijkvanzanten@me.com>
This commit is contained in:
Connor
2023-07-09 10:38:03 -05:00
committed by GitHub
parent 40047228b3
commit eefde53a86
4 changed files with 41 additions and 2 deletions

View File

@@ -0,0 +1,6 @@
---
"@directus/app": patch
"@directus/api": patch
---
Added Collection and Item Options to Flows Notification Operation

View File

@@ -8,12 +8,17 @@ type Options = {
subject: string;
message?: unknown | null;
permissions: string; // $public, $trigger, $full, or UUID of a role
collection?: string;
item?: string;
};
export default defineOperationApi<Options>({
id: 'notification',
handler: async ({ recipient, subject, message, permissions }, { accountability, database, getSchema }) => {
handler: async (
{ recipient, subject, message, permissions, collection, item },
{ accountability, database, getSchema }
) => {
const schema = await getSchema({ database });
let customAccountability: Accountability | null;
@@ -34,6 +39,8 @@ export default defineOperationApi<Options>({
});
const messageString = message ? optionToString(message) : null;
const collectionString = message ? optionToString(collection) : null;
const itemString = message ? optionToString(item) : null;
const payload = toArray(recipient).map((userId) => {
return {
@@ -41,6 +48,8 @@ export default defineOperationApi<Options>({
sender: customAccountability?.user ?? null,
subject,
message: messageString,
collection: collectionString,
item: itemString,
};
});

View File

@@ -2189,7 +2189,9 @@ operations:
recipient: User
recipient_placeholder: Enter a UUID...
recipient_note: Add user UUID and press enter...
item_note: Item Key or Relative URL
message: Message
subject: Subject
request:
name: Webhook / Request URL
description: 'Make a request to a URL'

View File

@@ -61,7 +61,7 @@ export default defineOperationApp({
},
{
field: 'subject',
name: '$t:title',
name: '$t:operations.notification.subject',
type: 'string',
meta: {
width: 'full',
@@ -80,5 +80,27 @@ export default defineOperationApp({
interface: 'input-rich-text-md',
},
},
{
field: 'collection',
name: '$t:collection',
type: 'string',
meta: {
width: 'half',
interface: 'system-collection',
},
},
{
field: 'item',
name: '$t:item',
type: 'string',
meta: {
width: 'half',
interface: 'input',
options: {
iconRight: 'vpn_key',
},
note: '$t:operations.notification.item_note',
},
},
],
});