feat: Add native support for CSML in agent_bot API (#4913)
This commit is contained in:
parent
f71980bd95
commit
b7606e4dd2
26 changed files with 722 additions and 80 deletions
52
lib/csml_engine.rb
Normal file
52
lib/csml_engine.rb
Normal file
|
@ -0,0 +1,52 @@
|
|||
class CsmlEngine
|
||||
API_KEY_HEADER = 'X-Api-Key'.freeze
|
||||
|
||||
def initialize
|
||||
@host_url = GlobalConfigService.load('CSML_BOT_HOST', '')
|
||||
@api_key = GlobalConfigService.load('CSML_BOT_API_KEY', '')
|
||||
|
||||
raise ArgumentError, 'Missing Credentials' if @host_url.blank? || @api_key.blank?
|
||||
end
|
||||
|
||||
def status
|
||||
response = HTTParty.get("#{@host_url}/status")
|
||||
process_response(response)
|
||||
end
|
||||
|
||||
def run(bot, params)
|
||||
payload = {
|
||||
bot: bot,
|
||||
event: {
|
||||
request_id: SecureRandom.uuid,
|
||||
client: params[:client],
|
||||
payload: params[:payload],
|
||||
metadata: params[:metadata],
|
||||
ttl_duration: 4000
|
||||
}
|
||||
}
|
||||
response = post('run', payload)
|
||||
process_response(response)
|
||||
end
|
||||
|
||||
def validate(bot)
|
||||
response = post('validate', bot)
|
||||
process_response(response)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def process_response(response)
|
||||
return response.parsed_response if response.success?
|
||||
|
||||
{ error: response.parsed_response, status: response.code }
|
||||
end
|
||||
|
||||
def post(path, payload)
|
||||
HTTParty.post(
|
||||
"#{@host_url}/#{path}", {
|
||||
headers: { API_KEY_HEADER => @api_key, 'Content-Type' => 'application/json' },
|
||||
body: payload.to_json
|
||||
}
|
||||
)
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue