Skip to content

Commit 6ad8005

Browse files
Pull request #22: feature/EOA-5904-SS-Intellegence-Cloud-Api
Merge in SDK/python_telesign from feature/EOA-5904-SS-Intellegence-Cloud-Api to developer Squashed commit of the following: commit 712528498ec48a9470d4fe679a735fae38b94065 Merge: 40a2fe3 c9be38c Author: Juan Camilo Martinez <jmartinez@telesign.com> Date: Mon Jan 19 10:39:59 2026 -0500 Solving issues merge commit 40a2fe34fbbb7c0f9bb20656e2a05bbb9e11d13f Author: MousumiMohanty <@telesign.com> Date: Fri Oct 31 11:41:56 2025 +0530 comments updated commit 963e61c936d016d421496ce3c03a56b10384e679 Author: MousumiMohanty <@telesign.com> Date: Thu Oct 30 15:08:27 2025 +0530 update the setup version commit 25163417f6d7cb8117714bdcb563a408442f053c Author: MousumiMohanty <@telesign.com> Date: Thu Oct 30 11:13:40 2025 +0530 Added support for Intelligence Cloud to use new endpoint
1 parent c9be38c commit 6ad8005

5 files changed

Lines changed: 126 additions & 59 deletions

File tree

RELEASE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
4.0.0
2+
- Added support for Intelligence Cloud to use new endpoint
3+
14
3.0.1
25
- Removed deprecated pkg_resources.declare_namespace() usage.
36
- Cleaned up old mock dependency logic.

examples/score/1_check_phone_number_risk_level.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,24 @@
22
from telesign.score import ScoreClient
33

44
customer_id = "FFFFFFFF-EEEE-DDDD-1234-AB1234567890"
5-
api_key = "EXAMPLE----TE8sTgg45yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw=="
5+
api_key = "ABC12345yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw=="
66

77
phone_number = "phone_number"
88
account_lifecycle_event = "create"
99

10-
data = ScoreClient(customer_id, api_key)
11-
response = data.score(phone_number, account_lifecycle_event)
10+
score_client = ScoreClient(customer_id, api_key)
11+
response = score_client.score(phone_number, account_lifecycle_event)
1212

1313
if response.ok:
14-
print("Phone number {} has a '{}' risk level and the recommendation is to '{}' the transaction.".format(
15-
phone_number,
16-
response.json['risk']['level'],
17-
response.json['risk']['recommendation']))
14+
print(
15+
"Phone number {} has a '{}' risk level and the recommendation is to '{}' the transaction.".format(
16+
phone_number,
17+
response.json['risk']['level'],
18+
response.json['risk']['recommendation'])
19+
)
20+
else:
21+
print(
22+
"Request failed with status code: {}. Details: {}".format(
23+
response.status_code,
24+
response.json)
25+
)

setup.py

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,48 @@
44

55
from setuptools import setup, find_packages
66

7-
EXCLUDE_FROM_PACKAGES = ['tests']
7+
EXCLUDE_FROM_PACKAGES = ["tests"]
88

99
here = path.abspath(path.dirname(__file__))
1010

11-
version = "3.0.1"
11+
version = "4.0.0"
1212

13-
with open(path.join(here, 'README.rst'), encoding='utf-8') as f:
13+
with open(path.join(here, "README.rst"), encoding="utf-8") as f:
1414
long_description = f.read()
1515

16-
setup(name='telesign',
17-
version=version,
18-
description="TeleSign SDK",
19-
license="MIT",
20-
classifiers=[
21-
"Development Status :: 5 - Production/Stable",
22-
"Intended Audience :: Developers",
23-
"License :: OSI Approved :: MIT License",
24-
"Natural Language :: English",
25-
"Programming Language :: Python",
26-
"Programming Language :: Python :: 2",
27-
"Programming Language :: Python :: 2.6",
28-
"Programming Language :: Python :: 2.7",
29-
"Programming Language :: Python :: 3",
30-
"Programming Language :: Python :: 3.3",
31-
"Programming Language :: Python :: 3.4",
32-
"Programming Language :: Python :: 3.5",
33-
"Programming Language :: Python :: 3.6",
34-
"Programming Language :: Python :: 3.7",
35-
"Programming Language :: Python :: 3.8",
36-
"Programming Language :: Python :: 3.9",
37-
"Programming Language :: Python :: 3.10",
38-
"Programming Language :: Python :: 3.11",
39-
"Programming Language :: Python :: 3.12",
40-
],
41-
long_description=long_description,
42-
keywords='telesign, sms, voice, mobile, authentication, identity, messaging',
43-
author='TeleSign Corp.',
44-
author_email='support@telesign.com',
45-
url="https://github.com/telesign/python_telesign",
46-
install_requires=['requests'],
47-
test_suite='nose.collector',
48-
tests_require=['nose', 'pytz'],
49-
packages=find_packages(exclude=EXCLUDE_FROM_PACKAGES),
50-
)
16+
setup(
17+
name="telesign",
18+
version=version,
19+
description="TeleSign SDK",
20+
license="MIT",
21+
classifiers=[
22+
"Development Status :: 5 - Production/Stable",
23+
"Intended Audience :: Developers",
24+
"License :: OSI Approved :: MIT License",
25+
"Natural Language :: English",
26+
"Programming Language :: Python",
27+
"Programming Language :: Python :: 2",
28+
"Programming Language :: Python :: 2.6",
29+
"Programming Language :: Python :: 2.7",
30+
"Programming Language :: Python :: 3",
31+
"Programming Language :: Python :: 3.3",
32+
"Programming Language :: Python :: 3.4",
33+
"Programming Language :: Python :: 3.5",
34+
"Programming Language :: Python :: 3.6",
35+
"Programming Language :: Python :: 3.7",
36+
"Programming Language :: Python :: 3.8",
37+
"Programming Language :: Python :: 3.9",
38+
"Programming Language :: Python :: 3.10",
39+
"Programming Language :: Python :: 3.11",
40+
"Programming Language :: Python :: 3.12",
41+
],
42+
long_description=long_description,
43+
keywords="telesign, sms, voice, mobile, authentication, identity, messaging",
44+
author="TeleSign Corp.",
45+
author_email="support@telesign.com",
46+
url="https://github.com/telesign/python_telesign",
47+
install_requires=["requests"],
48+
test_suite="nose.collector",
49+
tests_require=["nose", "pytz"],
50+
packages=find_packages(exclude=EXCLUDE_FROM_PACKAGES),
51+
)

telesign/score.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,35 @@
1-
from __future__ import unicode_literals
2-
31
from telesign.rest import RestClient
42

5-
SCORE_RESOURCE = "/v1/score/{phone_number}"
6-
3+
DETECT_HOST = "https://detect.telesign.com"
4+
INTELLIGENCE_RESOURCE = "/intelligence/phone"
75

86
class ScoreClient(RestClient):
97
"""
10-
Score provides risk information about a specified phone number.
8+
ScoreClient for TeleSign Intelligence Cloud.
9+
Supports POST /intelligence/phone endpoint(Cloud migration).
1110
"""
1211

13-
def __init__(self, customer_id, api_key, **kwargs):
14-
super(ScoreClient, self).__init__(customer_id, api_key, **kwargs)
12+
def __init__(self, customer_id, api_key, rest_endpoint=DETECT_HOST, **kwargs):
13+
super(ScoreClient, self).__init__(customer_id, api_key, rest_endpoint, **kwargs)
1514

1615
def score(self, phone_number, account_lifecycle_event, **params):
1716
"""
18-
Score is an API that delivers reputation scoring based on phone number intelligence, traffic patterns, machine
19-
learning, and a global data consortium.
20-
21-
See https://developer.telesign.com/docs/score-api for detailed API documentation.
17+
Obtain a risk recommendation for a phone number using Telesign Intelligence Cloud API.
18+
Required parameters:
19+
- phone_number
20+
- account_lifecycle_event ("create", "sign-in", "transact", "update", "delete")
21+
Optional parameters: account_id, device_id, email_address, external_id, originating_ip, etc.
2222
"""
23-
return self.post(SCORE_RESOURCE.format(phone_number=phone_number),
24-
account_lifecycle_event=account_lifecycle_event,
25-
**params)
23+
if not phone_number:
24+
raise ValueError("phone_number cannot be null or empty")
25+
26+
if not account_lifecycle_event:
27+
raise ValueError("account_lifecycle_event cannot be null or empty")
28+
29+
params["phone_number"] = phone_number
30+
params["account_lifecycle_event"] = account_lifecycle_event
31+
32+
return self.post(
33+
INTELLIGENCE_RESOURCE,
34+
**params
35+
)

tests/test_score.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from __future__ import unicode_literals
2+
import os
3+
from unittest import TestCase, mock
4+
from telesign.score import ScoreClient
5+
6+
class TestScoreClient(TestCase):
7+
def setUp(self):
8+
self.customer_id = os.getenv('CUSTOMER_ID', 'FFFFFFFF-EEEE-DDDD-1234-AB1234567890')
9+
self.api_key = os.getenv('API_KEY', 'ABC12345yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw==')
10+
self.phone_number_test = os.getenv('PHONE_NUMBER', 'phone_number')
11+
self.account_lifecycle_event = "create"
12+
13+
@mock.patch('telesign.rest.requests.Session.post')
14+
def test_score_method(self, mock_post):
15+
mock_response = mock.Mock()
16+
mock_response.ok = True
17+
mock_response.status_code = 200
18+
mock_response.headers = {'Content-Type': 'application/json'}
19+
mock_response.json.return_value = {
20+
"risk": {
21+
"level": "LOW",
22+
"recommendation": "allow"
23+
}
24+
}
25+
mock_post.return_value = mock_response
26+
27+
client = ScoreClient(self.customer_id, self.api_key)
28+
response = client.score(self.phone_number_test, self.account_lifecycle_event)
29+
30+
called_url = mock_post.call_args[0][0]
31+
self.assertIn('/intelligence/phone', called_url)
32+
33+
called_kwargs = mock_post.call_args[1] if mock_post.call_args else {}
34+
called_data = called_kwargs.get('data', '')
35+
36+
self.assertTrue(called_data, "POST data is empty, expected form parameters")
37+
self.assertIn(f'phone_number={self.phone_number_test}', called_data)
38+
self.assertIn(f'account_lifecycle_event={self.account_lifecycle_event}', called_data)
39+
40+
self.assertEqual(response.status_code, 200)
41+
self.assertTrue(response.ok)
42+
self.assertEqual(response.headers.get('Content-Type'), 'application/json')
43+
self.assertIn('risk', response.json)
44+
self.assertEqual(response.json['risk']['level'], 'LOW')
45+
self.assertEqual(response.json['risk']['recommendation'], 'allow')

0 commit comments

Comments
 (0)