|
|
|
@ -1,21 +1,23 @@ |
|
|
|
|
#!/usr/bin/env python |
|
|
|
|
import pprint |
|
|
|
|
import os |
|
|
|
|
import json |
|
|
|
|
import random |
|
|
|
|
import string |
|
|
|
|
from flowroutenumbersandmessaging.flowroutenumbersandmessaging_client import FlowroutenumbersandmessagingClient |
|
|
|
|
from flowroutenumbersandmessaging.configuration import Configuration |
|
|
|
|
from flowroutenumbersandmessaging.flowroutenumbersandmessaging_client import \ |
|
|
|
|
FlowroutenumbersandmessagingClient |
|
|
|
|
|
|
|
|
|
print("Number/Route Management v2 & Messaging v2.1 Demo") |
|
|
|
|
|
|
|
|
|
# Set up your api credentials and test mobile number for outbound SMS or MMS |
|
|
|
|
basic_auth_user_name = os.environ.get('FR_ACCESS_KEY') |
|
|
|
|
basic_auth_password = os.environ.get('FR_SECRET_KEY') |
|
|
|
|
mobile_number = "YOUR_MOBILE_NUMBER" |
|
|
|
|
# basic_auth_user_name = os.environ.get('FR_ACCESS_KEY') |
|
|
|
|
# basic_auth_password = os.environ.get('FR_SECRET_KEY') |
|
|
|
|
mobile_number = "4254664078" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Instantiate API client and create controllers for Numbers, Messages, and Routes |
|
|
|
|
client = FlowroutenumbersandmessagingClient(basic_auth_user_name, basic_auth_password) |
|
|
|
|
# Instantiate API client and create controllers for Numbers, |
|
|
|
|
# Messages, and Routes |
|
|
|
|
client = FlowroutenumbersandmessagingClient(Configuration.basic_auth_user_name, |
|
|
|
|
Configuration.basic_auth_password) |
|
|
|
|
numbers_controller = client.numbers |
|
|
|
|
routes_controller = client.routes |
|
|
|
|
messages_controller = client.messages |
|
|
|
@ -24,7 +26,9 @@ print("--List Available Area Codes") |
|
|
|
|
max_setup_cost = 3.25 |
|
|
|
|
limit = 3 |
|
|
|
|
offset = None |
|
|
|
|
result = numbers_controller.list_available_area_codes(limit, offset, max_setup_cost) |
|
|
|
|
result = numbers_controller.list_available_area_codes(limit, |
|
|
|
|
offset, |
|
|
|
|
max_setup_cost) |
|
|
|
|
pprint.pprint(result) |
|
|
|
|
|
|
|
|
|
print("--List Available Exchange Codes") |
|
|
|
@ -32,7 +36,10 @@ limit = 3 |
|
|
|
|
offset = None |
|
|
|
|
max_setup_cost = None |
|
|
|
|
areacode = 347 |
|
|
|
|
result = numbers_controller.list_available_exchange_codes(limit, offset, max_setup_cost, areacode) |
|
|
|
|
result = numbers_controller.list_available_exchange_codes(limit, |
|
|
|
|
offset, |
|
|
|
|
max_setup_cost, |
|
|
|
|
areacode) |
|
|
|
|
pprint.pprint(result) |
|
|
|
|
|
|
|
|
|
print("--Search for Purchasable Phone Numbers") |
|
|
|
@ -43,20 +50,28 @@ limit = 3 |
|
|
|
|
offset = None |
|
|
|
|
rate_center = None |
|
|
|
|
state = None |
|
|
|
|
result = numbers_controller.search_for_purchasable_phone_numbers(starts_with, contains, ends_with, limit, offset, rate_center, state) |
|
|
|
|
result = numbers_controller.search_for_purchasable_phone_numbers(starts_with, |
|
|
|
|
contains, |
|
|
|
|
ends_with, |
|
|
|
|
limit, |
|
|
|
|
offset, |
|
|
|
|
rate_center, |
|
|
|
|
state) |
|
|
|
|
pprint.pprint(result) |
|
|
|
|
|
|
|
|
|
print("--Purchase a Phone Number") |
|
|
|
|
purchasable_number = result['data'][0]['id'] |
|
|
|
|
#result = numbers_controller.purchase_a_phone_number(purchasable_number) |
|
|
|
|
if len(result['data']): |
|
|
|
|
print("--Purchase a Phone Number") |
|
|
|
|
purchasable_number = result['data'][0]['id'] |
|
|
|
|
# result = numbers_controller.purchase_a_phone_number(purchasable_number) |
|
|
|
|
|
|
|
|
|
print("--List Account Phone Numbers") |
|
|
|
|
starts_with = 201 |
|
|
|
|
starts_with = None |
|
|
|
|
ends_with = None |
|
|
|
|
contains = None |
|
|
|
|
limit = 3 |
|
|
|
|
offset = None |
|
|
|
|
result = numbers_controller.list_account_phone_numbers(starts_with, ends_with, contains, limit, offset) |
|
|
|
|
result = numbers_controller.list_account_phone_numbers(starts_with, ends_with, |
|
|
|
|
contains, limit, offset) |
|
|
|
|
pprint.pprint(result) |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -66,10 +81,18 @@ result = numbers_controller.list_phone_number_details(number_id) |
|
|
|
|
pprint.pprint(result) |
|
|
|
|
|
|
|
|
|
print("---Create an Inbound Route") |
|
|
|
|
|
|
|
|
|
print("---First list all available edge strategies") |
|
|
|
|
# result = routes_controller.list_edge_strategies() |
|
|
|
|
# pprint.pprint(result) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Function to generate six-charac random string |
|
|
|
|
def id_generator(size=6, chars=string.ascii_lowercase + string.digits): |
|
|
|
|
return ''.join(random.choice(chars) for _ in range(size)) |
|
|
|
|
new_route = id_generator() + '.sonsofodin.com' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
new_route = '{}.sonsofodin.com'.format(id_generator()) |
|
|
|
|
alias = id_generator() |
|
|
|
|
for i in range(10): |
|
|
|
|
alias += str(i) |
|
|
|
@ -78,8 +101,9 @@ request_body = '{ \ |
|
|
|
|
"type": "route", \ |
|
|
|
|
"attributes": { \ |
|
|
|
|
"route_type": "host", \ |
|
|
|
|
"value": "' + new_route +'", \ |
|
|
|
|
"alias": "' + alias + '" \ |
|
|
|
|
"value": "' + new_route + '", \ |
|
|
|
|
"alias": "' + alias + '", \ |
|
|
|
|
"edge_strategy": "1" \ |
|
|
|
|
} \ |
|
|
|
|
} \ |
|
|
|
|
}' |
|
|
|
@ -97,7 +121,7 @@ secrouteid = result['data'][2]['id'] |
|
|
|
|
request_body = '{ \ |
|
|
|
|
"data": { \ |
|
|
|
|
"type": "route", \ |
|
|
|
|
"id": "' + str(prirouteid) +'" \ |
|
|
|
|
"id": "' + str(prirouteid) + '" \ |
|
|
|
|
} \ |
|
|
|
|
}' |
|
|
|
|
|
|
|
|
@ -111,7 +135,7 @@ else: |
|
|
|
|
request_body = '{ \ |
|
|
|
|
"data": { \ |
|
|
|
|
"type": "route", \ |
|
|
|
|
"id": "' + str(secrouteid) +'" \ |
|
|
|
|
"id": "' + str(secrouteid) + '" \ |
|
|
|
|
} \ |
|
|
|
|
}' |
|
|
|
|
|
|
|
|
@ -122,7 +146,21 @@ if result is None: |
|
|
|
|
else: |
|
|
|
|
print (result) |
|
|
|
|
|
|
|
|
|
body_with_space = "hello there{}how are you?".format(chr(160)) |
|
|
|
|
|
|
|
|
|
request_body = '{ \ |
|
|
|
|
"data": { \ |
|
|
|
|
"type": "message", \ |
|
|
|
|
"attributes": { \ |
|
|
|
|
"to": "' + str(mobile_number) + '", \ |
|
|
|
|
"from": "' + str(number_id) + '", \ |
|
|
|
|
"body": "' + unicode(body_with_space, "utf-8") + '", \ |
|
|
|
|
"is_mms": "false" \ |
|
|
|
|
} \ |
|
|
|
|
} \ |
|
|
|
|
}' |
|
|
|
|
|
|
|
|
|
request_body_mms = '{ \ |
|
|
|
|
"data": { \ |
|
|
|
|
"type": "message", \ |
|
|
|
|
"attributes": { \ |
|
|
|
@ -136,19 +174,19 @@ request_body = '{ \ |
|
|
|
|
}' |
|
|
|
|
|
|
|
|
|
print("---Send A Message") |
|
|
|
|
#result = messages_controller.send_a_message(request_body) |
|
|
|
|
#pprint.pprint(result) |
|
|
|
|
result = messages_controller.send_a_message(request_body) |
|
|
|
|
pprint.pprint(result) |
|
|
|
|
|
|
|
|
|
print("---Look Up A Set Of Messages") |
|
|
|
|
start_date = "2017-12-01" |
|
|
|
|
end_date = "2018-01-08" |
|
|
|
|
limit = 2 |
|
|
|
|
result = messages_controller.look_up_a_set_of_messages(start_date, end_date, limit) |
|
|
|
|
result = messages_controller.look_up_a_set_of_messages(start_date, |
|
|
|
|
end_date, |
|
|
|
|
limit) |
|
|
|
|
pprint.pprint(result) |
|
|
|
|
|
|
|
|
|
print ("---Look Up A Message Detail Record") |
|
|
|
|
message_id = result['data'][0]['id'] |
|
|
|
|
result = messages_controller.look_up_a_message_detail_record(message_id) |
|
|
|
|
pprint.pprint(result) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|