Class: Sendly::TenDlcResource
- Inherits:
-
Object
- Object
- Sendly::TenDlcResource
- Defined in:
- lib/sendly/tendlc_resource.rb
Overview
10DLC resource — register your business for carrier review so you can text from local (10-digit) US numbers. The flow has three steps:
- Register a brand with #create_brand, then poll #get_brand until it is verified.
- Create a campaign under the verified brand with #create_campaign, then poll #get_campaign until it is active. #qualify pre-checks a use case before you create the campaign.
- Attach a number you own with #assign_number. Once the assignment is "Active", the number can send.
Writes require a live API key with the tendlc:write scope.
Instance Method Summary collapse
-
#assign_number(campaign_id, phone_number:) ⇒ TenDlcAssignment
Assign a phone number you own to an active (carrier-approved) campaign, making the number sendable.
-
#create_brand(legal_name:, dba: nil, ein: nil, entity_type: nil, vertical: nil, website: nil, email: nil, phone: nil, mobile_phone: nil, street: nil, city: nil, state: nil, postal_code: nil, country: nil, verification_id: nil) ⇒ TenDlcBrand
Register a brand for carrier review — step 1 of enabling local-number texting.
-
#create_campaign(brand_id:, use_case:, description:, message_flow:, sample_messages:, sub_use_cases: nil, opt_in_keywords: nil, opt_out_keywords: nil, help_keywords: nil, opt_in_message: nil, opt_out_message: nil, help_message: nil, embedded_link: nil, embedded_phone: nil) ⇒ TenDlcCampaign
Create a messaging campaign under a verified brand and submit it for carrier review.
-
#get_brand(id) ⇒ TenDlcBrand
Fetch one brand.
-
#get_campaign(id) ⇒ TenDlcCampaign
Fetch one campaign.
-
#initialize(client) ⇒ TenDlcResource
constructor
A new instance of TenDlcResource.
-
#list_assignments ⇒ Hash
List your number-to-campaign assignments.
-
#list_brands ⇒ Hash
List the brands registered for carrier review.
-
#list_campaigns ⇒ Hash
List your messaging campaigns.
-
#qualify(brand_id, use_case) ⇒ TenDlcQualifyResult
Pre-check whether a use case qualifies for a brand on the carrier network before creating a campaign.
Constructor Details
#initialize(client) ⇒ TenDlcResource
Returns a new instance of TenDlcResource.
197 198 199 |
# File 'lib/sendly/tendlc_resource.rb', line 197 def initialize(client) @client = client end |
Instance Method Details
#assign_number(campaign_id, phone_number:) ⇒ TenDlcAssignment
Assign a phone number you own to an active (carrier-approved) campaign, making the number sendable. Requires a live API key.
Idempotent — re-assigning the same number to the same campaign returns the existing assignment.
379 380 381 382 383 384 385 386 |
# File 'lib/sendly/tendlc_resource.rb', line 379 def assign_number(campaign_id, phone_number:) raise ValidationError, "Campaign ID is required" if campaign_id.nil? || campaign_id.to_s.empty? raise ValidationError, "phone_number is required" if phone_number.nil? || phone_number.to_s.empty? encoded_id = URI.encode_www_form_component(campaign_id) response = @client.post("/tendlc/campaigns/#{encoded_id}/assign", { phoneNumber: phone_number }) TenDlcAssignment.new(response["data"] || {}) end |
#create_brand(legal_name:, dba: nil, ein: nil, entity_type: nil, vertical: nil, website: nil, email: nil, phone: nil, mobile_phone: nil, street: nil, city: nil, state: nil, postal_code: nil, country: nil, verification_id: nil) ⇒ TenDlcBrand
Register a brand for carrier review — step 1 of enabling local-number texting. Requires a live API key.
The brand starts pending. Poll #get_brand until it is verified before creating a campaign.
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/sendly/tendlc_resource.rb', line 234 def create_brand(legal_name:, dba: nil, ein: nil, entity_type: nil, vertical: nil, website: nil, email: nil, phone: nil, mobile_phone: nil, street: nil, city: nil, state: nil, postal_code: nil, country: nil, verification_id: nil) raise ValidationError, "legal_name is required" if legal_name.nil? || legal_name.to_s.empty? body = { legalName: legal_name } body[:dba] = dba if dba body[:ein] = ein if ein body[:entityType] = entity_type if entity_type body[:vertical] = vertical if vertical body[:website] = website if website body[:email] = email if email body[:phone] = phone if phone body[:mobilePhone] = mobile_phone if mobile_phone body[:street] = street if street body[:city] = city if city body[:state] = state if state body[:postalCode] = postal_code if postal_code body[:country] = country if country body[:verificationId] = verification_id if verification_id response = @client.post("/tendlc/brands", body) TenDlcBrand.new(response["data"] || {}) end |
#create_campaign(brand_id:, use_case:, description:, message_flow:, sample_messages:, sub_use_cases: nil, opt_in_keywords: nil, opt_out_keywords: nil, help_keywords: nil, opt_in_message: nil, opt_out_message: nil, help_message: nil, embedded_link: nil, embedded_phone: nil) ⇒ TenDlcCampaign
Create a messaging campaign under a verified brand and submit it for carrier review. Requires a live API key.
The campaign starts pending. Poll #get_campaign until it is active before assigning numbers.
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 |
# File 'lib/sendly/tendlc_resource.rb', line 323 def create_campaign(brand_id:, use_case:, description:, message_flow:, sample_messages:, sub_use_cases: nil, opt_in_keywords: nil, opt_out_keywords: nil, help_keywords: nil, opt_in_message: nil, opt_out_message: nil, help_message: nil, embedded_link: nil, embedded_phone: nil) raise ValidationError, "brand_id is required" if brand_id.nil? || brand_id.to_s.empty? raise ValidationError, "use_case is required" if use_case.nil? || use_case.to_s.empty? raise ValidationError, "description is required" if description.nil? || description.to_s.empty? raise ValidationError, "message_flow is required" if .nil? || .to_s.empty? raise ValidationError, "sample_messages is required" if .nil? || .empty? body = { brandId: brand_id, useCase: use_case, description: description, messageFlow: , sampleMessages: } body[:subUseCases] = sub_use_cases if sub_use_cases body[:optInKeywords] = opt_in_keywords if opt_in_keywords body[:optOutKeywords] = opt_out_keywords if opt_out_keywords body[:helpKeywords] = help_keywords if help_keywords body[:optInMessage] = if body[:optOutMessage] = if body[:helpMessage] = if body[:embeddedLink] = unless .nil? body[:embeddedPhone] = unless .nil? response = @client.post("/tendlc/campaigns", body) TenDlcCampaign.new(response["data"] || {}) end |
#get_brand(id) ⇒ TenDlcBrand
Fetch one brand. Also refreshes its carrier-review status, so polling this method shows progress (pending -> verified/failed).
265 266 267 268 269 270 271 |
# File 'lib/sendly/tendlc_resource.rb', line 265 def get_brand(id) raise ValidationError, "Brand ID is required" if id.nil? || id.to_s.empty? encoded_id = URI.encode_www_form_component(id) response = @client.get("/tendlc/brands/#{encoded_id}") TenDlcBrand.new(response["data"] || {}) end |
#get_campaign(id) ⇒ TenDlcCampaign
Fetch one campaign. Also refreshes its carrier-review status, so polling this method shows progress (pending -> active) including throughput once carriers approve.
362 363 364 365 366 367 368 |
# File 'lib/sendly/tendlc_resource.rb', line 362 def get_campaign(id) raise ValidationError, "Campaign ID is required" if id.nil? || id.to_s.empty? encoded_id = URI.encode_www_form_component(id) response = @client.get("/tendlc/campaigns/#{encoded_id}") TenDlcCampaign.new(response["data"] || {}) end |
#list_assignments ⇒ Hash
List your number-to-campaign assignments.
391 392 393 394 395 |
# File 'lib/sendly/tendlc_resource.rb', line 391 def list_assignments response = @client.get("/tendlc/assignments") assignments = (response["data"] || []).map { |a| TenDlcAssignment.new(a) } { assignments: assignments } end |
#list_brands ⇒ Hash
List the brands registered for carrier review.
204 205 206 207 208 |
# File 'lib/sendly/tendlc_resource.rb', line 204 def list_brands response = @client.get("/tendlc/brands") brands = (response["data"] || []).map { |b| TenDlcBrand.new(b) } { brands: brands } end |
#list_campaigns ⇒ Hash
List your messaging campaigns.
293 294 295 296 297 |
# File 'lib/sendly/tendlc_resource.rb', line 293 def list_campaigns response = @client.get("/tendlc/campaigns") campaigns = (response["data"] || []).map { |c| TenDlcCampaign.new(c) } { campaigns: campaigns } end |
#qualify(brand_id, use_case) ⇒ TenDlcQualifyResult
Pre-check whether a use case qualifies for a brand on the carrier network before creating a campaign.
280 281 282 283 284 285 286 287 288 |
# File 'lib/sendly/tendlc_resource.rb', line 280 def qualify(brand_id, use_case) raise ValidationError, "Brand ID is required" if brand_id.nil? || brand_id.to_s.empty? raise ValidationError, "use_case is required" if use_case.nil? || use_case.to_s.empty? encoded_id = URI.encode_www_form_component(brand_id) encoded_use_case = URI.encode_www_form_component(use_case) response = @client.get("/tendlc/brands/#{encoded_id}/qualify/#{encoded_use_case}") TenDlcQualifyResult.new(response["data"] || {}) end |