Class: SignalWire::REST::Namespaces::PhoneNumbersResource

Inherits:
CrudResource show all
Defined in:
lib/signalwire/rest/namespaces/phone_numbers.rb

Overview

Phone number management.

Supports the standard CRUD surface plus typed helpers for binding an inbound call to a handler (SWML webhook, cXML webhook, AI agent, call flow, RELAY application/topic). The binding model is: set call_handler and the handler-specific companion field on the phone number; the server auto-materializes the matching Fabric resource. See SignalWire::REST::PhoneCallHandler for the enum, and the porting-sdk’s phone-binding.md for the full model.

Instance Method Summary collapse

Methods inherited from CrudResource

#create, #delete, #get, #list, #update, update_method, update_method=

Constructor Details

#initialize(http) ⇒ PhoneNumbersResource

Returns a new instance of PhoneNumbersResource.



20
21
22
# File 'lib/signalwire/rest/namespaces/phone_numbers.rb', line 20

def initialize(http)
  super(http, '/api/relay/rest/phone_numbers')
end

Instance Method Details

#search(**params) ⇒ Object



24
25
26
# File 'lib/signalwire/rest/namespaces/phone_numbers.rb', line 24

def search(**params)
  @http.get(_path('search'), params.empty? ? nil : params)
end

#set_ai_agent(sid, agent_id:, **extra) ⇒ Object

Route inbound calls to an AI Agent Fabric resource by ID.



80
81
82
83
84
85
86
87
# File 'lib/signalwire/rest/namespaces/phone_numbers.rb', line 80

def set_ai_agent(sid, agent_id:, **extra)
  update(
    sid,
    call_handler: PhoneCallHandler::AI_AGENT,
    call_ai_agent_id: agent_id,
    **extra
  )
end

#set_call_flow(sid, flow_id:, version: nil, **extra) ⇒ Object

Route inbound calls to a Call Flow by ID.

version accepts “working_copy” or “current_deployed” (server default when omitted).



93
94
95
96
97
98
99
100
# File 'lib/signalwire/rest/namespaces/phone_numbers.rb', line 93

def set_call_flow(sid, flow_id:, version: nil, **extra)
  body = {
    call_handler: PhoneCallHandler::CALL_FLOW,
    call_flow_id: flow_id
  }
  body[:call_flow_version] = version unless version.nil?
  update(sid, **body, **extra)
end

#set_cxml_application(sid, application_id:, **extra) ⇒ Object

Route inbound calls to an existing cXML application by ID.



70
71
72
73
74
75
76
77
# File 'lib/signalwire/rest/namespaces/phone_numbers.rb', line 70

def set_cxml_application(sid, application_id:, **extra)
  update(
    sid,
    call_handler: PhoneCallHandler::LAML_APPLICATION,
    call_laml_application_id: application_id,
    **extra
  )
end

#set_cxml_webhook(sid, url:, fallback_url: nil, status_callback_url: nil, **extra) ⇒ Object

Route inbound calls to a cXML (Twilio-compat / LAML) webhook.

Despite the wire value laml_webhooks being plural, this creates a single cxml_webhook Fabric resource. fallback_url is used when the primary URL fails; status_callback_url receives call status updates.



59
60
61
62
63
64
65
66
67
# File 'lib/signalwire/rest/namespaces/phone_numbers.rb', line 59

def set_cxml_webhook(sid, url:, fallback_url: nil, status_callback_url: nil, **extra)
  body = {
    call_handler: PhoneCallHandler::LAML_WEBHOOKS,
    call_request_url: url
  }
  body[:call_fallback_url]        = fallback_url        unless fallback_url.nil?
  body[:call_status_callback_url] = status_callback_url unless status_callback_url.nil?
  update(sid, **body, **extra)
end

#set_relay_application(sid, name:, **extra) ⇒ Object

Route inbound calls to a named RELAY application.



103
104
105
106
107
108
109
110
# File 'lib/signalwire/rest/namespaces/phone_numbers.rb', line 103

def set_relay_application(sid, name:, **extra)
  update(
    sid,
    call_handler: PhoneCallHandler::RELAY_APPLICATION,
    call_relay_application: name,
    **extra
  )
end

#set_relay_topic(sid, topic:, status_callback_url: nil, **extra) ⇒ Object

Route inbound calls to a RELAY topic (client subscription).



113
114
115
116
117
118
119
120
# File 'lib/signalwire/rest/namespaces/phone_numbers.rb', line 113

def set_relay_topic(sid, topic:, status_callback_url: nil, **extra)
  body = {
    call_handler: PhoneCallHandler::RELAY_TOPIC,
    call_relay_topic: topic
  }
  body[:call_relay_topic_status_callback_url] = status_callback_url unless status_callback_url.nil?
  update(sid, **body, **extra)
end

#set_swml_webhook(sid, url:, **extra) ⇒ Hash

Route inbound calls to an SWML webhook URL.

Your backend returns an SWML document per call. The server auto-creates a swml_webhook Fabric resource keyed off this URL.

Parameters:

  • sid (String)

    the phone number SID (e.g. pn-...)

  • url (String)

    the SWML webhook URL

  • extra (Hash)

    additional fields passed to update

Returns:

  • (Hash)

    the updated phone number representation



44
45
46
47
48
49
50
51
# File 'lib/signalwire/rest/namespaces/phone_numbers.rb', line 44

def set_swml_webhook(sid, url:, **extra)
  update(
    sid,
    call_handler: PhoneCallHandler::RELAY_SCRIPT,
    call_relay_script_url: url,
    **extra
  )
end