Skip to content

Commit

Permalink
feat(integration): document alert messages
Browse files Browse the repository at this point in the history
  • Loading branch information
nikkothari22 committed Dec 15, 2024
1 parent b0d1f4e commit 20a5b44
Show file tree
Hide file tree
Showing 16 changed files with 623 additions and 8 deletions.
30 changes: 30 additions & 0 deletions frontend/src/types/RavenIntegrations/RavenDocumentNotification.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { RavenDocumentNotificationRecipients } from './RavenDocumentNotificationRecipients'

export interface RavenDocumentNotification{
creation: string
name: string
modified: string
owner: string
modified_by: string
docstatus: 0 | 1 | 2
parent?: string
parentfield?: string
parenttype?: string
idx?: number
/** Notification Name : Data */
notification_name: string
/** Enabled : Check */
enabled?: 0 | 1
/** Sender : Link - Raven Bot */
sender: string
/** Send Alert On : Select */
send_alert_on: "New Document" | "Update" | "Submit" | "Cancel" | "Delete"
/** Document Type : Link - DocType */
document_type: string
/** Condition : Code - Optional: The alert will be sent if this expression is true */
condition?: string
/** Recipients : Table - Raven Document Notification Recipients */
recipients: RavenDocumentNotificationRecipients[]
/** Message : Code - Can be HTML/Markdown/Plain Text. Support Jinja tags */
message: string
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

export interface RavenDocumentNotificationRecipients{
creation: string
name: string
modified: string
owner: string
modified_by: string
docstatus: 0 | 1 | 2
parent?: string
parentfield?: string
parenttype?: string
idx?: number
/** Channel Type : Select */
channel_type: "Channel" | "User"
/** Variable Type : Select */
variable_type: "Static" | "DocField" | "Jinja"
/** Value : Data */
value: string
}
6 changes: 4 additions & 2 deletions frontend/src/types/RavenMessaging/RavenMessage.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { RavenMention } from './RavenMention'

export interface RavenMessage{
name: string
creation: string
name: string
modified: string
owner: string
modified_by: string
Expand All @@ -28,7 +28,7 @@ export interface RavenMessage{
/** Is Thread : Check - This message starts a thread */
is_thread?: 0 | 1
/** Message Type : Select */
message_type?: "Text" | "Image" | "File" | "Poll"
message_type?: "Text" | "Image" | "File" | "Poll" | "System"
/** Content : Long Text */
content?: string
/** File : Attach */
Expand Down Expand Up @@ -61,4 +61,6 @@ export interface RavenMessage{
bot?: string
/** Hide link preview : Check */
hide_link_preview?: 0 | 1
/** Notification : Data - Linked to the notification that triggered this message */
notification?: string
}
8 changes: 8 additions & 0 deletions raven/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@
# Hook on document methods and events

doc_events = {
"*": {
"after_insert": "raven.raven_integrations.doctype.raven_document_notification.raven_document_notification.run_document_notification",
"on_update": "raven.raven_integrations.doctype.raven_document_notification.raven_document_notification.run_document_notification",
"on_trash": "raven.raven_integrations.doctype.raven_document_notification.raven_document_notification.run_document_notification",
"on_cancel": "raven.raven_integrations.doctype.raven_document_notification.raven_document_notification.run_document_notification",
"on_submit": "raven.raven_integrations.doctype.raven_document_notification.raven_document_notification.run_document_notification",
"on_change": "raven.raven_integrations.doctype.raven_document_notification.raven_document_notification.run_document_notification",
},
"User": {
"after_insert": "raven.raven.doctype.raven_user.raven_user.add_user_to_raven",
"on_update": "raven.raven.doctype.raven_user.raven_user.add_user_to_raven",
Expand Down
33 changes: 31 additions & 2 deletions raven/raven/workspace/raven/raven.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"app": "raven",
"charts": [],
"content": "[{\"id\":\"MKitHAnT4f\",\"type\":\"header\",\"data\":{\"text\":\"<span class=\\\"h4\\\"><a href=\\\"/raven\\\">Raven</a></span>\",\"col\":12}},{\"id\":\"gBy2HFBNf4\",\"type\":\"onboarding\",\"data\":{\"onboarding_name\":\"Raven\",\"col\":12}},{\"id\":\"ZcawYU5brv\",\"type\":\"card\",\"data\":{\"card_name\":\"DocTypes\",\"col\":4}},{\"id\":\"Uox8EFjnuM\",\"type\":\"card\",\"data\":{\"card_name\":\"AI\",\"col\":4}}]",
"content": "[{\"id\":\"MKitHAnT4f\",\"type\":\"header\",\"data\":{\"text\":\"<span class=\\\"h4\\\"><a href=\\\"/raven\\\">Raven</a></span>\",\"col\":12}},{\"id\":\"gBy2HFBNf4\",\"type\":\"onboarding\",\"data\":{\"onboarding_name\":\"Raven\",\"col\":12}},{\"id\":\"ZcawYU5brv\",\"type\":\"card\",\"data\":{\"card_name\":\"DocTypes\",\"col\":4}},{\"id\":\"Uox8EFjnuM\",\"type\":\"card\",\"data\":{\"card_name\":\"AI\",\"col\":4}},{\"id\":\"F85-QVSjIb\",\"type\":\"card\",\"data\":{\"card_name\":\"Integrations\",\"col\":4}}]",
"creation": "2023-06-22 20:12:29.687295",
"custom_blocks": [],
"docstatus": 0,
Expand Down Expand Up @@ -150,9 +150,38 @@
"link_type": "DocType",
"onboard": 0,
"type": "Link"
},
{
"hidden": 0,
"is_query_report": 0,
"label": "Integrations",
"link_count": 2,
"link_type": "DocType",
"onboard": 0,
"type": "Card Break"
},
{
"hidden": 0,
"is_query_report": 0,
"label": "Message Actions",
"link_count": 0,
"link_to": "Raven Message Action",
"link_type": "DocType",
"onboard": 0,
"type": "Link"
},
{
"hidden": 0,
"is_query_report": 0,
"label": "Document Notifications",
"link_count": 0,
"link_to": "Raven Document Notification",
"link_type": "DocType",
"onboard": 0,
"type": "Link"
}
],
"modified": "2024-10-22 20:06:54.714414",
"modified": "2024-12-15 19:43:38.989720",
"modified_by": "Administrator",
"module": "Raven",
"name": "Raven",
Expand Down
7 changes: 6 additions & 1 deletion raven/raven_bot/doctype/raven_bot/raven_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ def send_message(
link_doctype: str = None,
link_document: str = None,
markdown: bool = False,
notification_name: str = None,
) -> str:
"""
Send a text message to a channel
Expand Down Expand Up @@ -271,6 +272,7 @@ def send_message(
"bot": self.raven_user,
"link_doctype": link_doctype,
"link_document": link_document,
"notification": notification_name,
}
)
# Bots can probably send messages without permissions? Upto the end user to create bots.
Expand Down Expand Up @@ -313,6 +315,7 @@ def send_direct_message(
link_doctype: str = None,
link_document: str = None,
markdown: bool = False,
notification_name: str = None,
) -> str:
"""
Send a text message to a user in a Direct Message channel
Expand All @@ -333,7 +336,9 @@ def send_direct_message(
channel_id = self.create_direct_message_channel(user_id)

if channel_id:
return self.send_message(channel_id, text, link_doctype, link_document, markdown)
return self.send_message(
channel_id, text, link_doctype, link_document, markdown, notification_name
)

def get_last_message(self, channel_id: str = None, message_type: str = None) -> Document | None:
"""
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) 2024, The Commit Company (Algocode Technologies Pvt. Ltd.) and contributors
// For license information, please see license.txt

// frappe.ui.form.on("Raven Document Notification", {
// refresh(frm) {

// },
// });
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
{
"actions": [],
"allow_rename": 1,
"autoname": "field:notification_name",
"creation": "2024-12-15 17:36:24.825068",
"doctype": "DocType",
"engine": "InnoDB",
"field_order": [
"notification_name",
"enabled",
"column_break_hpcq",
"sender",
"section_break_vsib",
"send_alert_on",
"column_break_rxyz",
"document_type",
"conditions_tab",
"condition",
"recipients_tab",
"recipients",
"message_content_tab",
"message"
],
"fields": [
{
"fieldname": "notification_name",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Notification Name",
"reqd": 1,
"unique": 1
},
{
"default": "1",
"fieldname": "enabled",
"fieldtype": "Check",
"label": "Enabled"
},
{
"fieldname": "column_break_hpcq",
"fieldtype": "Column Break"
},
{
"fieldname": "section_break_vsib",
"fieldtype": "Section Break"
},
{
"fieldname": "send_alert_on",
"fieldtype": "Select",
"in_list_view": 1,
"label": "Send Alert On",
"options": "New Document\nUpdate\nSubmit\nCancel\nDelete",
"reqd": 1
},
{
"fieldname": "column_break_rxyz",
"fieldtype": "Column Break"
},
{
"fieldname": "document_type",
"fieldtype": "Link",
"in_list_view": 1,
"label": "Document Type",
"options": "DocType",
"reqd": 1,
"search_index": 1
},
{
"fieldname": "conditions_tab",
"fieldtype": "Tab Break",
"label": "Conditions"
},
{
"description": "Optional: The alert will be sent if this expression is true",
"fieldname": "condition",
"fieldtype": "Code",
"label": "Condition"
},
{
"fieldname": "recipients_tab",
"fieldtype": "Tab Break",
"label": "Recipients"
},
{
"fieldname": "recipients",
"fieldtype": "Table",
"label": "Recipients",
"options": "Raven Document Notification Recipients",
"reqd": 1
},
{
"fieldname": "message_content_tab",
"fieldtype": "Tab Break",
"label": "Message Content"
},
{
"description": "Can be HTML/Markdown/Plain Text. Support Jinja tags",
"fieldname": "message",
"fieldtype": "Code",
"label": "Message",
"reqd": 1
},
{
"fieldname": "sender",
"fieldtype": "Link",
"label": "Sender",
"options": "Raven Bot",
"reqd": 1
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2024-12-15 19:21:43.452516",
"modified_by": "Administrator",
"module": "Raven Integrations",
"name": "Raven Document Notification",
"naming_rule": "By fieldname",
"owner": "Administrator",
"permissions": [
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "System Manager",
"share": 1,
"write": 1
},
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "Raven Admin",
"share": 1,
"write": 1
}
],
"sort_field": "creation",
"sort_order": "DESC",
"states": []
}
Loading

0 comments on commit 20a5b44

Please sign in to comment.