Class: Nexmo::SMS

Inherits:
Namespace
  • Object
show all
Defined in:
lib/nexmo/sms.rb

Defined Under Namespace

Classes: Response

Instance Method Summary collapse

Instance Method Details

#send(params) ⇒ Response

Send an outbound SMS from your Nexmo account.

Examples:

response = client.sms.send(from: 'Ruby', to: '447700900000', text: 'Hello world')

if response.success?
  puts "Sent message id=#{response.messages.first.message_id}"
else
  puts "Error: #{response.messages.first.error_text}"
end

Parameters:

  • params (Hash)

Options Hash (params):

  • :from (required, String)

    The name or number the message should be sent from. Alphanumeric senderID's are not supported in all countries, see [Global Messaging](developer.nexmo.com/messaging/sms/guides/global-messaging#country-specific-features) for more details. If alphanumeric, spaces will be ignored. Numbers are specified in E.164 format.

  • :to (required, String)

    The number that the message should be sent to. Numbers are specified in E.164 format.

  • :text (String)

    The body of the message being sent. If your message contains characters that can be encoded according to the GSM Standard and Extended tables then you can set the :type to `text`. If your message contains characters outside this range, then you will need to set the :type to `unicode`.

  • :ttl (Integer)

    The duration in milliseconds the delivery of an SMS will be attempted. By default Nexmo attempt delivery for 72 hours, however the maximum effective value depends on the operator and is typically 24 - 48 hours. We recommend this value should be kept at its default or at least 30 minutes.

  • :status_report_req (Boolean)

    Boolean indicating if you like to receive a [Delivery Receipt](developer.nexmo.com/messaging/sms/building-blocks/receive-a-delivery-receipt).

  • :callback (String)

    The webhook endpoint the delivery receipt for this sms is sent to. This parameter overrides the webhook endpoint you set in Dashboard.

  • :message_class (Integer)

    The Data Coding Scheme value of the message.

  • :type (String)

    The format of the message body.

  • :vcard (String)

    A business card in [vCard format](en.wikipedia.org/wiki/VCard). Depends on :type option having the value `vcard`.

  • :vcal (String)

    A calendar event in [vCal format](en.wikipedia.org/wiki/VCal). Depends on :type option having the value `vcal`.

  • :body (String)

    Hex encoded binary data. Depends on :type option having the value `binary`.

  • :udh (String)

    Your custom Hex encoded [User Data Header](en.wikipedia.org/wiki/User_Data_Header). Depends on :type option having the value `binary`.

  • :protocol_id (Integer)

    The value of the [protocol identifier](en.wikipedia.org/wiki/GSM_03.40#Protocol_Identifier) to use. Ensure that the value is aligned with :udh.

  • :title (String)

    The title for a wappush SMS. Depends on :type option having the value `wappush`.

  • :url (String)

    The URL of your website. Depends on :type option having the value `wappush`.

  • :validity (String)

    The availability for an SMS in milliseconds. Depends on :type option having the value `wappush`.

  • :client_ref (String)

    You can optionally include your own reference of up to 40 characters.

  • :account_ref (String)

    An optional string used to identify separate accounts using the SMS endpoint for billing purposes. To use this feature, please email [[email protected]]([email protected]).

Returns:

See Also:


97
98
99
100
101
102
103
104
105
106
107
# File 'lib/nexmo/sms.rb', line 97

def send(params)
  if unicode?(params[:text]) && params[:type] != 'unicode'
    message = 'Sending unicode text SMS without setting the type parameter to "unicode". ' \
      'See https://developer.nexmo.com/messaging/sms for details, ' \
      'or email [email protected] if you have any questions.'

    @logger.warn(message)
  end

  request('/sms/json', params: hyphenate(params), type: Post, response_class: Response)
end