blob: 35446a3d24192a5742aca86b3b7afa981ee2d5df [file] [log] [blame]
Rushabh Mehtae67d1fb2013-08-05 14:59:54 +05301# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
2# License: GNU General Public License v3. See license.txt
Rushabh Mehta2e5db352013-01-16 11:34:26 +05303
4from __future__ import unicode_literals
5
6import webnotes
Rushabh Mehtaa0fa3302013-03-22 13:02:08 +05307from webnotes.utils import now
Rushabh Mehta2e5db352013-01-16 11:34:26 +05308
9max_communications_per_hour = 300
10
11@webnotes.whitelist(allow_guest=True)
12def send_message(subject="Website Query", message="", sender="", status="Open"):
13 if not message:
14 webnotes.response["message"] = 'Please write something'
15 return
16
17 if not sender:
18 webnotes.response["message"] = 'Email Id Required'
19 return
20
21 # make lead / communication
Rushabh Mehta176829e2013-02-11 14:54:30 +053022 from selling.doctype.lead.get_leads import add_sales_communication
Rushabh Mehta46ec2682013-08-29 13:53:36 +053023 message = add_sales_communication(subject or "Website Query", message, sender, sender,
Rushabh Mehta0e5401c2013-02-11 15:08:24 +053024 mail=None, status=status)
Rushabh Mehta2e5db352013-01-16 11:34:26 +053025
26 # guest method, cap max writes per hour
27 if webnotes.conn.sql("""select count(*) from `tabCommunication`
Rushabh Mehtaa0fa3302013-03-22 13:02:08 +053028 where TIMEDIFF(%s, modified) < '01:00:00'""", now())[0][0] > max_communications_per_hour:
Rushabh Mehta2e5db352013-01-16 11:34:26 +053029 webnotes.response["message"] = "Sorry: we believe we have received an unreasonably high number of requests of this kind. Please try later"
30 return
31
Rushabh Mehta46ec2682013-08-29 13:53:36 +053032 webnotes.response.status = "okay"