Skip to content

Syniverse/QuickStart-BatchNumberMonitoring-Python

 
 

Repository files navigation

PhoneNumberMonitoring

Example code to subscribe & unsubscribe for Phone Number Monitoring from Syniverse.

By downloading the attached python files, and simply adding your access token and delivery configuration Id you can quickly set up monitoring for the phone numbers in the file phonenumbers.txt.

script File name

PNV-Batch-Scrub-Monitor-Tool.py

Dependencies

You will first need to have an account (create at https://developer.syniverse.com ).

Then follow the instructions at https://sdcdocumentation.syniverse.com/index.php/batch-automation/quick-start-batch-automation to set up the platform.

  • Syniverse Developer Community (SDC) Account

  • SDC Subscription to Phone Number Verification

  • SDC Application created with Batch Automation, Media Storage and Phone Number Verification enabled for the App.

  • Access Token for application

  • Delivery Configuration ID from ESS application

  • Company ID in case executing in QA environment

  • Python installed (version 3.6 used in the example)

  • time, zlib, csv, sys, os, requests module's should be installed ($pip install )

Provide Access token in the script

  • Open the script in a Text File or Python Editor Tool
  • provide the Bearer Token that you are authorized to use under the attribute access_token = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
  • For QA environment -> Update company_id also. company_id = 'XXXXXX'
  • For PROD environment keep it blank company_id = ''

Command to run the script/tool

  • Change directiry where input file is stored $ python <Script_Name> <input_file> <feature_set> <file_retention_days> <delivery_configuration_id>
  • Script_Name = PNV-Batch-Scrub-Monitor-Tool.py (If script is in different directory provide full path)
  • input_file = .txt Data File with Phone Numbers to Scrub and monitor in ASCII Text format (phone numbers within the file should be mentioned in E164 format eg.+1831325XXXX,,)
  • feature_set = fs1, fs5
  • file_retention_days = anywhere between 1 and 7
  • delivery_configuration_id should be from ESS application
  • environment = QA or PROD

Eg., In order to run from command line:

  • $ python PNV-Batch-Scrub-Monitor-Tool.py phonenumbers.txt fs1 1 1758 QA

How to identify output files

  • All the output files, are generated in the same directory.

  • The following files are created only when there is a success, error or retry output,

  • else the files will not be created.

  • --PNV-Scrub-Retry-.txt

  • --PNV-Scrub-Success-.zip

  • --PNV-Scrub-Error-.txt

    • you will need to take back up of these files before you can start the next process. else the files will be overwritten.

Sample output when running the Unsubscribe script is

python.exe PycharmProjects/BatchMonitor/BatchMonitorUnsubscribe-Example.py Starting Engines

Creating file in Media Storage create file response status code: 201 mss create response body: {"file_id":"08fb7e20-3dae-47ea-936f-469a17b9d6ac","company-id":"589","file_status":"CREATED","file_uri":"https://api.syniverse.com/mediastorage/v1/files/08fb7e20-3dae-47ea-936f-469a17b9d6ac/content","file_version":1,"file_checksum":0,"file_size":0,"file_fullsize":2000000,"creation_time":"2017-07-28T09:04:44.063 +0000","modified_time":"2017-07-28T09:04:44.063 +0000","file_retention_time":30,"expire_time":"2017-08-27T09:04:44.063 +0000"}

Uploading input file to Media Storage upload response status code: 201 upload response:

Scheduling the Number Monitoring Unsubscribe batch job in Batch Automation Scheduling response status code: 201 Scheduling response: {"schedule":{"id":"cf5850e3-147a-4e7c-b32b-914b264fb501","jobId":"NIS-Unsubscribe-v2","name":"NISUnsubscribe","inputFileId":"08fb7e20-3dae-47ea-936f-469a17b9d6ac","fileRetentionDays":30,"scheduleRetentionDays":30,"outputFileNamingExpression":"DS1-NIS-Unsubscribe-output.txt","outputFileFolder":"/opt/apps/aba/output","outputFileTag":null,"jobRuntimeContext":{}}}

Waiting 20s for job to complete

Retrieving batch job execution details Get batch job details status code: 200 Get batch job details response: {"executions":[{"id":"74e8e09f-224b-482e-a7f4-8189dedb939e","scheduleDetail":{"id":"cf5850e3-147a-4e7c-b32b-914b264fb501","jobId":"NIS-Unsubscribe-v2","name":"NISUnsubscribe","inputFileId":"08fb7e20-3dae-47ea-936f-469a17b9d6ac","fileRetentionDays":30,"scheduleRetentionDays":30,"outputFileNamingExpression":"DS1-NIS-Unsubscribe-output.txt","outputFileFolder":"/opt/apps/aba/output","outputFileTag":null,"jobRuntimeContext":{}},"status":"COMPLETE","statusReason":"Final Status","startTimestamp":1501232693409,"statusUpdateTimestamp":1501232698016,"outputFileId":"ba0f8c70-ab93-44eb-bd7a-2c0b2e14b0f7","errorDetailFileId":"EMPTY_FILE","retryFileId":"EMPTY_FILE","recordSuccessCount":3,"recordRetryCount":0,"recordErrorCount":0,"outputFileURI":"https://api.syniverse.com/mediastorage/v1/files/ba0f8c70-ab93-44eb-bd7a-2c0b2e14b0f7/content","errorDetailFileURI":"EMPTY_FILE","retryFileURI":"EMPTY_FILE"}]}

Downloading the Output file Download output status code: 200 Download output response: +18132633923,unsubscribe,ALL,2017-07-28T09:04:55.564Z[UTC] +18135041457,unsubscribe,ALL,2017-07-28T09:04:55.559Z[UTC] +18139551760,unsubscribe,ALL,2017-07-28T09:04:55.564Z[UTC]

Process finished with exit code 0

Example Phone Event Notification

Once subscribed you will receive a notification if anything happens to a subscribed phone number.

Notifications are sent by the Event Manager system (https://sdcdocumentation.syniverse.com/index.php/event-manager/overview) as a POST request to your defined end point.

The headers and payload for an example notification are shown below.

HEADERS   "X-ESS-EVENT-KEY": "+17805199493,",   "X-ESS-EVENT-TIMESTAMP": "2017-07-12T20:21:00.129Z",   "CONTENT-TYPE": "application/json; charset=UTF-8"

BODY/PAYLOAD {"topic":"NIS-Events","attempt":1,"event":{"fld-val-list":{"number":"+17805199493","previous_carrier_id":"1025","previous_carrier_name":"AT@$# T WIRELESS","tracking_id":"1655272074","deactivation_date":"2017-06-03T04:00:00Z"},"evt-tp":"deactivation_event","timestamp":"2017-07-12T20:21:00.129Z"},"event-id":"d0qgWF8ERLGn_7JJOGhqNQ"}

About

How to subscribe & unsubscribe to Monitoring Phone numbers using SDC and Python

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%