Class: Vapi::CustomMessage

Inherits:
Object
  • Object
show all
Defined in:
lib/vapi_server_sdk/types/custom_message.rb

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, contents: OMIT, content: OMIT, additional_properties: nil) ⇒ Vapi::CustomMessage

Parameters:

  • contents (Array<Vapi::TextContent>) (defaults to: OMIT)

    This is an alternative to the ‘content` property. It allows to specify variants of the same content, one per language. Usage:

    • If your assistants are multilingual, you can provide content for each

    language.

    • If you don’t provide content for a language, the first item in the array will

    be automatically translated to the active language at that moment. This will override the ‘content` property.

  • type (String)

    This is a custom message.

  • content (String) (defaults to: OMIT)

    This is the content that the assistant will say when this message is triggered.

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



42
43
44
45
46
47
48
49
50
# File 'lib/vapi_server_sdk/types/custom_message.rb', line 42

def initialize(type:, contents: OMIT, content: OMIT, additional_properties: nil)
  @contents = contents if contents != OMIT
  @type = type
  @content = content if content != OMIT
  @additional_properties = additional_properties
  @_field_set = { "contents": contents, "type": type, "content": content }.reject do |_k, v|
    v == OMIT
  end
end

Instance Attribute Details

#additional_propertiesOpenStruct (readonly)

Returns Additional properties unmapped to the current class definition.

Returns:

  • (OpenStruct)

    Additional properties unmapped to the current class definition



23
24
25
# File 'lib/vapi_server_sdk/types/custom_message.rb', line 23

def additional_properties
  @additional_properties
end

#contentString (readonly)

Returns This is the content that the assistant will say when this message is triggered.

Returns:

  • (String)

    This is the content that the assistant will say when this message is triggered.



21
22
23
# File 'lib/vapi_server_sdk/types/custom_message.rb', line 21

def content
  @content
end

#contentsArray<Vapi::TextContent> (readonly)

Returns This is an alternative to the ‘content` property. It allows to specify variants of the same content, one per language. Usage:

  • If your assistants are multilingual, you can provide content for each

language.

  • If you don’t provide content for a language, the first item in the array will

be automatically translated to the active language at that moment. This will override the ‘content` property.

Returns:

  • (Array<Vapi::TextContent>)

    This is an alternative to the ‘content` property. It allows to specify variants of the same content, one per language. Usage:

    • If your assistants are multilingual, you can provide content for each

    language.

    • If you don’t provide content for a language, the first item in the array will

    be automatically translated to the active language at that moment. This will override the ‘content` property.



17
18
19
# File 'lib/vapi_server_sdk/types/custom_message.rb', line 17

def contents
  @contents
end

#typeString (readonly)

Returns This is a custom message.

Returns:

  • (String)

    This is a custom message.



19
20
21
# File 'lib/vapi_server_sdk/types/custom_message.rb', line 19

def type
  @type
end

Class Method Details

.from_json(json_object:) ⇒ Vapi::CustomMessage

Deserialize a JSON object to an instance of CustomMessage

Parameters:

  • json_object (String)

Returns:



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/vapi_server_sdk/types/custom_message.rb', line 56

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  contents = parsed_json["contents"]&.map do |item|
    item = item.to_json
    Vapi::TextContent.from_json(json_object: item)
  end
  type = parsed_json["type"]
  content = parsed_json["content"]
  new(
    contents: contents,
    type: type,
    content: content,
    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)


86
87
88
89
90
# File 'lib/vapi_server_sdk/types/custom_message.rb', line 86

def self.validate_raw(obj:)
  obj.contents&.is_a?(Array) != false || raise("Passed value for field obj.contents is not the expected type, validation failed.")
  obj.type.is_a?(String) != false || raise("Passed value for field obj.type is not the expected type, validation failed.")
  obj.content&.is_a?(String) != false || raise("Passed value for field obj.content is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ String

Serialize an instance of CustomMessage to a JSON object

Returns:

  • (String)


76
77
78
# File 'lib/vapi_server_sdk/types/custom_message.rb', line 76

def to_json(*_args)
  @_field_set&.to_json
end