feat: Add native support for CSML in agent_bot API (#4913)

This commit is contained in:
Pranav Raj S
2022-06-23 19:17:46 +05:30
committed by GitHub
parent f71980bd95
commit b7606e4dd2
26 changed files with 722 additions and 80 deletions

View File

@@ -1,17 +1,6 @@
class Integrations::Dialogflow::ProcessorService
class Integrations::Dialogflow::ProcessorService < Integrations::BotProcessorService
pattr_initialize [:event_name!, :hook!, :event_data!]
def perform
message = event_data[:message]
return if message.private?
return unless processable_message?(message)
return unless message.conversation.pending?
content = message_content(message)
response = get_dialogflow_response(message.conversation.contact_inbox.source_id, content) if content.present?
process_response(message, response) if response.present?
end
private
def message_content(message)
@@ -23,19 +12,7 @@ class Integrations::Dialogflow::ProcessorService
message.content
end
def processable_message?(message)
# TODO: change from reportable and create a dedicated method for this?
return unless message.reportable?
return if message.outgoing? && !processable_outgoing_message?(message)
true
end
def processable_outgoing_message?(message)
event_name == 'message.updated' && ['input_select'].include?(message.content_type)
end
def get_dialogflow_response(session_id, message)
def get_response(session_id, message)
Google::Cloud::Dialogflow.configure { |config| config.credentials = hook.settings['credentials'] }
session_client = Google::Cloud::Dialogflow.sessions
session = session_client.session_path project: hook.settings['project_id'], session: session_id
@@ -72,13 +49,4 @@ class Integrations::Dialogflow::ProcessorService
inbox_id: conversation.inbox_id
}))
end
def process_action(message, action)
case action
when 'handoff'
message.conversation.open!
when 'resolve'
message.conversation.resolved!
end
end
end