SMS Alert: Doing it by Js and python

Does anyone know how to send SMS alert from script ?? i couldn’t find any custom script…

this is the link, it just tells that what will be the settings but i have to do it by script and on_submit button … anyone could help me please… highly thankful

First you need to set SMS Settings and then

  frappe.ui.form.on("Sales Invoice", "on_submit", function(frm, cdt, cdn) {
            var message = 'XYXYXYXYXYX(Your MSG)';


           frappe.call({
                   method: "frappe.core.doctype.sms_settings.sms_settings.send_sms",
                   args: {
                       receiver_list: [frm.doc.contact_number],
                       msg: message,
                   },
                   callback: function(r) {


                       if (r.exc) {
                           msgprint(r.exc);
                           return;
                       }
                   }
                 });
})
4 Likes

i have seen many sms providers and they are providig sample code to integrate it with php, C# and many others but i havent seen i seen simple sample with erpnext… can you please help me with the steps how to integrate and send sms …
thanx in advance @Sagar_Bhogayata

i have to do sms settings here:
http://dev.tektician.com:32006/desk#Form/SMS%20Settings/SMS%20Settings
and then i will get this settings through this above code ?

@Sagar_Bhogayata - thanks - was looking for a way to setup an automatic sms notification. Can you add document number (sales invoice number) or total amount for this custom script? Will appreciate guidance on how to code it…

i am having an issue … when i trigger this event it says the message has been sent to the number but i am not receiving the message on my cellphone… i am using sms provider
https://www.isms.com.my/isms_send.php
i have given its credentials but i think its not making connection with the api … can you help us with that ?

I think you didn’t set SMS Settings Properly… @Owais_Zafar

You need to customized message like

  frappe.ui.form.on("Sales Invoice", "on_submit", function(frm, cdt, cdn) {
        var message = 'Invoice Number is ' + frm.doc.name;


       frappe.call({
               method: "frappe.core.doctype.sms_settings.sms_settings.send_sms",
               args: {
                   receiver_list: [frm.doc.contact_number],
                   msg: message,
               },
               callback: function(r) {


                   if (r.exc) {
                       msgprint(r.exc);
                       return;
                   }
               }
             });
})
1 Like

Can i write receiver_list like this ??
receiver_list: {
‘doctype’: ‘Property Sales Customer’,
‘filters’: {‘primary_correspondence’: 1,‘parent’:frm.doc.name},
‘fieldname’: [‘customer_tel’]
}, @Sagar_Bhogayata

Now my messages are sent to api and they are showing status that messages has been sent to these numbers but i am not receiving on my cellphones

@Owais_Zafar I think Something went wrong in SMS Configuration, Please check Delivery History from SMS Provider Panel

@zerodiscount There are some Points, In my system works perfectly

  • Check contact number field (in my case frm.doc.contact_number which is the custom field)
  • Check on_submit event triggering or not
  • You can remove callback if you want
  • Check Console log (If any log Please share here)

erpnext sms_manager code url for reference

How do I get the default contact number associated with the Sales Order?

You need to create contact details from the customer which store in contact doctype

and then its fetch to sales order

After some trial and error - this is what seems to work for me:

frappe.ui.form.on("Sales Order", "on_submit", function(frm){
		frappe.call({
               	method: "frappe.core.doctype.sms_settings.sms_settings.send_sms",
               	args: {
                   receiver_list: [frm.doc.contact_mobile],
                   msg: "Your Order "+[frm.doc.name]+" for the amount $"+[frm.doc.grand_total]+" has been received",
               	},
         })
});
2 Likes

Thanyou so much all of you guys , its solved now :slight_smile:

Hi Sagar - with update to V12 - where the mobile_number has been dropped for contact - how are you working with SMS function? Do you continue to use a custom field (which is not affected by upgrade)?

Is there a way to do this via python? (server side)

yes you can also do this by python… you can just go to that path and enable sms method