Skip to content

Commit

Permalink
reply multiple action and csat trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
jderecho committed Dec 14, 2023
1 parent b1ec835 commit 37b386f
Show file tree
Hide file tree
Showing 37 changed files with 649 additions and 29 deletions.
19 changes: 17 additions & 2 deletions app/builders/csat_surveys/response_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,27 @@ def perform
def process_csat_response(conversation, rating, feedback_message)
csat_survey_response = message.csat_survey_response || CsatSurveyResponse.new(
message_id: message.id, account_id: message.account_id, conversation_id: message.conversation_id,
contact_id: conversation.contact_id, assigned_agent: conversation.assignee,
csat_template_id: message.csat_template_question&.csat_template_id, csat_template_question_id: message.csat_template_question&.id
contact_id: conversation.contact_id, assigned_agent: conversation.assignee
)

update_message_content_attributes
csat_survey_response.csat_template_id = csat_template_question.csat_template_id
csat_survey_response.csat_template_question_id = csat_template_question.id
csat_survey_response.rating = rating
csat_survey_response.feedback_message = feedback_message
csat_survey_response.save!
csat_survey_response
end

def csat_template_question
@csat_template_question ||= (message.csat_template_question || CsatTemplateQuestion.load_by_content(message.content))
end

def update_message_content_attributes
return unless (attrs = message.content_attributes.dig(:submitted_values)).present?

attrs['csat_template_question_id'] = csat_template_question&.id
message.content_attributes['submitted_values'] = attrs
message.save
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
class Api::V1::Accounts::Conversations::ReplyActionController < Api::V1::Accounts::Conversations::BaseController
# def show
# render json: { action_type: 'default' } and return unless Redis::Alfred.exists?(action_redis_key)

# action_type = Redis::Alfred.get(action_redis_key)
# render json: { action_type: action_type }
# end

def show
puts ' ---------------- default action show -------------'
render json: { action_type: 'default_reply_action'}
end

# def update
# # Redis::Alfred.set(action_redis_key, action_type_params)
# puts ' ---------------- default action updated -------------'
# head :ok
# end

# def destroy
# Redis::Alfred.delete(action_redis_key)
# head :ok
# end

# private

# def action_redis_key
# format(Redis::Alfred::CONVERSATION_DRAFT_MESSAGE, conversation_id: conversation_id, account_id: current_account.id)
# end

# def conversation_id
# params[:conversation_id]
# end

# def action_type_params
# params.dig(:reply_action, :type) || ''
# end
end
10 changes: 9 additions & 1 deletion app/controllers/api/v1/accounts/csat_templates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ def update
# rubocop:enable Rails/SkipsModelValidations
end

def update_csat_trigger
render json: { status: Current.account.update(csat_trigger: params[:csat_trigger]) }
end

def csat_trigger
render json: { csat_trigger: Current.account.csat_trigger }
end

def destroy
@template.destroy
render json: { success: @template.destroyed? }
Expand All @@ -33,7 +41,7 @@ def setting_status
end

def toggle_setting
Current.account.update(csat_template_enabled: params[:status])
render json: { success: true }
end

def inboxes
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v1/accounts/inboxes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def update_channel_feature_flags
def inbox_attributes
[:name, :avatar, :greeting_enabled, :greeting_message, :enable_email_collect, :csat_survey_enabled,
:enable_auto_assignment, :working_hours_enabled, :out_of_office_message, :timezone, :allow_messages_after_resolved,
:lock_to_single_conversation, :portal_id, :sender_name_type, :business_name]
:lock_to_single_conversation, :portal_id, :sender_name_type, :business_name, :default_reply_action]
end

def permitted_params(channel_attributes = [])
Expand Down
10 changes: 10 additions & 0 deletions app/javascript/dashboard/api/csatTemplates.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ class CsatTemplatesAPI extends ApiClient {
return axios.get(`${this.url}/setting_status`);
}

getCsatTrigger() {
return axios.get(`${this.url}/csat_trigger`);
}

updateCsatTrigger(csat_trigger) {
return axios.patch(`${this.url}/update_csat_trigger`, {
csat_trigger: csat_trigger
});
}

toggleSetting(status) {
return axios.patch(`${this.url}/toggle_setting`, {
status: status,
Expand Down
11 changes: 11 additions & 0 deletions app/javascript/dashboard/api/inbox/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const buildCreatePayload = ({
bccEmails = '',
toEmails = '',
templateParams,
contentType,
}) => {
let payload;
if (files && files.length !== 0) {
Expand All @@ -33,6 +34,9 @@ export const buildCreatePayload = ({
if (contentAttributes) {
payload.append('content_attributes', JSON.stringify(contentAttributes));
}
if (contentType) {
payload.append('content_type', contentType);
}
} else {
payload = {
content: message,
Expand All @@ -44,7 +48,12 @@ export const buildCreatePayload = ({
to_emails: toEmails,
template_params: templateParams,
};

if (contentType) {
payload.content_type = contentType;
}
}

return payload;
};

Expand All @@ -64,6 +73,7 @@ class MessageApi extends ApiClient {
bccEmails = '',
toEmails = '',
templateParams,
contentType,
}) {
return axios({
method: 'post',
Expand All @@ -78,6 +88,7 @@ class MessageApi extends ApiClient {
bccEmails,
toEmails,
templateParams,
contentType,
}),
});
}
Expand Down
25 changes: 25 additions & 0 deletions app/javascript/dashboard/api/inbox/reply_action.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* eslint no-console: 0 */
/* global axios */
import ApiClient from '../ApiClient';

class ReplyActionApi extends ApiClient {
constructor() {
super('conversations', { accountScoped: true });
}

get(conversationId) {
return axios.get(`${this.url}/${conversationId}/reply_action`);
}

update({ conversationId, message }) {
return axios.put(`${this.url}/${conversationId}/reply_action`, {
message,
});
}

delete(conversationId) {
return axios.delete(`${this.url}/${conversationId}/reply_action`);
}
}

export default new ReplyActionApi();
45 changes: 45 additions & 0 deletions app/javascript/dashboard/api/specs/inbox/reply_action.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import replyActionApi from '../../inbox/conversation';
import ApiClient from '../../ApiClient';
import describeWithAPIMock from '../apiSpecHelper';

describe('#ReplyActionApi', () => {
it('creates correct instance', () => {
expect(replyActionApi).toBeInstanceOf(ApiClient);
expect(replyActionApi).toHaveProperty('get');
expect(replyActionApi).toHaveProperty('update');
expect(replyActionApi).toHaveProperty('delete');
});

describeWithAPIMock('API calls', context => {
it('#get', () => {
replyActionApi.get({
conversationId: 2,
});
expect(context.axiosMock.get).toHaveBeenCalledWith(
`/api/v1/conversations/2/reply_action`
);
});

it('#update', () => {
replyActionApi.update({
conversationId: 45,
message: 'Hello',
});
expect(context.axiosMock.post).toHaveBeenCalledWith(
'/api/v1/conversations/45/reply_action',
{
message: 'Hello',
}
);
});

it('#delete', () => {
replyActionApi.delete({
conversationId: 12,
});
expect(context.axiosMock.delete).toHaveBeenCalledWith(
`/api/v1/conversations/12/reply_action`
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@
</transition>
</div>
<div class="right-wrap">
<reply-to-multiple-action
:inbox="inbox"
:conversation-id="conversationId"
:is-disabled="isSendDisabled"
:message="message"
:on-send="onSend"
:on-send-as-survey="onSendAsSurvey"
/>
<woot-button
size="small"
:class-names="buttonClass"
Expand Down Expand Up @@ -139,10 +147,11 @@ import VideoCallButton from '../VideoCallButton.vue';
import AIAssistanceButton from '../AIAssistanceButton.vue';
import { REPLY_EDITOR_MODES } from './constants';
import { mapGetters } from 'vuex';
import ReplyToMultipleAction from './ReplyToMultipleAction.vue';
export default {
name: 'ReplyBottomPanel',
components: { FileUpload, VideoCallButton, AIAssistanceButton },
components: { FileUpload, VideoCallButton, AIAssistanceButton, ReplyToMultipleAction },
mixins: [eventListenerMixins, uiSettingsMixin, inboxMixin],
props: {
mode: {
Expand All @@ -153,6 +162,10 @@ export default {
type: Function,
default: () => {},
},
onSendAsSurvey: {
type: Function,
default: () => {},
},
sendButtonText: {
type: String,
default: '',
Expand Down
Loading

0 comments on commit 37b386f

Please sign in to comment.