검토가 필요한 계약의 담당자 알림
예제용 Contract에서 상태가 Requires review인 계약이 생기면 해당 계약의 담당자에게 알립니다. 수신자는 고정 목록 대신 계약에 저장한 Foundry 사용자 ID 배열로 정합니다.
조건
Objects added to set을 선택하고 Contract의 contract status를 Requires review로 필터링합니다. 해당 상태로 새 계약을 만들거나 기존 계약이 그 상태로 바뀌어 집합에 들어오면 발동합니다.
계약마다 별도 알림
Notification 효과를 추가합니다.
Send one notification for each Contract added를 선택합니다. 수신자 설정은 Object-property-backed로 하고 사용자 속성으로 Contract Owners를 지정합니다. 이 속성은 Foundry 사용자 ID 배열입니다. 사용자 ID는 1234a567-8bc9-12ab-3456-7ca89b1c234a와 같은 형태이며, Contract Owners에는 실제 담당자의 ID를 저장합니다.
수신자에게는 자동화의 Viewer 권한이 있어야 합니다. 트리거 객체와 함수가 읽는 객체에 대한 알림 권한도 필요합니다.
개인화한 알림 함수
다음 TypeScript v1 함수는 수신자와 계약을 입력으로 받아 플랫폼 알림 및 전자우편 내용을 만듭니다. 실제 전송은 이 함수를 연결한 Automate 알림 효과가 수행합니다.
생성 SDK에는 _automateExampleContract와 title, contractStatus, customerName, customerUrl 속성이 있어야 합니다. 이 예제는 네 값을 요구하며 고객 링크에 HTTP 또는 HTTPS 웹 주소를 사용합니다. 함수는 필수 값이 null이나 undefined인지 확인하고, 고객 URL의 앞뒤 공백을 제거한 뒤 http:// 또는 https://로 시작하는지 검사합니다. 이 조건을 충족하지 않으면 알림 내용을 만들지 않고 UserFacingError를 던집니다.
HTML에 넣는 값에는 알림 함수의 escapeHtml helper를 사용합니다. 같은 함수 저장소의 src/notificationText.ts에 두고 아래 클래스를 src/contractNotifications.ts에서 내보냅니다.
import {
Function, Notification, User, ShortNotification,
EmailNotificationContent, UserFacingError,
} from "@foundry/functions-api";
import { _automateExampleContract } from "@foundry/ontology-api";
import { escapeHtml } from "./notificationText";
export class ContractNotifications {
@Function()
public createContractStatusChangeNotification(
user: User,
contract: _automateExampleContract,
): Notification | undefined {
const title = contract.title;
const status = contract.contractStatus;
const customerName = contract.customerName;
const customerUrl = contract.customerUrl?.trim();
if (title == null || status == null || customerName == null || customerUrl == null) {
throw new UserFacingError("계약 제목, 상태, 고객 이름과 URL이 필요합니다.");
}
if (!/^https?:\/\//i.test(customerUrl)) {
throw new UserFacingError("고객 URL에는 HTTP 또는 HTTPS 웹 주소가 필요합니다.");
}
const shortNotification = ShortNotification.builder()
.heading("Contract change")
.content(`The contract "${title}" changed its status to ${status}`)
.addObjectLink("View contract", contract)
.build();
const emailBody = `<p>Hello, ${escapeHtml(user.firstName ?? user.username)}!</p>` +
`<p>The contract "${escapeHtml(title)}" that you are owning changed its status to "${escapeHtml(status)}".</p>` +
`<p>Check the contract details. View more customer information <a href="${escapeHtml(customerUrl)}">here</a>.</p>`;
const emailNotificationContent = EmailNotificationContent.builder()
.subject(`Contract change - ${customerName}`)
.body(emailBody)
.addObjectLink("View contract", contract)
.build();
return Notification.builder()
.shortNotification(shortNotification)
.emailNotificationContent(emailNotificationContent)
.build();
}
}
TypeScript v1 함수가 게시 대상에 포함되도록 functions-typescript/src/index.ts에서 클래스를 내보냅니다.
export { ContractNotifications } from "./contractNotifications";
함수를 게시한 뒤 알림 효과에서 함수와 버전을 선택합니다. user에는 Recipient, contract에는 조건이 제공하는 New Contract added를 연결합니다.
운영 경고와 저장
계약 담당자에게 자동화 자체의 상태 경고를 보내지 않으려면 Settings의 Automation administrators에 운영 관리자 그룹을 지정합니다. 이는 계약별 업무 알림의 수신자와 별도 설정입니다.
이름과 저장 위치를 정하고 만료를 무기한으로 설정하여 저장합니다.