Class: Courier::Send::ContentMessage

Inherits:
Object
  • Object
show all
Defined in:
lib/trycourier/send/types/content_message.rb

Overview

The message property has the following primary top-level properties. They define the destination and content of the message. Additional advanced configuration fields [are defined below](www.courier.com/docs/reference/send/message/#other-message-properties).

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content:, to:, data: nil, brand_id: nil, channels: nil, context: nil, metadata: nil, providers: nil, routing: nil, timeout: nil, delay: nil, expiry: nil, additional_properties: nil) ⇒ Send::ContentMessage

Parameters:

  • content (Send::Content)

    Describes the content of the message in a way that will work for email, push, chat, or any channel. Either this or template must be specified.

  • to (Send::MessageRecipient)

    The recipient or a list of recipients of the message

  • data (Send::MESSAGE_DATA) (defaults to: nil)

    An arbitrary object that includes any data you want to pass to the message. The data will populate the corresponding template or elements variables.

  • brand_id (String) (defaults to: nil)
  • channels (Send::MESSAGE_CHANNELS) (defaults to: nil)

    “Define run-time configuration for one or more channels. If you don’t specify channels, the default configuration for each channel will be used. Valid ChannelId’s are: email, sms, push, inbox, direct_message, banner, and webhook.”

  • context (Send::MessageContext) (defaults to: nil)

    Context to load with this recipient. Will override any context set on message.context.

  • metadata (Send::MessageMetadata) (defaults to: nil)

    Metadata such as utm tracking attached with the notification through this channel.

  • providers (Send::MESSAGE_PROVIDERS) (defaults to: nil)

    An object whose keys are valid provider identifiers which map to an object.

  • routing (Send::Routing) (defaults to: nil)
  • timeout (Send::Timeout) (defaults to: nil)

    Time in ms to attempt the channel before failing over to the next available channel.

  • delay (Send::Delay) (defaults to: nil)

    Defines the time to wait before delivering the message.

  • expiry (Send::Expiry) (defaults to: nil)

    “Expiry allows you to set an absolute or relative time in which a message expires. Note: This is only valid for the Courier Inbox channel as of 12-08-2022.”

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/trycourier/send/types/content_message.rb', line 41

def initialize(content:, to:, data: nil, brand_id: nil, channels: nil, context: nil, metadata: nil,
               providers: nil, routing: nil, timeout: nil, delay: nil, expiry: nil, additional_properties: nil)
  # @type [Send::Content] Describes the content of the message in a way that will work for email, push,
  #   chat, or any channel. Either this or template must be specified.
  @content = content
  # @type [Send::MessageRecipient] The recipient or a list of recipients of the message
  @to = to
  # @type [Send::MESSAGE_DATA] An arbitrary object that includes any data you want to pass to the message.
  #   The data will populate the corresponding template or elements variables.
  @data = data
  # @type [String]
  @brand_id = brand_id
  # @type [Send::MESSAGE_CHANNELS] "Define run-time configuration for one or more channels. If you don't specify channels, the default configuration for each channel will be used. Valid ChannelId's are: email, sms, push, inbox, direct_message, banner, and webhook."
  @channels = channels
  # @type [Send::MessageContext] Context to load with this recipient. Will override any context set on message.context.
  @context = context
  # @type [Send::MessageMetadata] Metadata such as utm tracking attached with the notification through this channel.
  @metadata = 
  # @type [Send::MESSAGE_PROVIDERS] An object whose keys are valid provider identifiers which map to an object.
  @providers = providers
  # @type [Send::Routing]
  @routing = routing
  # @type [Send::Timeout] Time in ms to attempt the channel before failing over to the next available channel.
  @timeout = timeout
  # @type [Send::Delay] Defines the time to wait before delivering the message.
  @delay = delay
  # @type [Send::Expiry] "Expiry allows you to set an absolute or relative time in which a message expires.
  #   Note: This is only valid for the Courier Inbox channel as of 12-08-2022."
  @expiry = expiry
  # @type [OpenStruct] Additional properties unmapped to the current class definition
  @additional_properties = additional_properties
end

Instance Attribute Details

#additional_propertiesObject (readonly)

Returns the value of attribute additional_properties.



21
22
23
# File 'lib/trycourier/send/types/content_message.rb', line 21

def additional_properties
  @additional_properties
end

#brand_idObject (readonly)

Returns the value of attribute brand_id.



21
22
23
# File 'lib/trycourier/send/types/content_message.rb', line 21

def brand_id
  @brand_id
end

#channelsObject (readonly)

Returns the value of attribute channels.



21
22
23
# File 'lib/trycourier/send/types/content_message.rb', line 21

def channels
  @channels
end

#contentObject (readonly)

Returns the value of attribute content.



21
22
23
# File 'lib/trycourier/send/types/content_message.rb', line 21

def content
  @content
end

#contextObject (readonly)

Returns the value of attribute context.



21
22
23
# File 'lib/trycourier/send/types/content_message.rb', line 21

def context
  @context
end

#dataObject (readonly)

Returns the value of attribute data.



21
22
23
# File 'lib/trycourier/send/types/content_message.rb', line 21

def data
  @data
end

#delayObject (readonly)

Returns the value of attribute delay.



21
22
23
# File 'lib/trycourier/send/types/content_message.rb', line 21

def delay
  @delay
end

#expiryObject (readonly)

Returns the value of attribute expiry.



21
22
23
# File 'lib/trycourier/send/types/content_message.rb', line 21

def expiry
  @expiry
end

#metadataObject (readonly)

Returns the value of attribute metadata.



21
22
23
# File 'lib/trycourier/send/types/content_message.rb', line 21

def 
  @metadata
end

#providersObject (readonly)

Returns the value of attribute providers.



21
22
23
# File 'lib/trycourier/send/types/content_message.rb', line 21

def providers
  @providers
end

#routingObject (readonly)

Returns the value of attribute routing.



21
22
23
# File 'lib/trycourier/send/types/content_message.rb', line 21

def routing
  @routing
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



21
22
23
# File 'lib/trycourier/send/types/content_message.rb', line 21

def timeout
  @timeout
end

#toObject (readonly)

Returns the value of attribute to.



21
22
23
# File 'lib/trycourier/send/types/content_message.rb', line 21

def to
  @to
end

Class Method Details

.from_json(json_object:) ⇒ Send::ContentMessage

Deserialize a JSON object to an instance of ContentMessage

Parameters:

  • json_object (JSON)

Returns:



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/trycourier/send/types/content_message.rb', line 78

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  if parsed_json["content"].nil?
    content = nil
  else
    content = parsed_json["content"].to_json
    content = Send::Content.from_json(json_object: content)
  end
  if parsed_json["to"].nil?
    to = nil
  else
    to = parsed_json["to"].to_json
    to = Send::MessageRecipient.from_json(json_object: to)
  end
  data = struct.data
  brand_id = struct.brand_id
  channels = struct.channels
  if parsed_json["context"].nil?
    context = nil
  else
    context = parsed_json["context"].to_json
    context = Send::MessageContext.from_json(json_object: context)
  end
  if parsed_json["metadata"].nil?
     = nil
  else
     = parsed_json["metadata"].to_json
     = Send::MessageMetadata.from_json(json_object: )
  end
  providers = struct.providers
  if parsed_json["routing"].nil?
    routing = nil
  else
    routing = parsed_json["routing"].to_json
    routing = Send::Routing.from_json(json_object: routing)
  end
  if parsed_json["timeout"].nil?
    timeout = nil
  else
    timeout = parsed_json["timeout"].to_json
    timeout = Send::Timeout.from_json(json_object: timeout)
  end
  if parsed_json["delay"].nil?
    delay = nil
  else
    delay = parsed_json["delay"].to_json
    delay = Send::Delay.from_json(json_object: delay)
  end
  if parsed_json["expiry"].nil?
    expiry = nil
  else
    expiry = parsed_json["expiry"].to_json
    expiry = Send::Expiry.from_json(json_object: expiry)
  end
  new(content: content, to: to, data: data, brand_id: brand_id, channels: channels, context: context,
      metadata: , providers: providers, routing: routing, timeout: timeout, delay: delay, expiry: expiry, additional_properties: struct)
end

.validate_raw(obj:) ⇒ Void

Leveraged for Union-type generation, validate_raw attempts to parse the given hash and check each fields type against the current object’s property definitions.

Parameters:

  • obj (Object)

Returns:

  • (Void)


161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/trycourier/send/types/content_message.rb', line 161

def self.validate_raw(obj:)
  Send::Content.validate_raw(obj: obj.content)
  Send::MessageRecipient.validate_raw(obj: obj.to)
  obj.data&.is_a?(Hash) != false || raise("Passed value for field obj.data is not the expected type, validation failed.")
  obj.brand_id&.is_a?(String) != false || raise("Passed value for field obj.brand_id is not the expected type, validation failed.")
  obj.channels&.is_a?(Hash) != false || raise("Passed value for field obj.channels is not the expected type, validation failed.")
  obj.context.nil? || Send::MessageContext.validate_raw(obj: obj.context)
  obj..nil? || Send::MessageMetadata.validate_raw(obj: obj.)
  obj.providers&.is_a?(Hash) != false || raise("Passed value for field obj.providers is not the expected type, validation failed.")
  obj.routing.nil? || Send::Routing.validate_raw(obj: obj.routing)
  obj.timeout.nil? || Send::Timeout.validate_raw(obj: obj.timeout)
  obj.delay.nil? || Send::Delay.validate_raw(obj: obj.delay)
  obj.expiry.nil? || Send::Expiry.validate_raw(obj: obj.expiry)
end

Instance Method Details

#to_json(*_args) ⇒ JSON

Serialize an instance of ContentMessage to a JSON object

Returns:

  • (JSON)


140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/trycourier/send/types/content_message.rb', line 140

def to_json(*_args)
  {
    "content": @content,
    "to": @to,
    "data": @data,
    "brand_id": @brand_id,
    "channels": @channels,
    "context": @context,
    "metadata": @metadata,
    "providers": @providers,
    "routing": @routing,
    "timeout": @timeout,
    "delay": @delay,
    "expiry": @expiry
  }.to_json
end