Whatsapp Integrations with interakt.shop
Frappe ERPNext Integration for Sending WhatsApp Messages to Vendors
Integrations Overview
Integrations are done using different types of templates:
- Send only template message.
- Send template message with an attachment, such as a PDF file.
- Send a template with an attachment and include a dynamic body variable.
- Send a template with a dynamic variable.
Development Approach
- Create a configuration file for storing the API KEY, referred to as the WhatsApp setting.
- Create a class to handle sending different types of messages as discussed above.
- Class Method: This method accepts parameter values and triggers notifications.
Code to Initialize the Class
import frappe
from core_erp.customization.integrations.whatsapp_integrations.whatsapp_integrations import WhatsAppIntegration
def on_submit(self, method=None):
if self.status == "Unpaid" and self.outstanding_amount > 0:
customer = self.customer
var1 = f"Hello {customer}"
var2 = f"Thanks for regards"
whatsapp = WhatsAppIntegration()
res = whatsapp.send(
doctype=self.doctype,
docname=self.name,
template_name="send_user",
attach_format="Test Sales invoice",
body_values=[var1, var2],
headerValues=[]
)
Example to Run Scheduler
def whtMessagePaymentDueDate():
invoice_list = frappe.get_all("Sales Invoice", filters={"status": ["!=", "Paid"], "docstatus": 1, "outstanding_amount": [">", 0], "due_date": ["=", frappe.utils.now()]})
if len(invoice_list) > 0:
for invoice in invoice_list:
field_value = frappe.db.get_value("Sales Invoice", invoice.name, ["customer", "due_date", "name", "customer_name"], as_dict=1)
if field_value.customer == "SIICP00609":
print(f"customer name {field_value.customer_name} and due date {field_value.due_date}")
whatsapp = WhatsAppIntegration()
var1 = f"Dear {field_value.customer}"
var2 = f"Please Submit the payment on {field_value.due_date}"
res = whatsapp.send(
doctype="Sales Invoice",
docname=field_value.name,
template_name="send_user",
attach_format="Test Sales invoice",
body_values=[var1, var2],
headerValues=[]
)
Conclusion
This documentation provides a basic guide for integrating WhatsApp messaging functionality within the Frappe ERPNext environment. The examples include sending different types of template messages and running a scheduler to trigger messages based on due dates. ```