Class: Sendly::RcsResource

Inherits:
Object
  • Object
show all
Defined in:
lib/sendly/rcs_resource.rb

Overview

RCS resource — discover your RCS agents and pre-flight recipient capability.

RCS is a first-class Sendly channel: send branded rich messages — text with suggested replies and actions, or rich cards — via client.messages.send(channel: "rcs", ...). RCS agents are registered by Sendly for your brand; contact support to set one up, then discover it with Sendly::RcsAgentsResource#list.

Delivery is per-recipient: not every device or network supports RCS. Text messages fall back to plain SMS automatically (billed as SMS) unless you pass fallback_to_sms: false; rich cards have no SMS form and only deliver to RCS-capable recipients. Use #capability to check a recipient before sending.

RCS sends and capability checks require a live API key (+sk_live_v1_xxx+).

Examples:

Check capability, then send

cap = client.rcs.capability(to: "+15551234567")
if cap.capable?
  client.messages.send(
    channel: "rcs",
    to: "+15551234567",
    text: "Your order has shipped!"
  )
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ RcsResource

Returns a new instance of RcsResource.



191
192
193
194
# File 'lib/sendly/rcs_resource.rb', line 191

def initialize(client)
  @client = client
  @agents = RcsAgentsResource.new(client)
end

Instance Attribute Details

#agentsRcsAgentsResource (readonly)

Returns List registered agents.

Returns:



189
190
191
# File 'lib/sendly/rcs_resource.rb', line 189

def agents
  @agents
end

Instance Method Details

#capability(to:, agent_id: nil) ⇒ RcsCapability

Check whether a recipient can receive RCS.

Probes the recipient's device and network. When the recipient is not capable, a text send falls back to plain SMS (unless the fallback is disabled) and a card send fails with rcs_not_supported_for_recipient.

Examples:

cap = client.rcs.capability(to: "+15551234567")
puts cap.capable?
puts cap.features.inspect

Parameters:

  • to (String)

    The recipient's number, in E.164 format

  • agent_id (String, nil) (defaults to: nil)

    The agent to probe with. Optional when your workspace has exactly one sendable agent; required (the API responds 400 rcs_agent_ambiguous) when it has more.

Returns:

Raises:



213
214
215
216
217
218
219
220
# File 'lib/sendly/rcs_resource.rb', line 213

def capability(to:, agent_id: nil)
  raise ValidationError, "to is required" if to.nil? || to.to_s.empty?

  params = { to: to }
  params[:agentId] = agent_id if agent_id
  response = @client.get("/rcs/capability", params)
  RcsCapability.new(response)
end