Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Button : Get Alerts for Today #92

Merged
merged 11 commits into from
Aug 19, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,27 @@ frappe.ui.form.on('WhatsApp Notification', {
frappe.notification.setup_fieldname_select(frm);
},
});


frappe.ui.form.on('WhatsApp Notification', {
refresh: function (frm) {
frm.add_custom_button(__('Get Alerts for Today'), function () {
frappe.call({
method: 'frappe_whatsapp.frappe_whatsapp.doctype.whatsapp_notification.custom_api.call_trigger_notifications',
args: {
method: 'daily' // You can change this as needed
},
callback: function (response) {
// Handle the response as needed
if (response.message) {
console.log(response.message);
nilpatel42 marked this conversation as resolved.
Show resolved Hide resolved
nilpatel42 marked this conversation as resolved.
Show resolved Hide resolved
}
},
error: function (error) {
console.error('Error:', error);
nilpatel42 marked this conversation as resolved.
Show resolved Hide resolved
nilpatel42 marked this conversation as resolved.
Show resolved Hide resolved
frappe.msgprint(__('Failed to trigger notifications'));
}
});
});
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,20 @@ def template():
doc.mobile_no = "+919741094468"
notification.send_template_message(doc)



@frappe.whitelist()
def call_trigger_notifications():
"""Trigger notifications."""
try:
# Assuming trigger_notifications is defined elsewhere in the file
if 'trigger_notifications' in globals():
nilpatel42 marked this conversation as resolved.
Show resolved Hide resolved
trigger_notifications() # Call the function
else:
frappe.throw("trigger_notifications function is not defined.")
except Exception as e:
# Log the error but do not show any popup or alert
frappe.log_error(frappe.get_traceback(), "Error in call_trigger_notifications")
# Optionally, you could raise the exception to be handled elsewhere if needed
raise e

6 changes: 3 additions & 3 deletions frappe_whatsapp/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@
# Overriding Methods
# ------------------------------
#
# override_whitelisted_methods = {
# "frappe.desk.doctype.event.event.get_events": "frappe_whatsapp.event.get_events"
# }
override_whitelisted_methods = {
nilpatel42 marked this conversation as resolved.
Show resolved Hide resolved
"frappe_whatsapp.frappe_whatsapp.doctype.whatsapp_notification.custom_api.call_trigger_notifications": "frappe_whatsapp.frappe_whatsapp.doctype.whatsapp_notification.whatsapp_notification.call_trigger_notifications"
}
#
# each overriding function accepts a `data` argument;
# generated from the base implementation of the doctype dashboard,
Expand Down