fix: renamed Twilio Settings to CRM Twilio Settings
This commit is contained in:
parent
346efbbe78
commit
89dd09325f
@ -1,7 +1,7 @@
|
||||
// Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
// frappe.ui.form.on("Twilio Agents", {
|
||||
// frappe.ui.form.on("CRM Twilio Settings", {
|
||||
// refresh(frm) {
|
||||
|
||||
// },
|
||||
@ -108,7 +108,7 @@
|
||||
"modified": "2025-01-15 19:35:13.406254",
|
||||
"modified_by": "Administrator",
|
||||
"module": "FCRM",
|
||||
"name": "Twilio Settings",
|
||||
"name": "CRM Twilio Settings",
|
||||
"owner": "Administrator",
|
||||
"permissions": [
|
||||
{
|
||||
@ -2,13 +2,13 @@
|
||||
# For license information, please see license.txt
|
||||
|
||||
import frappe
|
||||
from frappe.model.document import Document
|
||||
from frappe import _
|
||||
|
||||
from frappe.model.document import Document
|
||||
from twilio.rest import Client
|
||||
|
||||
class TwilioSettings(Document):
|
||||
friendly_resource_name = "Frappe CRM" # System creates TwiML app & API keys with this name.
|
||||
|
||||
class CRMTwilioSettings(Document):
|
||||
friendly_resource_name = "Frappe CRM" # System creates TwiML app & API keys with this name.
|
||||
|
||||
def validate(self):
|
||||
self.validate_twilio_account()
|
||||
@ -33,28 +33,24 @@ class TwilioSettings(Document):
|
||||
frappe.throw(_("Invalid Account SID or Auth Token."))
|
||||
|
||||
def set_api_credentials(self, twilio):
|
||||
"""Generate Twilio API credentials if not exist and update them.
|
||||
"""
|
||||
"""Generate Twilio API credentials if not exist and update them."""
|
||||
if self.api_key and self.api_secret:
|
||||
return
|
||||
new_key = self.create_api_key(twilio)
|
||||
self.api_key = new_key.sid
|
||||
self.api_secret = new_key.secret
|
||||
frappe.db.set_value('Twilio Settings', 'Twilio Settings', {
|
||||
'api_key': self.api_key,
|
||||
'api_secret': self.api_secret
|
||||
})
|
||||
frappe.db.set_value(
|
||||
"Twilio Settings", "Twilio Settings", {"api_key": self.api_key, "api_secret": self.api_secret}
|
||||
)
|
||||
|
||||
def set_application_credentials(self, twilio):
|
||||
"""Generate TwiML app credentials if not exist and update them.
|
||||
"""
|
||||
"""Generate TwiML app credentials if not exist and update them."""
|
||||
credentials = self.get_application(twilio) or self.create_application(twilio)
|
||||
self.twiml_sid = credentials.sid
|
||||
frappe.db.set_value('Twilio Settings', 'Twilio Settings', 'twiml_sid', self.twiml_sid)
|
||||
frappe.db.set_value("Twilio Settings", "Twilio Settings", "twiml_sid", self.twiml_sid)
|
||||
|
||||
def create_api_key(self, twilio):
|
||||
"""Create API keys in twilio account.
|
||||
"""
|
||||
"""Create API keys in twilio account."""
|
||||
try:
|
||||
return twilio.new_keys.create(friendly_name=self.friendly_resource_name)
|
||||
except Exception:
|
||||
@ -66,23 +62,21 @@ class TwilioSettings(Document):
|
||||
return get_public_url(url_path)
|
||||
|
||||
def get_application(self, twilio, friendly_name=None):
|
||||
"""Get TwiML App from twilio account if exists.
|
||||
"""
|
||||
"""Get TwiML App from twilio account if exists."""
|
||||
friendly_name = friendly_name or self.friendly_resource_name
|
||||
applications = twilio.applications.list(friendly_name)
|
||||
return applications and applications[0]
|
||||
|
||||
def create_application(self, twilio, friendly_name=None):
|
||||
"""Create TwilML App in twilio account.
|
||||
"""
|
||||
"""Create TwilML App in twilio account."""
|
||||
friendly_name = friendly_name or self.friendly_resource_name
|
||||
application = twilio.applications.create(
|
||||
voice_method='POST',
|
||||
voice_url=self.get_twilio_voice_url(),
|
||||
friendly_name=friendly_name
|
||||
)
|
||||
voice_method="POST", voice_url=self.get_twilio_voice_url(), friendly_name=friendly_name
|
||||
)
|
||||
return application
|
||||
|
||||
def get_public_url(path: str=None):
|
||||
|
||||
def get_public_url(path: str | None = None):
|
||||
from frappe.utils import get_url
|
||||
return get_url().split(":8", 1)[0] + path
|
||||
|
||||
return get_url().split(":8", 1)[0] + path
|
||||
@ -5,5 +5,5 @@
|
||||
from frappe.tests import UnitTestCase
|
||||
|
||||
|
||||
class TestTwilioAgents(UnitTestCase):
|
||||
class TestCRMTwilioSettings(UnitTestCase):
|
||||
pass
|
||||
@ -1,78 +0,0 @@
|
||||
{
|
||||
"actions": [],
|
||||
"allow_rename": 1,
|
||||
"autoname": "field:user",
|
||||
"creation": "2023-08-17 19:59:56.239729",
|
||||
"default_view": "List",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"user",
|
||||
"user_name",
|
||||
"call_receiving_device",
|
||||
"column_break_ljne",
|
||||
"twilio_number"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "user",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "User",
|
||||
"options": "User",
|
||||
"unique": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_ljne",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "twilio_number",
|
||||
"fieldtype": "Data",
|
||||
"in_list_view": 1,
|
||||
"label": "Twilio Number",
|
||||
"options": "Phone"
|
||||
},
|
||||
{
|
||||
"fetch_from": "user.full_name",
|
||||
"fieldname": "user_name",
|
||||
"fieldtype": "Data",
|
||||
"label": "User Name",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"default": "Computer",
|
||||
"fieldname": "call_receiving_device",
|
||||
"fieldtype": "Select",
|
||||
"label": "Device",
|
||||
"options": "Computer\nPhone"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2024-01-19 21:57:18.626669",
|
||||
"modified_by": "Administrator",
|
||||
"module": "FCRM",
|
||||
"name": "Twilio Agents",
|
||||
"naming_rule": "By fieldname",
|
||||
"owner": "Administrator",
|
||||
"permissions": [
|
||||
{
|
||||
"create": 1,
|
||||
"delete": 1,
|
||||
"email": 1,
|
||||
"export": 1,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"report": 1,
|
||||
"role": "Sales Manager",
|
||||
"share": 1,
|
||||
"write": 1
|
||||
}
|
||||
],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"states": [],
|
||||
"track_changes": 1
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
# import frappe
|
||||
from frappe.model.document import Document
|
||||
|
||||
|
||||
class TwilioAgents(Document):
|
||||
pass
|
||||
@ -1,9 +0,0 @@
|
||||
# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
# See license.txt
|
||||
|
||||
# import frappe
|
||||
from frappe.tests import UnitTestCase
|
||||
|
||||
|
||||
class TestTwilioSettings(UnitTestCase):
|
||||
pass
|
||||
@ -1,8 +0,0 @@
|
||||
// Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
// frappe.ui.form.on("Twilio Settings", {
|
||||
// refresh(frm) {
|
||||
|
||||
// },
|
||||
// });
|
||||
Loading…
x
Reference in New Issue
Block a user