Method: Cpaas::Conversation.create_message

Defined in:
lib/cpaas-sdk/resources/conversation.rb

.create_message(params) ⇒ Object

Send a new outbound message

Parameters:

  • params (Hash)

Options Hash (params):

  • :type (String)

    Type of conversation. Possible value(s) - ‘sms’. Check Conversation.types for more options

  • :sender_address (String)

    Sender address information, basically the from address. E164 formatted DID number passed as a value, which is owned by the user. If the user wants to let CPaaS uses the default assigned DID number, this field can either has “default” value or the same value as the userId.

  • :destination_address (Array[string]|String)

    Indicates which DID number(s) used as destination for this SMS.

  • :message (String)

    SMS text message



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/cpaas-sdk/resources/conversation.rb', line 18

def self.create_message(params)
  if params[:type] == types[:SMS]
    address = (params[:destination_address].is_a? String) ? [ params[:destination_address] ] : params[:destination_address]

    options = {
      body: {
        outboundSMSMessageRequest: {
          address: address,
          clientCorrelator: Cpaas.api.client_correlator,
          outboundSMSTextMessage: {
            message: params[:message]
          }
        }
      }
    }

    response = Cpaas.api.send_request("#{base_url}/outbound/#{params[:sender_address]}/requests", options, :post)
    process_response(response) do |res|
      outboundSMS = res.dig(:outbound_sms_message_request)

      {
        message: outboundSMS.dig(:outbound_sms_text_message, :message),
        senderAddress: outboundSMS.dig(:sender_address),
        deliveryInfo: outboundSMS.dig(:delivery_info_list, :delivery_info)
      }
    end
  end
end