-
Notifications
You must be signed in to change notification settings - Fork 168
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
How can I trigger a WhatsApp Notification? #59
Comments
+1 |
@ahassoun
|
Thanks, worked perfectly. |
You can not directly call a Python method from the client script. Here's how you can properly trigger a server-side method to send a WhatsApp message from a custom button in the "Sales Invoice" DocType: Correcting the Client-side Script
Here's a corrected version of the client-side script: frappe.ui.form.on('Sales Invoice', {
refresh(frm) {
frm.add_custom_button(__('Send Invoice'), function() {
// Use frm.doc.name to get the current document's name
frappe.call({
method: 'your_app_path.your_module_name.your_method', // Specify the correct path to your server-side method
args: {
docname: frm.doc.name,
notification_name: 'WN-0001' // Assuming 'WN-0001' is the name of your WhatsApp Notification DocType instance
},
callback: function(r) {
if (!r.exc) {
// Handle successful message sending here, e.g., show a message to the user
frappe.msgprint(__('WhatsApp message sent successfully.'));
}
}
});
}, __("Send WhatsApp Alert"));
}
}); Required Server-side MethodYou'll need to implement a server-side method that the client-side script can call. This method will retrieve the Here's an example of what the server-side method could look like: # Example server-side method in your custom app
import frappe
from frappe.core.doctype.whatsapp_notification.whatsapp_notification import WhatsAppNotification
@frappe.whitelist()
def send_whatsapp_invoice(docname, notification_name):
try:
whatsapp_notification = frappe.get_doc('WhatsApp Notification', notification_name)
doc = frappe.get_doc('Sales Invoice', docname)
whatsapp_notification.send_scheduled_message(doc)
return {'status': 'success'}
except Exception as e:
frappe.log_error(frappe.get_traceback(), 'send_whatsapp_invoice Error')
return {'status': 'error', 'error': str(e)} Make sure to replace This setup ensures that when the "Send Invoice" button is clicked, it will make an AJAX call to the specified server-side method, which then handles the process of sending the WhatsApp Notification. Remember to adjust the server-side method path and any DocType names or field names to fit your actual setup. |
Stale issue message |
Hello!
I have a WhatsApp Template, Approved, and pulled successfully. AFAIK, the only way to initiate a message from this app is via
WhatsApp Notification
DocType.The
DocType Event
menu does not have what I need. I need a custom event.More specifically, I have a custom button on a DocType Form View, and I need the notification to be triggered once the button is clicked.
Could you please give me high level directions on how to achive this?
BR
The text was updated successfully, but these errors were encountered: