Class: Melaya::AssistantAPI

Inherits:
Object
  • Object
show all
Defined in:
lib/melaya/assistant.rb

Overview

Assistant API — get and save the caller's onboarding / persona profile.

The profile is stored envelope-encrypted (service=assistant_profile) and used to personalise the in-app assistant experience.

Maps to /api/v1/private/assistant/profile.

Examples:

profile = melaya.assistant.get_profile
melaya.assistant.set_profile(name: "Antoine", goals: ["grow my trading edge"])

Instance Method Summary collapse

Constructor Details

#initialize(http) ⇒ AssistantAPI

Returns a new instance of AssistantAPI.



15
16
17
# File 'lib/melaya/assistant.rb', line 15

def initialize(http)
  @http = http
end

Instance Method Details

#get_profileObject

GET /api/v1/private/assistant/profile Get the caller's assistant onboarding profile.



21
22
23
# File 'lib/melaya/assistant.rb', line 21

def get_profile
  @http.get("/api/v1/private/assistant/profile")
end

#set_profile(name: nil, goals: nil, context: nil, preferences: nil, **extra) ⇒ Object

PUT /api/v1/private/assistant/profile Save the caller's assistant onboarding profile.

Parameters:

  • name (String, nil) (defaults to: nil)
  • goals (Array<String>, nil) (defaults to: nil)
  • context (String, nil) (defaults to: nil)
  • preferences (Hash, nil) (defaults to: nil)
  • extra (Hash)

    any additional profile fields



32
33
34
35
36
37
38
39
# File 'lib/melaya/assistant.rb', line 32

def set_profile(name: nil, goals: nil, context: nil, preferences: nil, **extra)
  profile = extra.transform_keys(&:to_s)
  profile["name"]        = name        unless name.nil?
  profile["goals"]       = goals       unless goals.nil?
  profile["context"]     = context     unless context.nil?
  profile["preferences"] = preferences unless preferences.nil?
  @http.put("/api/v1/private/assistant/profile", profile)
end