Module: RubyConversations::Concerns::ConversationTemplates

Extended by:
ActiveSupport::Concern
Included in:
RubyConversations::ConversationManager
Defined in:
lib/ruby_conversations/concerns/conversation_templates.rb

Overview

Handles template-related functionality for Conversation

Instance Method Summary collapse

Instance Method Details

#all_templatesArray<Hash>

Fetch metadata for all available templates

Returns:

  • (Array<Hash>)

    Array of template metadata including fields and UI configuration



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ruby_conversations/concerns/conversation_templates.rb', line 28

def all_templates
  begin
    templates_data = RubyConversations.client.fetch_all_conversation_templates
  rescue RubyConversations::ClientError => e
    raise RubyConversations::TemplateNotFoundError, 'Failed to fetch templates' if e.status_code == 404

    raise e
  end

  return [] unless templates_data.is_a?(Array)

  templates_data.map { |template_data| (template_data) }.compact
end

#template_for(template_name) ⇒ Hash

Fetch template metadata for a given template name

Parameters:

  • template_name (String)

    The name of the template to fetch

Returns:

  • (Hash)

    Template metadata including fields and UI configuration



15
16
17
18
19
20
21
22
23
24
# File 'lib/ruby_conversations/concerns/conversation_templates.rb', line 15

def template_for(template_name)
  begin
    template_data = RubyConversations.client.fetch_conversation_template(template_name)
  rescue RubyConversations::ClientError => e
    raise RubyConversations::TemplateNotFoundError, "Template #{template_name} not found" if e.status_code == 404

    raise e
  end
  (template_data)
end