オントロジーの構築ファンクションオントロジーの編集通知の設定

注: 以下の翻訳の正確性は検証されていません。AIPを利用して英語版の原文から機械的に翻訳されたものです。

通知を設定する

関数を使用すると、ユーザーのメールアドレスに外部送信される通知も含め、プラットフォームで送信する通知を柔軟に設定できます。

関数で通知を設定するには、Principal(User または Group を表します)と notification のデータ型を使用します。このセクションを読み進める際には、次のリファレンスが役立ちます。

カスタム通知を定義する

オントロジーに、User に割り当てられる Issue オブジェクトが含まれているとします。Issue の詳細を含め、指定された User に送信する通知を定義する関数を作成できます。

Copied!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 import { EmailNotificationContent, Function, Notification, ShortNotification, User } from "@foundry/functions-api"; import { Issue } from "@foundry/ontology-api"; export class NotificationFunctions { @Function() public createIssueNotification(issue: Issue, user: User): Notification { // プラットフォーム内に表示される短い通知を作成します const shortNotification = ShortNotification.builder() .heading("New issue") .content("A new issue has been assigned to you.") // プラットフォーム内の Issue オブジェクトにリンクします .addObjectLink("Issue", issue) .build(); // メール本文を定義します。メール本文には、データのテーブルなどのヘッドレス HTML を含めることができます // コンテンツ内では、ユーザーと Issue の両方のプロパティにアクセスできることに注意してください const emailBody = `Hello, ${user.firstName}, A new issue has been assigned to you: ${issue.description}.`; const emailNotificationContent = EmailNotificationContent.builder() .subject("New issue") .body(emailBody) .addObjectLink("Issue", issue) .build(); return Notification.builder() .shortNotification(shortNotification) .emailNotificationContent(emailNotificationContent) .build(); } }
Copied!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 import { NotificationLink, Notification } from "@osdk/functions"; import { Issue } from "@ontology/sdk"; import type { Osdk } from "@osdk/api"; export default function createIssueNotification(issue: Osdk.Instance<Issue>): Notification { // プラットフォーム内の Issue オブジェクトにリンクします const links: NotificationLink[] = [ { label: "Issue", linkTarget: { type: "object", object: issue } } ] const platformNotification = { heading: "New issue", content: "A new issue has been assigned to you.", links: links } // メール本文を定義します。メール本文には、データのテーブルなどのヘッドレス HTML を含めることができます const emailBody = `Hello, A new issue has been assigned to you: ${issue.description}.`; const emailNotification = { subject: "New issue", body: emailBody, links: links } return { platformNotification: platformNotification, emailNotification: emailNotification } }
Copied!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 from functions.api import function, Notification, PlatformNotification, NotificationObjectLink, EmailNotification from ontology_sdk.ontology.objects import Issue @function() def createIssueNotification(issue: Issue) -> Notification[Issue]: # If configuring a notification with an object link, you must declare the object type as part of the return type # Link to the Issue object in the platform links = [ NotificationObjectLink(label="Issue", objectTarget=issue) ] #Create a short notification that will be shown within the platform platform_notification = PlatformNotification( heading="New issue", content="A new issue has been assigned to you.", links=links ) # Define the email body. The email body may contain headless HTML, such as tables of data emailBody = f"Hello, \n A new issue has been assigned to you: {issue.description}." email_notification = EmailNotification( subject="New issue", body=emailBody, links=links ) return Notification(platform_notification, email_notification)

ユーザーとグループを取得する

関数に User を渡すだけでなく、必要に応じて User または Group を取得することもできます。Issue オブジェクトに、ユーザーIDを含む assignee フィールドがあるとします。次の例では、関数は Issue についてユーザーにリマインドする通知を返します。

Copied!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 import { EmailNotificationContent, Function, Notification, ShortNotification, User, UserFacingError, Users } from "@foundry/functions-api"; import { Issue } from "@foundry/ontology-api"; export class NotificationFunctions { @Function() public async createIssueReminderNotification(issue: Issue): Promise<Notification> { if (!issue.assignee) { throw new UserFacingError("Cannot create notification for issue without an assignee."); } const user = await Users.getUserByIdAsync(issue.assignee); const emailBody = `Hello, ${user.firstName}, This is a reminder to investigate the following issue: ${issue.description}`; // この構造を使って、通知全体をインラインで作成することもできます return Notification.builder() .shortNotification(ShortNotification.builder() .heading("Issue reminder") .content("Investigate this issue.") .addObjectLink("Issue", issue) .build()) .emailNotificationContent(EmailNotificationContent.builder() .subject("New issue") .body(emailBody) .addObjectLink("Issue", issue) .build()) .build(); } }
Copied!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 import { NotificationLink, Notification } from "@osdk/functions"; import { Users } from "@osdk/foundry.admin"; import { Issue } from "@ontology/sdk"; import { Client } from "@osdk/client"; import type { Osdk } from "@osdk/api"; export default async function createIssueReminderNotification(client: Client, issue: Osdk.Instance<Issue>): Promise<Notification> { const user = await Users.get(client, issue.assignee); const emailBody = `Hello, ${user.firstName}, This is a reminder to investigate the following issue: ${issue.description}`; // この構造を使って、通知全体をインラインで作成することもできます const links: NotificationLink[] = [ { label: "Issue", linkTarget: { type: "object", object: issue } } ] // この構造を使って、通知全体をインラインで作成することもできます return { platformNotification: { heading: "Issue reminder", content: "Investigate this issue.", links: links }, emailNotification: { subject: "New issue", body: emailBody, links: links } } }
Copied!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 from functions.api import function, Notification, PlatformNotification, NotificationObjectLink, EmailNotification from ontology_sdk.ontology.objects import Issue from foundry_sdk import FoundryClient import foundry_sdk @function() def createIssueReminderNotification(issue: Issue) -> Notification[Issue]: client = FoundryClient(auth=foundry_sdk.UserTokenAuth(...), hostname="example.palantirfoundry.com") user = client.admin.User.get(issue.assignee) # Link to the Issue object in the platform links = [ NotificationObjectLink(label="Issue", objectTarget=issue) ] #Create a short notification that will be shown within the platform platform_notification = PlatformNotification( heading="Issue reminder", content="Investigate this issue.", links=links ) # Define the email body. The email body may contain headless HTML, such as tables of data # Note that you can access properties of both the user and the issue in the content emailBody = f"Hello, {user.firstName}, \n A new issue has been assigned to you: {issue.description}." email_notification = EmailNotification( subject="Issue reminder", body=emailBody, links=links ) return Notification(platform_notification, email_notification)

受信者を返す

上記で説明した Notification API を使用すると、カスタム通知の内容を返すことができます。関数を使用して通知を設定するもう1つの方法は、通知の受信者のリストを返すことです。この方法を使用するには、User や Group オブジェクトなど、1個以上の Principal オブジェクトを返す関数を作成します。

次の例では、関数は Issue を報告したユーザーと、その Issue に現在割り当てられているユーザーの両方を返します。

Copied!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 import { Function, User, UserFacingError, Users } from "@foundry/functions-api"; import { Issue } from "@foundry/ontology-api"; export class NotificationFunctions { /** * 指定された Issue の現在の担当者と、その Issue を最初に報告したユーザーを * 表すユーザーを返します。 */ @Function() public async getIssueAssigneeAndReporter(issue: Issue): Promise<User[]> { if (!issue.assignee || !issue.reporter) { throw new UserFacingError("Cannot create notification for issue without an assignee or reporter."); } const user = await Users.getUserByIdAsync(issue.assignee); const issueReporter = await Users.getUserByIdAsync(issue.reporter); return [user, issueReporter]; } }
Copied!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 import { UserId, Principal } from "@osdk/functions"; import { Users, Groups } from "@osdk/foundry.admin"; import { Issue } from "@ontology/sdk"; import { Client } from "@osdk/client"; import type { Osdk } from "@osdk/api"; /** * 指定された Issue の現在の担当者と、その Issue を最初に報告したユーザーを * 表すユーザーを返します。 */ async function getIssueAssigneeAndReporter(client: Client, issue: Osdk.Instance<Issue>): Promise<UserId[]> { const user = await Users.get(client, issue.assignee); const issueReporter = await Users.get(client, issue.reporter); return [user.id, issueReporter.id]; } /** * 指定された Issue の現在の担当者であるユーザーと、その Issue が属するグループを返します。 */ async function getIssueAssigneeAndGroups(client: Client, issue: Osdk.Instance<Issue>): Promise<Principal[]> { // グループとユーザーの両方を返すには、Principal 型を返します。 const user = await Users.get(client, issue.assignee); const group = await Groups.get(client, issue.group); return [{type: "user", id: user.id}, {type: "group", id: group.id}]; }
Copied!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 from functions.api import Array, function, Principal, UserId from ontology_sdk.ontology.objects import Issue from foundry_sdk import FoundryClient import foundry_sdk # 指定された Issue の現在の担当者と、その Issue を最初に報告したユーザーを # 表すユーザーを返します。 @function() def getIssueAssigneeAndReporter(issue: Issue) -> Array[UserId]: client = FoundryClient(auth=foundry_sdk.UserTokenAuth(...), hostname="example.palantirfoundry.com") user = client.admin.User.get(issue.assignee) issueReporter = client.admin.User.get(issue.reporter) return [user.id, issueReporter.id] # 指定された Issue の現在の担当者であるユーザーと、その Issue が属するグループを返します。 @function() def getIssueAssigneeAndGroup(issue: Issue) -> Array[Principal]: # グループとユーザーの両方を返すには、Principal 型を返します。 client = FoundryClient(auth=foundry_sdk.UserTokenAuth(...), hostname="example.palantirfoundry.com") user = client.admin.User.get(issue.assignee) group = client.admin.Group.get(issue.group) return [Principal.user(user.id), Principal.group(group.id)]