From 1761bec6152b3c7dedf0c97da4e6468914d7e881 Mon Sep 17 00:00:00 2001
From: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
Date: Tue, 28 Sep 2021 12:33:08 +0530
Subject: [PATCH] feat: Adds ability to edit out webhook URL of API Channel
(#3013)
---
.../dashboard/i18n/locale/en/inboxMgmt.json | 9 ++++-
.../dashboard/settings/inbox/Settings.vue | 39 ++++++++++++++++++-
app/javascript/shared/helpers/Validators.js | 2 +
.../helpers/specs/ValidatorsHelper.spec.js | 7 ++++
4 files changed, 54 insertions(+), 3 deletions(-)
create mode 100644 app/javascript/shared/helpers/specs/ValidatorsHelper.spec.js
diff --git a/app/javascript/dashboard/i18n/locale/en/inboxMgmt.json b/app/javascript/dashboard/i18n/locale/en/inboxMgmt.json
index 4d05e5807..b585eda4d 100644
--- a/app/javascript/dashboard/i18n/locale/en/inboxMgmt.json
+++ b/app/javascript/dashboard/i18n/locale/en/inboxMgmt.json
@@ -56,6 +56,11 @@
"CHANNEL_AVATAR": {
"LABEL": "Channel Avatar"
},
+ "CHANNEL_WEBHOOK_URL": {
+ "LABEL": "Webhook URL",
+ "PLACEHOLDER": "Enter your Webhook URL",
+ "ERROR": "Please enter a valid URL"
+ },
"CHANNEL_DOMAIN": {
"LABEL": "Website Domain",
"PLACEHOLDER": "Enter your website domain (eg: acme.com)"
@@ -127,11 +132,11 @@
"ERROR_MESSAGE": "We were not able to authenticate Twilio credentials, please try again"
}
},
- "SMS": {
+ "SMS": {
"TITLE": "SMS Channel via Twilio",
"DESC": "Start supporting your customers via SMS with Twilio integration."
},
- "WHATSAPP": {
+ "WHATSAPP": {
"TITLE": "Whatsapp Channel via Twilio",
"DESC": "Start supporting your customers via Whatsapp with Twilio integration."
},
diff --git a/app/javascript/dashboard/routes/dashboard/settings/inbox/Settings.vue b/app/javascript/dashboard/routes/dashboard/settings/inbox/Settings.vue
index cf8ddd2fd..fd7204fe7 100644
--- a/app/javascript/dashboard/routes/dashboard/settings/inbox/Settings.vue
+++ b/app/javascript/dashboard/routes/dashboard/settings/inbox/Settings.vue
@@ -22,7 +22,7 @@
@@ -32,6 +32,24 @@
:label="inboxNameLabel"
:placeholder="inboxNamePlaceHolder"
/>
+
+
import { mapGetters } from 'vuex';
import { createMessengerScript } from 'dashboard/helper/scriptGenerator';
+import { required } from 'vuelidate/lib/validators';
+import { shouldBeUrl } from 'shared/helpers/Validators';
import configMixin from 'shared/mixins/configMixin';
import alertMixin from 'shared/mixins/alertMixin';
import SettingIntroBanner from 'dashboard/components/widgets/SettingIntroBanner';
@@ -357,6 +387,7 @@ export default {
csatSurveyEnabled: false,
selectedInboxName: '',
channelWebsiteUrl: '',
+ webhookUrl: '',
channelWelcomeTitle: '',
channelWelcomeTagline: '',
selectedFeatureFlags: [],
@@ -503,6 +534,7 @@ export default {
this.fetchAttachedAgents();
this.avatarUrl = this.inbox.avatar_url;
this.selectedInboxName = this.inbox.name;
+ this.webhookUrl = this.inbox.webhook_url;
this.greetingEnabled = this.inbox.greeting_enabled || false;
this.greetingMessage = this.inbox.greeting_message || '';
this.autoAssignment = this.inbox.enable_auto_assignment;
@@ -555,6 +587,7 @@ export default {
channel: {
widget_color: this.inbox.widget_color,
website_url: this.channelWebsiteUrl,
+ webhook_url: this.webhookUrl,
welcome_title: this.channelWelcomeTitle || '',
welcome_tagline: this.channelWelcomeTagline || '',
selectedFeatureFlags: this.selectedFeatureFlags,
@@ -593,6 +626,10 @@ export default {
},
},
validations: {
+ webhookUrl: {
+ required,
+ shouldBeUrl,
+ },
selectedAgents: {
isEmpty() {
return !!this.selectedAgents.length;
diff --git a/app/javascript/shared/helpers/Validators.js b/app/javascript/shared/helpers/Validators.js
index 57e5e0e58..d6b802de8 100644
--- a/app/javascript/shared/helpers/Validators.js
+++ b/app/javascript/shared/helpers/Validators.js
@@ -1,2 +1,4 @@
export const isPhoneE164 = value => !!value.match(/^\+[1-9]\d{1,14}$/);
export const isPhoneE164OrEmpty = value => isPhoneE164(value) || value === '';
+export const shouldBeUrl = (value = '') =>
+ value ? value.startsWith('http') : true;
diff --git a/app/javascript/shared/helpers/specs/ValidatorsHelper.spec.js b/app/javascript/shared/helpers/specs/ValidatorsHelper.spec.js
new file mode 100644
index 000000000..ba393a7a3
--- /dev/null
+++ b/app/javascript/shared/helpers/specs/ValidatorsHelper.spec.js
@@ -0,0 +1,7 @@
+import { shouldBeUrl } from '../Validators';
+
+describe('#shouldBeUrl', () => {
+ it('should return correct url', () => {
+ expect(shouldBeUrl('http')).toEqual(true);
+ });
+});