Comments (5)
@ahassoun
On click of button you can call an api with below snippet
In you python code you can add the below snippet
doc = frappe.get_doc("<doctype name>", "<name>")
frappe.get_doc(
"WhatsApp Notification",
notification_name
).send_template_message(doc)
from frappe_whatsapp.
+1
from frappe_whatsapp.
@ahassoun On click of button you can call an api with below snippet In you python code you can add the below snippet
doc = frappe.get_doc("<doctype name>", "<name>") frappe.get_doc( "WhatsApp Notification", notification_name ).send_template_message(doc)
Thanks, worked perfectly.
from frappe_whatsapp.
@ahassoun can you share me code to which doctype you implemented? Complete code from button creation to trigger.
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
- Variable Scope: The variable
name
isn't defined in your function. You should usefrm.doc.name
to get the name of the current document. - Asynchronous Server Call: Use
frappe.call
to make an asynchronous call to a server-side method. You cannot directly call server-side methods likesend_scheduled_message
from the client-side without this.
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 Method
You'll need to implement a server-side method that the client-side script can call. This method will retrieve the WhatsApp Notification
document and then call its send_scheduled_message
method with the appropriate arguments.
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 'your_app_path.your_module_name.your_method'
in the client-side script with the actual path to this server-side method, such as 'your_app.doctype.sales_invoice.sales_invoice.send_whatsapp_invoice'
.
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.
from frappe_whatsapp.
Stale issue message
from frappe_whatsapp.
Related Issues (20)
- Notification sent successfully but not gettting any message HOT 4
- Error - v15 -The parameter template['language']['code'] is required. HOT 13
- Workflow state error HOT 1
- Messages are not getting send HOT 12
- Capture location/contact details. HOT 1
- Wrong version pulled HOT 3
- Getting error during execution HOT 1
- uninstall failed HOT 1
- Multilingual templates do not appear when we import templates from Meta HOT 2
- Sent messages in Whatsapp Message Log list HOT 2
- Message WhatsApp Templates None not found: and Server Error KeyError: 'error' Possible source of error: frappe_whatsapp (app), i'm getting a server error and message response when running whatsapp notification. Any help? HOT 3
- Frappe CRM Module not getting replied Whatsapp messages under Whatsapp Tab under individual leads HOT 1
- message sent, but errors in doctype document HOT 1
- send notification with variables on after submit fails HOT 2
- Not able to send message from frappe_whatsapp HOT 5
- Not able to send Message with Attachment (pdf) HOT 5
- Unable to receive the whatsapp message HOT 3
- Whatsapp Notification HOT 3
- unable to create the whatsapp template HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from frappe_whatsapp.