diff --git a/frappe/email/doctype/notification/notification.js b/frappe/email/doctype/notification/notification.js
index 059f5518fc..2cc027acd6 100644
--- a/frappe/email/doctype/notification/notification.js
+++ b/frappe/email/doctype/notification/notification.js
@@ -102,7 +102,7 @@ frappe.notification = {
Message Example
-Your {{ doc.name }} order of {{ doc.total }} has shipped and should be delivered on {{ doc.date }}. Details : {{doc.customer}}
+Your appointment is coming up on {{ doc.date }} at {{ doc.time }}
`;
} else if (frm.doc.channel === 'Email') {
template = `Message Example
@@ -166,6 +166,7 @@ frappe.ui.form.on('Notification', {
},
refresh: function(frm) {
frappe.notification.setup_fieldname_select(frm);
+ frappe.notification.setup_example_message(frm);
frm.get_field('is_standard').toggle(frappe.boot.developer_mode);
frm.trigger('event');
},
diff --git a/frappe/email/doctype/notification/notification.json b/frappe/email/doctype/notification/notification.json
index 8918709fa0..2a8ee1aeb1 100644
--- a/frappe/email/doctype/notification/notification.json
+++ b/frappe/email/doctype/notification/notification.json
@@ -67,7 +67,7 @@
},
{
"depends_on": "eval:doc.channel=='Slack'",
- "description": "To use Slack Channel, add a Slack Webhook URL.",
+ "description": "To use Slack Channel, add a Slack Webhook URL.",
"fieldname": "slack_webhook_url",
"fieldtype": "Link",
"label": "Slack Channel",
@@ -269,6 +269,7 @@
"fieldname": "twilio_number",
"fieldtype": "Link",
"label": "Twilio Number",
+ "mandatory_depends_on": "eval: doc.channel==='WhatsApp'",
"options": "Twilio Number Group"
},
{
@@ -290,7 +291,7 @@
"icon": "fa fa-envelope",
"index_web_pages_for_search": 1,
"links": [],
- "modified": "2020-09-01 18:36:22.550891",
+ "modified": "2020-09-03 10:33:23.084590",
"modified_by": "Administrator",
"module": "Email",
"name": "Notification",
diff --git a/frappe/email/doctype/notification/notification.py b/frappe/email/doctype/notification/notification.py
index 5355d56b35..9d8fb49ee9 100644
--- a/frappe/email/doctype/notification/notification.py
+++ b/frappe/email/doctype/notification/notification.py
@@ -43,6 +43,7 @@ class Notification(Document):
self.validate_forbidden_types()
self.validate_condition()
self.validate_standard()
+ self.validate_twilio_settings()
frappe.cache().hdel('notifications', self.document_type)
def on_update(self):
@@ -69,6 +70,11 @@ def get_context(context):
if self.is_standard and not frappe.conf.developer_mode:
frappe.throw(_('Cannot edit Standard Notification. To edit, please disable this and duplicate it'))
+ def validate_twilio_settings(self):
+ if self.enabled and self.channel == "WhatsApp" \
+ and not frappe.db.get_single_value("Twilio Settings", "enabled"):
+ frappe.throw(_("Please enable Twilio settings to send WhatsApp messages"))
+
def validate_condition(self):
temp_doc = frappe.new_doc(self.document_type)
if self.condition:
@@ -425,4 +431,4 @@ def get_assignees(doc):
recipients = [d.owner for d in assignees]
- return recipients
\ No newline at end of file
+ return recipients
diff --git a/frappe/integrations/doctype/twilio_settings/twilio_settings.json b/frappe/integrations/doctype/twilio_settings/twilio_settings.json
index e54500fd5d..9eb2c0c512 100644
--- a/frappe/integrations/doctype/twilio_settings/twilio_settings.json
+++ b/frappe/integrations/doctype/twilio_settings/twilio_settings.json
@@ -5,6 +5,7 @@
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
+ "enabled",
"account_sid",
"auth_token",
"column_break_2",
@@ -14,12 +15,14 @@
{
"fieldname": "account_sid",
"fieldtype": "Data",
- "label": "Account SID"
+ "label": "Account SID",
+ "mandatory_depends_on": "eval: doc.enabled"
},
{
"fieldname": "auth_token",
"fieldtype": "Password",
- "label": "Auth Token"
+ "label": "Auth Token",
+ "mandatory_depends_on": "eval: doc.enabled"
},
{
"fieldname": "column_break_2",
@@ -30,11 +33,18 @@
"fieldtype": "Table",
"label": "Twilio Number",
"options": "Twilio Number Group"
+ },
+ {
+ "default": "0",
+ "fieldname": "enabled",
+ "fieldtype": "Check",
+ "label": "Enabled"
}
],
+ "index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
- "modified": "2020-08-11 15:28:57.860554",
+ "modified": "2020-09-03 10:17:21.318743",
"modified_by": "Administrator",
"module": "Integrations",
"name": "Twilio Settings",
diff --git a/frappe/integrations/doctype/twilio_settings/twilio_settings.py b/frappe/integrations/doctype/twilio_settings/twilio_settings.py
index 6c698d719a..b8f991e829 100644
--- a/frappe/integrations/doctype/twilio_settings/twilio_settings.py
+++ b/frappe/integrations/doctype/twilio_settings/twilio_settings.py
@@ -5,14 +5,16 @@
from __future__ import unicode_literals
import frappe
from frappe.model.document import Document
-from twilio.rest import Client
from frappe import _
from frappe.utils.password import get_decrypted_password
+from twilio.rest import Client
from six import string_types
+from json import loads
class TwilioSettings(Document):
- def validate(self):
- self.validate_twilio_credentials()
+ def on_update(self):
+ if self.enabled:
+ self.validate_twilio_credentials()
def validate_twilio_credentials(self):
try:
@@ -23,14 +25,15 @@ class TwilioSettings(Document):
frappe.throw(_("Invalid Account SID or Auth Token."))
def send_whatsapp_message(sender, receiver_list, message):
- import json
+ twilio_settings = frappe.get_doc("Twilio Settings")
+ if not twilio_settings.enabled:
+ frappe.throw(_("Please enable twilio settings before sending WhatsApp messages"))
+
if isinstance(receiver_list, string_types):
- receiver_list = json.loads(receiver_list)
+ receiver_list = loads(receiver_list)
if not isinstance(receiver_list, list):
receiver_list = [receiver_list]
-
- twilio_settings = frappe.get_doc("Twilio Settings")
auth_token = get_decrypted_password("Twilio Settings", "Twilio Settings", 'auth_token')
client = Client(twilio_settings.account_sid, auth_token)
args = {