Class: Vonage::Messaging

Inherits:
Namespace
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/vonage/messaging.rb

Defined Under Namespace

Classes: Message

Instance Method Summary collapse

Instance Method Details

#send(to:, from:, channel:, message_type:, failover: nil, **message) ⇒ Object

Send a Message.

Examples:

message = client.messaging.sms(message: "Hello world!")
response = client.messaging.send(to: "447700900000", from: "447700900001", **message)

Parameters:

  • params (Hash)

    a customizable set of options

See Also:



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/vonage/messaging.rb', line 30

def send(to:, from:, channel:, message_type:, failover: nil, **message)
  params = { to: to, from: from, channel: channel, message_type: message_type }.merge(message)

  if failover
    raise ArgumentError.new("`failover` must be an array") unless failover.is_a?(Array)
    raise ArgumentError.new("`failover` must not be empty") if failover.empty?
    raise ArgumentError.new("`failover` must contain only Hashes") unless failover.all?(Hash)
    params[:failover] = failover
  end

  request('/v1/messages', params: params, type: Post)
end

#update(message_uuid:, **params) ⇒ Object

Update a Message Object.

‘:message_uuid` is always required. Other parameters will depend on the message channel and the specific action being performed.

Examples:

message = client.messaging.update(message_uuid: "aaaaaaaa-bbbb-4ccc-8ddd-0123456789ab", status: "read")

Parameters:

  • params (Hash)

    a customizable set of options

Options Hash (**params):

  • :message_uuid. (required, String)

    the UUID of the message to update.

See Also:



53
54
55
# File 'lib/vonage/messaging.rb', line 53

def update(message_uuid:, **params)
  request("/v1/messages/#{message_uuid}", params: params, type: Patch)
end

#verify_webhook_token(token:, signature_secret: @config.signature_secret) ⇒ Boolean

Validate a JSON Web Token from a Messages API Webhook.

Parameters:

  • :token (String, required)

    The JWT from the Webhook’s Authorization header

  • :signature_secret (String, optional)

    The account signature secret. Required, unless ‘signature_secret` is set in `Config`

Returns:

  • (Boolean)

    true, if the JWT is verified, false otherwise



64
65
66
# File 'lib/vonage/messaging.rb', line 64

def verify_webhook_token(token:, signature_secret: @config.signature_secret)
  JWT.verify_hs256_signature(token: token, signature_secret: signature_secret)
end