Loading...
Loading...
Create and manage messaging profiles with number pools, sticky sender, and geomatch features. Configure short codes for high-volume messaging. This skill provides Python SDK examples.
npx skill4agent add team-telnyx/skills telnyx-messaging-profiles-pythonpip install telnyximport os
from telnyx import Telnyx
client = Telnyx(
api_key=os.environ.get("TELNYX_API_KEY"), # This is the default and can be omitted
)clientimport telnyx
try:
result = client.messages.send(to="+13125550001", from_="+13125550002", text="Hello")
except telnyx.APIConnectionError:
print("Network error — check connectivity and retry")
except telnyx.RateLimitError:
# 429: rate limited — wait and retry with exponential backoff
import time
time.sleep(1) # Check Retry-After header for actual delay
except telnyx.APIStatusError as e:
print(f"API error {e.status_code}: {e.message}")
if e.status_code == 422:
print("Validation error — check required fields and formats")401403404422429for item in page_result:GET /messaging_profilespage = client.messaging_profiles.list()
page = page.data[0]
print(page.id)ai_assistant_idalpha_sendercreated_atdaily_spend_limitdaily_spend_limit_enabledenabledhealth_webhook_urlidmms_fall_back_to_smsmms_transcodingmobile_onlynamenumber_pool_settingsorganization_idrecord_typeredaction_enabledredaction_levelresource_group_idsmart_encodingupdated_aturl_shortener_settingsv1_secretwebhook_api_versionwebhook_failover_urlwebhook_urlwhitelisted_destinationsPOST /messaging_profilesnamewhitelisted_destinationsai_assistant_idalpha_senderdaily_spend_limitdaily_spend_limit_enabledenabledhealth_webhook_urlmms_fall_back_to_smsmms_transcodingmobile_onlynumber_pool_settingsresource_group_idsmart_encodingurl_shortener_settingswebhook_api_versionwebhook_failover_urlwebhook_urlmessaging_profile = client.messaging_profiles.create(
name="My name",
whitelisted_destinations=["US"],
)
print(messaging_profile.data)ai_assistant_idalpha_sendercreated_atdaily_spend_limitdaily_spend_limit_enabledenabledhealth_webhook_urlidmms_fall_back_to_smsmms_transcodingmobile_onlynamenumber_pool_settingsorganization_idrecord_typeredaction_enabledredaction_levelresource_group_idsmart_encodingupdated_aturl_shortener_settingsv1_secretwebhook_api_versionwebhook_failover_urlwebhook_urlwhitelisted_destinationsGET /messaging_profiles/{id}messaging_profile = client.messaging_profiles.retrieve(
"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
)
print(messaging_profile.data)ai_assistant_idalpha_sendercreated_atdaily_spend_limitdaily_spend_limit_enabledenabledhealth_webhook_urlidmms_fall_back_to_smsmms_transcodingmobile_onlynamenumber_pool_settingsorganization_idrecord_typeredaction_enabledredaction_levelresource_group_idsmart_encodingupdated_aturl_shortener_settingsv1_secretwebhook_api_versionwebhook_failover_urlwebhook_urlwhitelisted_destinationsPATCH /messaging_profiles/{id}alpha_sendercreated_atdaily_spend_limitdaily_spend_limit_enabledenabledidmms_fall_back_to_smsmms_transcodingmobile_onlynamenumber_pool_settingsrecord_typesmart_encodingupdated_aturl_shortener_settingsv1_secretwebhook_api_versionwebhook_failover_urlwebhook_urlwhitelisted_destinationsmessaging_profile = client.messaging_profiles.update(
messaging_profile_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
)
print(messaging_profile.data)ai_assistant_idalpha_sendercreated_atdaily_spend_limitdaily_spend_limit_enabledenabledhealth_webhook_urlidmms_fall_back_to_smsmms_transcodingmobile_onlynamenumber_pool_settingsorganization_idrecord_typeredaction_enabledredaction_levelresource_group_idsmart_encodingupdated_aturl_shortener_settingsv1_secretwebhook_api_versionwebhook_failover_urlwebhook_urlwhitelisted_destinationsDELETE /messaging_profiles/{id}messaging_profile = client.messaging_profiles.delete(
"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
)
print(messaging_profile.data)ai_assistant_idalpha_sendercreated_atdaily_spend_limitdaily_spend_limit_enabledenabledhealth_webhook_urlidmms_fall_back_to_smsmms_transcodingmobile_onlynamenumber_pool_settingsorganization_idrecord_typeredaction_enabledredaction_levelresource_group_idsmart_encodingupdated_aturl_shortener_settingsv1_secretwebhook_api_versionwebhook_failover_urlwebhook_urlwhitelisted_destinationsGET /messaging_profiles/{id}/phone_numberspage = client.messaging_profiles.list_phone_numbers(
messaging_profile_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
)
page = page.data[0]
print(page.id)country_codecreated_ateligible_messaging_productsfeatureshealthidmessaging_productmessaging_profile_idorganization_idphone_numberrecord_typetagstraffic_typetypeupdated_atGET /messaging_profiles/{id}/short_codespage = client.messaging_profiles.list_short_codes(
messaging_profile_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
)
page = page.data[0]
print(page.messaging_profile_id)country_codecreated_atidmessaging_profile_idrecord_typeshort_codetagsupdated_atGET /short_codespage = client.short_codes.list()
page = page.data[0]
print(page.messaging_profile_id)country_codecreated_atidmessaging_profile_idrecord_typeshort_codetagsupdated_atGET /short_codes/{id}short_code = client.short_codes.retrieve(
"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
)
print(short_code.data)country_codecreated_atidmessaging_profile_idrecord_typeshort_codetagsupdated_atmessaging_profile_idnullPATCH /short_codes/{id}messaging_profile_idtagsshort_code = client.short_codes.update(
id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
messaging_profile_id="abc85f64-5717-4562-b3fc-2c9600000000",
)
print(short_code.data)country_codecreated_atidmessaging_profile_idrecord_typeshort_codetagsupdated_at