forked from chatwoot/chatwoot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'staging' into master-staging
- Loading branch information
Showing
49 changed files
with
1,205 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
class SmartActionBuilder | ||
attr_accessor :errors | ||
|
||
def initialize(conversation, params) | ||
@conversation = conversation | ||
@params = params | ||
@errors = [] | ||
end | ||
|
||
def perform | ||
validate_params | ||
return if @errors.present? | ||
|
||
build_smart_action | ||
rescue StandardError => e | ||
@errors << e.message | ||
nil | ||
end | ||
|
||
private | ||
|
||
def validate_params | ||
return if @params.present? | ||
|
||
@errors << 'Missing parameters' | ||
end | ||
|
||
def build_smart_action | ||
@smart_action = @conversation.smart_actions.create(smart_action_params) | ||
end | ||
|
||
def smart_action_params | ||
@params.permit( | ||
:name, | ||
:label, | ||
:description, | ||
:event, | ||
:intent_type, | ||
:message_id, | ||
:to, | ||
:from, | ||
:link, | ||
:content | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
app/controllers/api/v1/accounts/conversations/smart_actions_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
class Api::V1::Accounts::Conversations::SmartActionsController < Api::V1::Accounts::Conversations::BaseController | ||
def index | ||
@smart_actions = @conversation.smart_actions | ||
end | ||
|
||
def create | ||
builder = SmartActionBuilder.new(@conversation, params) | ||
@smart_action = builder.perform | ||
|
||
render json: { | ||
success: @smart_action.present?, | ||
message: builder.errors.present? ? builder.errors.join(', ') : 'Successfully created' | ||
} | ||
end | ||
|
||
def event_data | ||
# todo move to service action | ||
case params[:event] | ||
when 'ask_copilot' | ||
event = @conversation.smart_actions.ask_copilot.last | ||
render json: event.present? ? event.event_data : {} | ||
else | ||
render json: {success: false} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* eslint no-console: 0 */ | ||
/* global axios */ | ||
import ApiClient from '../ApiClient'; | ||
import { SMART_ACTION_EVENTS } from 'shared/constants/smartActionEvents'; | ||
|
||
class SmartActionApi extends ApiClient { | ||
constructor() { | ||
super('conversations', { accountScoped: true }); | ||
} | ||
|
||
getSmartActions(conversationId) { | ||
return axios.get(`${this.url}/${conversationId}/smart_actions`); | ||
} | ||
|
||
askCopilot(conversationId) { | ||
return axios.get(`${this.url}/${conversationId}/smart_actions/event_data`, { | ||
params: { | ||
event: SMART_ACTION_EVENTS.ASK_COPILOT, | ||
}, | ||
}); | ||
} | ||
} | ||
|
||
export default new SmartActionApi(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
app/javascript/dashboard/components/widgets/conversation/Copilot.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<template> | ||
<div class="copilot"> | ||
<woot-button | ||
v-if="showCopilot" | ||
color-scheme="primary" | ||
icon="star-glitters" | ||
size="tiny" | ||
@click="askCopilot" | ||
> | ||
Ask Copilot | ||
</woot-button> | ||
<fluent-icon | ||
v-if="showLoadingSmartResponseIcon" | ||
icon="star-glitters" | ||
class="ml-2 mt-1" | ||
size="12" | ||
/> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
props: { | ||
showCopilot: { type: Boolean, default: false }, | ||
showLoadingSmartResponseIcon: { type: Boolean, default: false }, | ||
}, | ||
methods: { | ||
askCopilot() { | ||
this.$emit('ask-copilot'); | ||
}, | ||
}, | ||
}; | ||
</script> |
Oops, something went wrong.