[fix] SMS status and log
This commit is contained in:
parent
f5ea801b69
commit
098760f0e2
@ -42,6 +42,11 @@ def get_data():
|
||||
"name": "SMS Center",
|
||||
"description":_("Send mass SMS to your contacts"),
|
||||
},
|
||||
{
|
||||
"type": "doctype",
|
||||
"name": "SMS Log",
|
||||
"description":_("Logs for maintaining sms delivery status"),
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -48,6 +48,11 @@ def get_data():
|
||||
"name": "SMS Center",
|
||||
"description":_("Send mass SMS to your contacts"),
|
||||
},
|
||||
{
|
||||
"type": "doctype",
|
||||
"name": "SMS Log",
|
||||
"description":_("Logs for maintaining sms delivery status"),
|
||||
},
|
||||
{
|
||||
"type": "doctype",
|
||||
"name": "Newsletter",
|
||||
|
@ -5,7 +5,7 @@ from __future__ import unicode_literals
|
||||
import frappe
|
||||
|
||||
from frappe import _, throw, msgprint
|
||||
from frappe.utils import cstr, nowdate
|
||||
from frappe.utils import nowdate
|
||||
|
||||
from frappe.model.document import Document
|
||||
|
||||
@ -63,8 +63,7 @@ def send_sms(receiver_list, msg, sender_name = ''):
|
||||
}
|
||||
|
||||
if frappe.db.get_value('SMS Settings', None, 'sms_gateway_url'):
|
||||
ret = send_via_gateway(arg)
|
||||
msgprint(ret)
|
||||
send_via_gateway(arg)
|
||||
else:
|
||||
msgprint(_("Please Update SMS Settings"))
|
||||
|
||||
@ -74,12 +73,17 @@ def send_via_gateway(arg):
|
||||
for d in ss.get("parameters"):
|
||||
args[d.parameter] = d.value
|
||||
|
||||
resp = []
|
||||
success_list = []
|
||||
for d in arg.get('receiver_list'):
|
||||
args[ss.receiver_parameter] = d
|
||||
resp.append(send_request(ss.sms_gateway_url, args))
|
||||
status = send_request(ss.sms_gateway_url, args)
|
||||
if status == 200:
|
||||
success_list.append(d)
|
||||
|
||||
return resp
|
||||
if len(success_list) > 0:
|
||||
args.update(arg)
|
||||
create_sms_log(args, success_list)
|
||||
frappe.msgprint(_("SMS sent to following numbers: {0}").format("\n" + "\n".join(success_list)))
|
||||
|
||||
# Send Request
|
||||
# =========================================================
|
||||
@ -90,11 +94,8 @@ def send_request(gateway_url, args):
|
||||
headers = {}
|
||||
headers['Accept'] = "text/plain, text/html, */*"
|
||||
conn.request('GET', api_url + urllib.urlencode(args), headers = headers) # send request
|
||||
resp = conn.getresponse() # get response
|
||||
resp = resp.read()
|
||||
if resp.status==200:
|
||||
create_sms_log()
|
||||
return resp
|
||||
resp = conn.getresponse() # get response
|
||||
return resp.status
|
||||
|
||||
# Split gateway url to server and api url
|
||||
# =========================================================
|
||||
@ -109,12 +110,13 @@ def scrub_gateway_url(url):
|
||||
|
||||
# Create SMS Log
|
||||
# =========================================================
|
||||
def create_sms_log(arg, sent_sms):
|
||||
sl = frappe.get_doc('SMS Log')
|
||||
sl.sender_name = arg['sender_name']
|
||||
def create_sms_log(args, sent_to):
|
||||
sl = frappe.new_doc('SMS Log')
|
||||
sl.sender_name = args['sender_name']
|
||||
sl.sent_on = nowdate()
|
||||
sl.receiver_list = cstr(arg['receiver_list'])
|
||||
sl.message = arg['message']
|
||||
sl.no_of_requested_sms = len(arg['receiver_list'])
|
||||
sl.no_of_sent_sms = sent_sms
|
||||
sl.message = args['message']
|
||||
sl.no_of_requested_sms = len(args['receiver_list'])
|
||||
sl.requested_numbers = "\n".join(args['receiver_list'])
|
||||
sl.no_of_sent_sms = len(sent_to)
|
||||
sl.sent_to = "\n".join(sent_to)
|
||||
sl.save()
|
||||
|
@ -1,32 +1,58 @@
|
||||
{
|
||||
"autoname": "SMSLOG/.########",
|
||||
"creation": "2012-03-27 14:36:47.000000",
|
||||
"creation": "2012-03-27 14:36:47",
|
||||
"docstatus": 0,
|
||||
"doctype": "DocType",
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "column_break0",
|
||||
"fieldtype": "Column Break",
|
||||
"permlevel": 0,
|
||||
"width": "50%"
|
||||
},
|
||||
{
|
||||
"fieldname": "sender_name",
|
||||
"fieldtype": "Data",
|
||||
"label": "Sender Name",
|
||||
"permlevel": 0
|
||||
"permlevel": 0,
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "sent_on",
|
||||
"fieldtype": "Date",
|
||||
"label": "Sent On",
|
||||
"permlevel": 0
|
||||
"permlevel": 0,
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "receiver_list",
|
||||
"fieldname": "column_break0",
|
||||
"fieldtype": "Column Break",
|
||||
"permlevel": 0,
|
||||
"read_only": 0,
|
||||
"width": "50%"
|
||||
},
|
||||
{
|
||||
"fieldname": "message",
|
||||
"fieldtype": "Small Text",
|
||||
"label": "Receiver List",
|
||||
"permlevel": 0
|
||||
"label": "Message",
|
||||
"permlevel": 0,
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "sec_break1",
|
||||
"fieldtype": "Section Break",
|
||||
"options": "Simple",
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"read_only": 0
|
||||
},
|
||||
{
|
||||
"fieldname": "no_of_requested_sms",
|
||||
"fieldtype": "Int",
|
||||
"label": "No of Requested SMS",
|
||||
"permlevel": 0,
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "requested_numbers",
|
||||
"fieldtype": "Small Text",
|
||||
"label": "Requested Numbers",
|
||||
"permlevel": 0,
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break1",
|
||||
@ -34,28 +60,25 @@
|
||||
"permlevel": 0,
|
||||
"width": "50%"
|
||||
},
|
||||
{
|
||||
"fieldname": "no_of_requested_sms",
|
||||
"fieldtype": "Int",
|
||||
"label": "No of Requested SMS",
|
||||
"permlevel": 0
|
||||
},
|
||||
{
|
||||
"fieldname": "no_of_sent_sms",
|
||||
"fieldtype": "Int",
|
||||
"label": "No of Sent SMS",
|
||||
"permlevel": 0
|
||||
"permlevel": 0,
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "message",
|
||||
"fieldname": "sent_to",
|
||||
"fieldtype": "Small Text",
|
||||
"label": "Message",
|
||||
"permlevel": 0
|
||||
"label": "Sent To",
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"read_only": 1
|
||||
}
|
||||
],
|
||||
"icon": "icon-mobile-phone",
|
||||
"idx": 1,
|
||||
"modified": "2013-12-20 19:24:35.000000",
|
||||
"modified": "2015-07-22 11:53:25.998578",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Utilities",
|
||||
"name": "SMS Log",
|
||||
|
Loading…
Reference in New Issue
Block a user