chore: remove twilio from requirements
This commit is contained in:
parent
04b1e40023
commit
ea0af8d2e2
3 changed files with 0 additions and 132 deletions
|
|
@ -1,67 +0,0 @@
|
|||
{
|
||||
"actions": [],
|
||||
"creation": "2020-01-28 15:21:44.457163",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"enabled",
|
||||
"account_sid",
|
||||
"auth_token",
|
||||
"column_break_2",
|
||||
"twilio_number"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "account_sid",
|
||||
"fieldtype": "Data",
|
||||
"label": "Account SID",
|
||||
"mandatory_depends_on": "eval: doc.enabled"
|
||||
},
|
||||
{
|
||||
"fieldname": "auth_token",
|
||||
"fieldtype": "Password",
|
||||
"label": "Auth Token",
|
||||
"mandatory_depends_on": "eval: doc.enabled"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_2",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "twilio_number",
|
||||
"fieldtype": "Table",
|
||||
"label": "Twilio Number",
|
||||
"options": "Twilio Number Group"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"fieldname": "enabled",
|
||||
"fieldtype": "Check",
|
||||
"label": "Enabled"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"issingle": 1,
|
||||
"links": [],
|
||||
"modified": "2020-09-03 10:17:21.318743",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Integrations",
|
||||
"name": "Twilio Settings",
|
||||
"owner": "Administrator",
|
||||
"permissions": [
|
||||
{
|
||||
"create": 1,
|
||||
"delete": 1,
|
||||
"email": 1,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"role": "System Manager",
|
||||
"share": 1,
|
||||
"write": 1
|
||||
}
|
||||
],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"track_changes": 1
|
||||
}
|
||||
|
|
@ -1,63 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2020, Frappe Technologies and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
from frappe.model.document import Document
|
||||
from frappe import _
|
||||
from frappe.utils.password import get_decrypted_password
|
||||
from twilio.rest import Client
|
||||
from six import string_types
|
||||
from json import loads
|
||||
|
||||
class TwilioSettings(Document):
|
||||
def on_update(self):
|
||||
if self.enabled:
|
||||
self.validate_twilio_credentials()
|
||||
|
||||
def validate_twilio_credentials(self):
|
||||
try:
|
||||
auth_token = get_decrypted_password("Twilio Settings", "Twilio Settings", 'auth_token')
|
||||
client = Client(self.account_sid, auth_token)
|
||||
client.api.accounts(self.account_sid).fetch()
|
||||
except Exception:
|
||||
frappe.throw(_("Invalid Account SID or Auth Token."))
|
||||
|
||||
def send_whatsapp_message(sender, receiver_list, message):
|
||||
twilio_settings = frappe.get_doc("Twilio Settings")
|
||||
if not twilio_settings.enabled:
|
||||
frappe.throw(_("Please enable twilio settings before sending WhatsApp messages"))
|
||||
|
||||
if isinstance(receiver_list, string_types):
|
||||
receiver_list = loads(receiver_list)
|
||||
if not isinstance(receiver_list, list):
|
||||
receiver_list = [receiver_list]
|
||||
|
||||
auth_token = get_decrypted_password("Twilio Settings", "Twilio Settings", 'auth_token')
|
||||
client = Client(twilio_settings.account_sid, auth_token)
|
||||
args = {
|
||||
"from_": 'whatsapp:+{}'.format(sender),
|
||||
"body": message
|
||||
}
|
||||
|
||||
failed_delivery = []
|
||||
|
||||
for rec in receiver_list:
|
||||
args.update({"to": 'whatsapp:{}'.format(rec)})
|
||||
resp = _send_whatsapp(args, client)
|
||||
if not resp or resp.error_message:
|
||||
failed_delivery.append(rec)
|
||||
|
||||
if failed_delivery:
|
||||
frappe.log_error(_("The message wasn't correctly delivered to: {}".format(", ".join(failed_delivery))), _('Delivery Failed'))
|
||||
|
||||
|
||||
def _send_whatsapp(message_dict, client):
|
||||
response = frappe._dict()
|
||||
try:
|
||||
response = client.messages.create(**message_dict)
|
||||
except Exception as e:
|
||||
frappe.log_error(e, title = _('Twilio WhatsApp Message Error'))
|
||||
|
||||
return response
|
||||
|
|
@ -72,7 +72,5 @@ zxcvbn-python==4.4.24
|
|||
pycryptodome==3.9.8
|
||||
paytmchecksum==1.7.0
|
||||
wrapt==1.10.11
|
||||
twilio==6.44.2
|
||||
razorpay==1.2.0
|
||||
|
||||
rsa>=4.1 # not directly required, pinned by Snyk to avoid a vulnerability
|
||||
Loading…
Add table
Reference in a new issue