telnyx-10dlc-python
npx skills add https://github.com/team-telnyx/telnyx-ext-agent-skills --skill telnyx-10dlc-python
Agent 安装分布
Skill 文档
Telnyx 10Dlc – Python
Installation
pip install telnyx
Setup
import os
from telnyx import Telnyx
client = Telnyx(
api_key=os.environ.get("TELNYX_API_KEY"), # This is the default and can be omitted
)
All examples below assume client is already initialized as shown above.
List Brands
This endpoint is used to list all brands associated with your organization.
GET /10dlc/brand
page = client.messaging_10dlc.brand.list()
page = page.records[0]
print(page.identity_status)
Create Brand
This endpoint is used to create a new brand.
POST /10dlc/brand â Required: entityType, displayName, country, email, vertical
Optional: businessContactEmail (string), city (string), companyName (string), ein (string), firstName (string), ipAddress (string), isReseller (boolean), lastName (string), mobilePhone (string), mock (boolean), phone (string), postalCode (string), state (string), stockExchange (object), stockSymbol (string), street (string), webhookFailoverURL (string), webhookURL (string), website (string)
telnyx_brand = client.messaging_10dlc.brand.create(
country="US",
display_name="ABC Mobile",
email="email",
entity_type="PRIVATE_PROFIT",
vertical="TECHNOLOGY",
)
print(telnyx_brand.identity_status)
Get Brand
Retrieve a brand by brandId.
GET /10dlc/brand/{brandId}
brand = client.messaging_10dlc.brand.retrieve(
"brandId",
)
print(brand)
Update Brand
Update a brand’s attributes by brandId.
PUT /10dlc/brand/{brandId} â Required: entityType, displayName, country, email, vertical
Optional: altBusinessId (string), altBusinessIdType (enum), businessContactEmail (string), city (string), companyName (string), ein (string), firstName (string), identityStatus (enum), ipAddress (string), isReseller (boolean), lastName (string), phone (string), postalCode (string), state (string), stockExchange (object), stockSymbol (string), street (string), webhookFailoverURL (string), webhookURL (string), website (string)
telnyx_brand = client.messaging_10dlc.brand.update(
brand_id="brandId",
country="US",
display_name="ABC Mobile",
email="email",
entity_type="PRIVATE_PROFIT",
vertical="TECHNOLOGY",
)
print(telnyx_brand.identity_status)
Delete Brand
Delete Brand.
DELETE /10dlc/brand/{brandId}
client.messaging_10dlc.brand.delete(
"brandId",
)
Resend brand 2FA email
POST /10dlc/brand/{brandId}/2faEmail
client.messaging_10dlc.brand.resend_2fa_email(
"brandId",
)
List External Vettings
Get list of valid external vetting record for a given brand
GET /10dlc/brand/{brandId}/externalVetting
external_vettings = client.messaging_10dlc.brand.external_vetting.list(
"brandId",
)
print(external_vettings)
Order Brand External Vetting
Order new external vetting for a brand
POST /10dlc/brand/{brandId}/externalVetting â Required: evpId, vettingClass
response = client.messaging_10dlc.brand.external_vetting.order(
brand_id="brandId",
evp_id="evpId",
vetting_class="vettingClass",
)
print(response.create_date)
Import External Vetting Record
This operation can be used to import an external vetting record from a TCR-approved vetting provider.
PUT /10dlc/brand/{brandId}/externalVetting â Required: evpId, vettingId
Optional: vettingToken (string)
response = client.messaging_10dlc.brand.external_vetting.imports(
brand_id="brandId",
evp_id="evpId",
vetting_id="vettingId",
)
print(response.create_date)
Revet Brand
This operation allows you to revet the brand.
PUT /10dlc/brand/{brandId}/revet
telnyx_brand = client.messaging_10dlc.brand.revet(
"brandId",
)
print(telnyx_brand.identity_status)
Get Brand SMS OTP Status by Brand ID
Query the status of an SMS OTP (One-Time Password) for Sole Proprietor brand verification using the Brand ID.
GET /10dlc/brand/{brandId}/smsOtp
response = client.messaging_10dlc.brand.retrieve_sms_otp_status(
"4b20019b-043a-78f8-0657-b3be3f4b4002",
)
print(response.brand_id)
Trigger Brand SMS OTP
Trigger or re-trigger an SMS OTP (One-Time Password) for Sole Proprietor brand verification.
POST /10dlc/brand/{brandId}/smsOtp â Required: pinSms, successSms
response = client.messaging_10dlc.brand.trigger_sms_otp(
brand_id="4b20019b-043a-78f8-0657-b3be3f4b4002",
pin_sms="Your PIN is @OTP_PIN@",
success_sms="Verification successful!",
)
print(response.brand_id)
Verify Brand SMS OTP
Verify the SMS OTP (One-Time Password) for Sole Proprietor brand verification.
PUT /10dlc/brand/{brandId}/smsOtp â Required: otpPin
client.messaging_10dlc.brand.verify_sms_otp(
brand_id="4b20019b-043a-78f8-0657-b3be3f4b4002",
otp_pin="123456",
)
Get Brand SMS OTP Status
Query the status of an SMS OTP (One-Time Password) for Sole Proprietor brand verification.
GET /10dlc/brand/smsOtp/{referenceId}
response = client.messaging_10dlc.brand.get_sms_otp_by_reference(
reference_id="OTP4B2001",
)
print(response.brand_id)
Get Brand Feedback By Id
Get feedback about a brand by ID.
GET /10dlc/brand_feedback/{brandId}
response = client.messaging_10dlc.brand.get_feedback(
"brandId",
)
print(response.brand_id)
Submit Campaign
Before creating a campaign, use the Qualify By Usecase endpoint to ensure that the brand you want to assign a new campaign…
POST /10dlc/campaignBuilder â Required: brandId, description, usecase
Optional: ageGated (boolean), autoRenewal (boolean), directLending (boolean), embeddedLink (boolean), embeddedLinkSample (string), embeddedPhone (boolean), helpKeywords (string), helpMessage (string), messageFlow (string), mnoIds (array[integer]), numberPool (boolean), optinKeywords (string), optinMessage (string), optoutKeywords (string), optoutMessage (string), privacyPolicyLink (string), referenceId (string), resellerId (string), sample1 (string), sample2 (string), sample3 (string), sample4 (string), sample5 (string), subUsecases (array[string]), subscriberHelp (boolean), subscriberOptin (boolean), subscriberOptout (boolean), tag (array[string]), termsAndConditions (boolean), termsAndConditionsLink (string), webhookFailoverURL (string), webhookURL (string)
telnyx_campaign_csp = client.messaging_10dlc.campaign_builder.submit(
brand_id="brandId",
description="description",
usecase="usecase",
)
print(telnyx_campaign_csp.brand_id)
Qualify By Usecase
This endpoint allows you to see whether or not the supplied brand is suitable for your desired campaign use case.
GET /10dlc/campaignBuilder/brand/{brandId}/usecase/{usecase}
response = client.messaging_10dlc.campaign_builder.brand.qualify_by_usecase(
usecase="usecase",
brand_id="brandId",
)
print(response.annual_fee)
List Campaigns
Retrieve a list of campaigns associated with a supplied brandId.
GET /10dlc/campaign
page = client.messaging_10dlc.campaign.list(
brand_id="brandId",
)
page = page.records[0]
print(page.age_gated)
Get campaign
Retrieve campaign details by campaignId.
GET /10dlc/campaign/{campaignId}
telnyx_campaign_csp = client.messaging_10dlc.campaign.retrieve(
"campaignId",
)
print(telnyx_campaign_csp.brand_id)
Update campaign
Update a campaign’s properties by campaignId.
PUT /10dlc/campaign/{campaignId}
Optional: autoRenewal (boolean), helpMessage (string), messageFlow (string), resellerId (string), sample1 (string), sample2 (string), sample3 (string), sample4 (string), sample5 (string), webhookFailoverURL (string), webhookURL (string)
telnyx_campaign_csp = client.messaging_10dlc.campaign.update(
campaign_id="campaignId",
)
print(telnyx_campaign_csp.brand_id)
Deactivate campaign
Terminate a campaign.
DELETE /10dlc/campaign/{campaignId}
response = client.messaging_10dlc.campaign.deactivate(
"campaignId",
)
print(response.time)
Submit campaign appeal for manual review
Submits an appeal for rejected native campaigns in TELNYX_FAILED or MNO_REJECTED status.
POST /10dlc/campaign/{campaignId}/appeal â Required: appeal_reason
response = client.messaging_10dlc.campaign.submit_appeal(
campaign_id="5eb13888-32b7-4cab-95e6-d834dde21d64",
appeal_reason="The website has been updated to include the required privacy policy and terms of service.",
)
print(response.appealed_at)
Get Campaign Mno Metadata
Get the campaign metadata for each MNO it was submitted to.
GET /10dlc/campaign/{campaignId}/mnoMetadata
response = client.messaging_10dlc.campaign.get_mno_metadata(
"campaignId",
)
print(response._10999)
Get campaign operation status
Retrieve campaign’s operation status at MNO level.
GET /10dlc/campaign/{campaignId}/operationStatus
response = client.messaging_10dlc.campaign.get_operation_status(
"campaignId",
)
print(response)
Get OSR campaign attributes
GET /10dlc/campaign/{campaignId}/osr_attributes
response = client.messaging_10dlc.campaign.osr.get_attributes(
"campaignId",
)
print(response)
Get Sharing Status
GET /10dlc/campaign/{campaignId}/sharing
response = client.messaging_10dlc.campaign.get_sharing_status(
"campaignId",
)
print(response.shared_by_me)
Accept Shared Campaign
Manually accept a campaign shared with Telnyx
POST /10dlc/campaign/acceptSharing/{campaignId}
response = client.messaging_10dlc.campaign.accept_sharing(
"C26F1KLZN",
)
print(response)
Get Campaign Cost
GET /10dlc/campaign/usecase_cost
response = client.messaging_10dlc.campaign.usecase.get_cost(
usecase="usecase",
)
print(response.campaign_usecase)
List Shared Campaigns
Retrieve all partner campaigns you have shared to Telnyx in a paginated fashion.
GET /10dlc/partner_campaigns
page = client.messaging_10dlc.partner_campaigns.list()
page = page.records[0]
print(page.tcr_brand_id)
Get Single Shared Campaign
Retrieve campaign details by campaignId.
GET /10dlc/partner_campaigns/{campaignId}
telnyx_downstream_campaign = client.messaging_10dlc.partner_campaigns.retrieve(
"campaignId",
)
print(telnyx_downstream_campaign.tcr_brand_id)
Update Single Shared Campaign
Update campaign details by campaignId.
PATCH /10dlc/partner_campaigns/{campaignId}
Optional: webhookFailoverURL (string), webhookURL (string)
telnyx_downstream_campaign = client.messaging_10dlc.partner_campaigns.update(
campaign_id="campaignId",
)
print(telnyx_downstream_campaign.tcr_brand_id)
Get Sharing Status
GET /10dlc/partnerCampaign/{campaignId}/sharing
response = client.messaging_10dlc.partner_campaigns.retrieve_sharing_status(
"campaignId",
)
print(response)
List shared partner campaigns
Get all partner campaigns you have shared to Telnyx in a paginated fashion
This endpoint is currently limited to only returning shared campaigns that Telnyx has accepted.
GET /10dlc/partnerCampaign/sharedByMe
page = client.messaging_10dlc.partner_campaigns.list_shared_by_me()
page = page.records[0]
print(page.brand_id)
List phone number campaigns
GET /10dlc/phone_number_campaigns
page = client.messaging_10dlc.phone_number_campaigns.list()
page = page.records[0]
print(page.campaign_id)
Create New Phone Number Campaign
POST /10dlc/phone_number_campaigns â Required: phoneNumber, campaignId
phone_number_campaign = client.messaging_10dlc.phone_number_campaigns.create(
campaign_id="4b300178-131c-d902-d54e-72d90ba1620j",
phone_number="+18005550199",
)
print(phone_number_campaign.campaign_id)
Get Single Phone Number Campaign
Retrieve an individual phone number/campaign assignment by phoneNumber.
GET /10dlc/phone_number_campaigns/{phoneNumber}
phone_number_campaign = client.messaging_10dlc.phone_number_campaigns.retrieve(
"phoneNumber",
)
print(phone_number_campaign.campaign_id)
Create New Phone Number Campaign
PUT /10dlc/phone_number_campaigns/{phoneNumber} â Required: phoneNumber, campaignId
phone_number_campaign = client.messaging_10dlc.phone_number_campaigns.update(
campaign_phone_number="phoneNumber",
campaign_id="4b300178-131c-d902-d54e-72d90ba1620j",
phone_number="+18005550199",
)
print(phone_number_campaign.campaign_id)
Delete Phone Number Campaign
This endpoint allows you to remove a campaign assignment from the supplied phoneNumber.
DELETE /10dlc/phone_number_campaigns/{phoneNumber}
phone_number_campaign = client.messaging_10dlc.phone_number_campaigns.delete(
"phoneNumber",
)
print(phone_number_campaign.campaign_id)
Assign Messaging Profile To Campaign
This endpoint allows you to link all phone numbers associated with a Messaging Profile to a campaign.
POST /10dlc/phoneNumberAssignmentByProfile â Required: messagingProfileId
Optional: campaignId (string), tcrCampaignId (string)
response = client.messaging_10dlc.phone_number_assignment_by_profile.assign(
messaging_profile_id="4001767e-ce0f-4cae-9d5f-0d5e636e7809",
)
print(response.messaging_profile_id)
Get Assignment Task Status
Check the status of the task associated with assigning all phone numbers on a messaging profile to a campaign by taskId.
GET /10dlc/phoneNumberAssignmentByProfile/{taskId}
response = client.messaging_10dlc.phone_number_assignment_by_profile.retrieve_status(
"taskId",
)
print(response.status)
Get Phone Number Status
Check the status of the individual phone number/campaign assignments associated with the supplied taskId.
GET /10dlc/phoneNumberAssignmentByProfile/{taskId}/phoneNumbers
response = client.messaging_10dlc.phone_number_assignment_by_profile.list_phone_number_status(
task_id="taskId",
)
print(response.records)
Webhooks
The following webhook events are sent to your configured webhook URL.
All webhooks include telnyx-timestamp and telnyx-signature-ed25519 headers for verification (Standard Webhooks compatible).
| Event | Description |
|---|---|
campaignStatusUpdate |
Campaign Status Update |
Webhook payload fields
campaignStatusUpdate
| Field | Type | Description |
|---|---|---|
brandId |
string | Brand ID associated with the campaign. |
campaignId |
string | The ID of the campaign. |
createDate |
string | Unix timestamp when campaign was created. |
cspId |
string | Alphanumeric identifier of the CSP associated with this campaign. |
isTMobileRegistered |
boolean | Indicates whether the campaign is registered with T-Mobile. |
type |
enum | |
description |
string | Description of the event. |
status |
enum | The status of the campaign. |