mcpField
F
frappe-core-notifications

frappe-core-notifications

github.com/impertio-studio開発198114 回インストール30 週間前に更新
リポジトリ

frappe-core-notifications について

Frappe アプリの開発者向けに、通知の実装方法をまとめたリファレンススキルです。ノーコードのドキュメント通知に加え、メールやリアルタイム通知、割り当て、タスク、コメント、タグの API を扱います。

主な機能

  1. 014チャネルのノーコード通知設定
  2. 02APIによるメールとリアルタイム通知
  3. 03ドキュメントの割り当てとToDo作成
  4. 04ドキュメントへのコメントとタグ追加
  5. 05イベントトリガーと受信者の設定

活用シーン

  1. 01ドキュメントイベントのメールやSMS通知設定
  2. 02データベースのトランザクション確定後にアプリ内通知
  3. 03ドキュメントを割り当てて後続タスクを作成

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/impertio-studio/frappe_claude_skill_package --skill frappe-core-notifications

インストール後、Claude Code で/frappe-core-notificationsを入力して読み込まれたか確認します。

同梱ファイル

SKILL.md と一緒にインストールされる参考資料やスクリプト。

references/
.gitkeep
anti-patterns.md
api-reference.md
email-system.md
examples.md

詳細

Frappe 通知システム

クイックリファレンス

チャネル方法ユースケース
メールfrappe.sendmail()完全に制御できるプログラムからのメール送信
メールNotification DocType(Email)ドキュメントイベントに応じたノーコードのメール送信
システムfrappe.publish_realtime()socket.io 経由のアプリ内リアルタイム通知
システムNotification DocType(System)ノーコードのアプリ内通知
SMSNotification DocType(SMS)ドキュメントイベントに応じたノーコードの SMS 送信
SlackNotification DocType(Slack)ノーコードの Slack webhook メッセージ
割り当てfrappe.desk.form.assign_to.add()ドキュメントをユーザーに割り当てる(ToDo を作成)
ToDofrappe.get_doc({"doctype": "ToDo", ...})タスクを直接作成
コメントdoc.add_comment("Comment", text)ドキュメントのタイムラインにコメントを追加
タグdoc.add_tag("tag_name")フィルタリング用にドキュメントにタグを付ける

判断ツリー

What notification mechanism do you need?
│
├─ Email on document event (no code)?
│  └─ Notification DocType → Channel: Email
│
├─ Programmatic email with custom logic?
│  └─ frappe.sendmail() in server script or hook
│
├─ Real-time in-app notification?
│  ├─ No-code → Notification DocType → Channel: System Notification
│  └─ Programmatic → frappe.publish_realtime()
│
├─ SMS on document event?
│  └─ Notification DocType → Channel: SMS (requires SMS Settings)
│
├─ Assign document to user?
│  ├─ No-code → Assignment Rule DocType
│  └─ Programmatic → frappe.desk.form.assign_to.add()
│
├─ Recurring document creation?
│  └─ Auto Repeat DocType
│
└─ Add comment or tag?
   ├─ Comment → doc.add_comment("Comment", text="...")
   └─ Tag → doc.add_tag("tag_name")

Notification DocType

Notification DocType を使うと、4 つのチャネルでノーコードの通知を設定できます。

イベントトリガー
イベント発生するタイミング
Newドキュメントが作成されたとき
Saveドキュメントが保存されたとき
Submitドキュメントが送信されたとき
Cancelドキュメントがキャンセルされたとき
Value Change特定のフィールド値が変更されたとき
Days Before日付フィールドの値の N 日前
Days After日付フィールドの値の N 日後
Methodカスタム Python メソッドが呼び出されたとき
条件の構文

Condition フィールドでは、必ず Python の式を使用してください。

# Status-based
doc.status == "Open"

# Date-based
doc.due_date == nowdate()

# Threshold-based
doc.grand_total > 40000

# Combined
doc.status == "Overdue" and doc.grand_total > 10000

使用可能なコンテキスト:doc、nowdate()、frappe.utils.*。

受信者の設定
ソース説明
Document Fieldドキュメント上のメールアドレス/電話番号フィールド
Role指定したロールを持つすべてのユーザー
Customハードコードされたメールアドレス
All Assigneesドキュメントに割り当てられたすべてのユーザー
Condition受信者を絞り込む Jinja 式
Jinja メッセージテンプレート
<h3>Order Overdue</h3>
<p>Transaction {{ doc.name }} has exceeded its due date.</p>

{% if comments %}
Last comment: {{ comments[-1].comment }} by {{ comments[-1].by }}
{% endif %}

<ul>
  <li>Customer: {{ doc.customer }}</li>
  <li>Amount: {{ doc.grand_total }}</li>
</ul>

テンプレート変数:{{ doc }}、{{ doc.fieldname }}、{{ comments }}、{{ nowdate() }}。

印刷物を添付

ドキュメントの PDF を添付するには、Attach Print を設定します。カスタムレイアウトを使用するには、Print Format を選択します。


frappe.sendmail():プログラムからのメール送信

frappe.sendmail(
    recipients=["[email protected]"],       # list of email addresses
    subject="Invoice Due",                  # email subject
    message="<p>Your invoice is due.</p>",  # HTML body
    template="invoice_reminder",            # Jinja template name (optional)
    args={"customer": "ACME"},              # template context variables
    attachments=[{"fname": "inv.pdf", "fcontent": pdf_bytes}],
    reference_doctype="Sales Invoice",      # links email to document
    reference_name="SINV-00001",
    delayed=True,                           # queue via Email Queue (default)
    now=False,                              # True = send immediately, skip queue
    sender="[email protected]",           # override sender
    cc=["[email protected]"],
    bcc=["[email protected]"],
    reply_to="[email protected]",
    expose_recipients="header",             # show recipients in email header
)

ルール:

  • メールがドキュメントに関連する場合は、必ず reference_doctype と reference_name を設定してください。これにより、メールがドキュメントのタイムラインに表示されます。
  • 本番環境では、now=True を設定しないでください。リクエストがブロックされます。Email Queue 経由でキューに登録するには、delayed=True(デフォルト)を使用してください。
  • frappe.sendmail を呼び出す前に、"Enable Outgoing" が有効な Email Account が設定されていることを必ず確認してください。
Email Queue

メールは Email Queue DocType に登録され、スケジューラーによって送信されます。キューのステータスを確認するには、次のようにします。

# Check pending emails
pending = frappe.get_all("Email Queue", filters={"status": "Not Sent"}, limit=10)

frappe.publish_realtime():システム通知

frappe.publish_realtime(
    event="msgprint",                      # event name
    message={"msg": "Task completed!"},    # dict payload
    user="[email protected]",               # target specific user
    doctype="Sales Invoice",               # broadcast to doctype room
    docname="SINV-00001",                  # broadcast to document room
    after_commit=True,                     # emit after transaction commits
)
ルームの種類
ルーム対象
user:{email}単一のユーザー(user= を設定)
doctype:{dt}該当するリストを表示しているすべてのユーザー
doc:{dt}/{dn}該当するドキュメントを表示しているすべてのユーザー
allサイト全体のすべての Desk ユーザー
task_progress:{id}バックグラウンドタスクの進行状況
組み込みイベント
イベント目的
msgprintユーザーにメッセージダイアログを表示
list_updateドキュメントリストビューを更新
docinfo_updateドキュメント情報サイドバーを更新
progress進行状況バーを表示

データベーストランザクション内から通知を送信する場合は、必ず after_commit=True を設定してください。設定しないと、データのコミット前にイベントが発生し、クライアントが古いデータを読み取る可能性があります。


割り当てルール

条件に基づいてドキュメントをユーザーに自動割り当てします(コード不要)。

設定フィールド
フィールド目的
Document Typeルールをトリガーする DocType
Assign ConditionPython 式(Notification と同じ)
Assignment Days特定の曜日に限定
Users割り当て先ユーザーのリスト
Assignment RuleRound Robin、Load Balancing、または Based on Field
プログラムによる割り当て
from frappe.desk.form.assign_to import add, remove, close, clear

# Assign
add({
    "assign_to": ["[email protected]"],
    "doctype": "Task",
    "name": "TASK-00001",
    "description": "Please review this task",
    "priority": "High",
    "date": "2025-12-31",
})

# Remove assignment (cancels ToDo)
remove("Task", "TASK-00001", "[email protected]")

# Close assignment (only assignee can close)
close("Task", "TASK-00001", "[email protected]")

# Clear all assignments
clear("Task", "TASK-00001")

担当者とは異なるユーザーとして close() を呼び出さないでください。権限エラーが発生します。


自動繰り返し

スケジュールに従って、ドキュメントのコピーを定期的に作成します。

フィールド目的
参照 DocType繰り返す DocType
参照ドキュメントコピー元のドキュメント
頻度毎日、毎週、毎月、四半期ごと、半年ごと、毎年
開始日/終了日スケジュールの期間
メールで通知作成時に通知を送信

自動繰り返しには必ず終了日を設定してください。終了日がないスケジュールではドキュメントが無期限に作成され、デバッグが困難になります。


ToDo API

# Create ToDo directly
todo = frappe.get_doc({
    "doctype": "ToDo",
    "allocated_to": "[email protected]",
    "assigned_by": frappe.session.user,
    "description": "Review the quarterly report",
    "priority": "Medium",
    "date": "2025-12-31",
    "status": "Open",
    "reference_type": "Task",
    "reference_name": "TASK-00001",
}).insert(ignore_permissions=True)

ToDo のステータス:Open、Closed、Cancelled。


コメントとタグ

# Add comment (appears in document timeline)
doc.add_comment("Comment", text="Reviewed and approved")
doc.add_comment("Edit", "Values changed")

# Add/get tags
doc.add_tag("urgent")
tags = doc.get_tags()  # returns list of tag strings

バージョンの違い

機能v14v15v16
通知 DocType4 つすべてのチャネル4 つすべてのチャネル4 つすべてのチャネル
分前/分後利用不可利用可能利用可能
frappe.publish_realtime利用可能利用可能利用可能
割り当てルール利用可能利用可能利用可能

関連項目

コメント