mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
512 lines
15 KiB
512 lines
15 KiB
3 years ago
|
<template>
|
||
3 years ago
|
<v-form v-if="hook" ref="form" v-model="valid" class="mx-4" lazy-validation>
|
||
3 years ago
|
<div>
|
||
|
<a class="pointer mx-4" @click="$emit('backToList')">
|
||
3 years ago
|
<v-icon class="ml-n1 nc-icon-hook-navigate-left">mdi-arrow-left-bold</v-icon>
|
||
3 years ago
|
</a>
|
||
3 years ago
|
</div>
|
||
|
<v-card-title>
|
||
3 years ago
|
{{ meta.title }} : {{ hook.title || 'Webhook' }}
|
||
|
<v-spacer />
|
||
|
|
||
2 years ago
|
<div class="d-flex">
|
||
3 years ago
|
<v-spacer />
|
||
|
<v-btn
|
||
|
outlined
|
||
|
tooltip="Save"
|
||
|
small
|
||
3 years ago
|
class="nc-btn-webhook-test"
|
||
3 years ago
|
:disabled="loading || !valid || !hook.event"
|
||
|
@click.prevent="$refs.webhookTest.testWebhook()"
|
||
|
>
|
||
|
Test webhook
|
||
|
</v-btn>
|
||
|
<v-btn
|
||
|
tooltip="Save"
|
||
|
color="primary"
|
||
|
small
|
||
3 years ago
|
class="nc-btn-webhook-save"
|
||
3 years ago
|
:disabled="loading || !valid || !hook.event"
|
||
|
@click.prevent="saveHooks"
|
||
|
>
|
||
2 years ago
|
<v-icon small left> save </v-icon>
|
||
3 years ago
|
<!-- Save -->
|
||
2 years ago
|
{{ $t('general.save') }}
|
||
3 years ago
|
</v-btn>
|
||
|
</div>
|
||
|
</v-card-title>
|
||
|
<v-divider class="my-4" />
|
||
3 years ago
|
<v-card-text>
|
||
|
<v-text-field
|
||
|
v-model="hook.title"
|
||
3 years ago
|
class="caption nc-text-field-hook-title"
|
||
3 years ago
|
outlined
|
||
|
dense
|
||
|
:label="$t('general.title')"
|
||
|
required
|
||
2 years ago
|
:rules="[v => !!v || `${$t('general.required')}`]"
|
||
3 years ago
|
/>
|
||
3 years ago
|
<v-row>
|
||
|
<v-col>
|
||
|
<webhook-event
|
||
3 years ago
|
class="nc-text-field-hook-event"
|
||
3 years ago
|
:event.sync="hook.event"
|
||
|
:operation.sync="hook.operation"
|
||
2 years ago
|
/> </v-col
|
||
|
><v-col>
|
||
3 years ago
|
<v-select
|
||
|
v-model="hook.notification.type"
|
||
|
outlined
|
||
3 years ago
|
dense
|
||
3 years ago
|
:label="$t('general.notification')"
|
||
|
required
|
||
|
:items="notificationList"
|
||
2 years ago
|
:rules="[v => !!v || `${$t('general.required')}`]"
|
||
3 years ago
|
class="caption nc-text-field-hook-notification-type"
|
||
3 years ago
|
:prepend-inner-icon="notificationIcon[hook.notification.type]"
|
||
|
@change="onNotTypeChange"
|
||
|
>
|
||
|
<template #item="{ item }">
|
||
|
<v-list-item-icon>
|
||
|
<v-icon small>
|
||
|
{{ notificationIcon[item] }}
|
||
|
</v-icon>
|
||
|
</v-list-item-icon>
|
||
|
<v-list-item-title>
|
||
|
{{ item }}
|
||
|
</v-list-item-title>
|
||
|
</template>
|
||
|
</v-select>
|
||
|
</v-col>
|
||
|
</v-row>
|
||
3 years ago
|
<template v-if="hook.notification.type === 'URL'">
|
||
|
<http-webhook v-model="notification" />
|
||
|
</template>
|
||
|
|
||
|
<template v-if="hook.notification.type === 'Slack'">
|
||
|
<v-combobox
|
||
|
v-if="slackChannels"
|
||
|
v-model="notification.channels"
|
||
2 years ago
|
:rules="[v => !!v || `${$t('general.required')}`]"
|
||
3 years ago
|
:items="slackChannels"
|
||
|
item-text="channel"
|
||
|
label="Select Slack channels"
|
||
|
multiple
|
||
|
outlined
|
||
|
dense
|
||
|
class="caption"
|
||
|
/>
|
||
|
</template>
|
||
|
<template v-if="hook.notification.type === 'Microsoft Teams'">
|
||
|
<v-combobox
|
||
|
v-if="teamsChannels"
|
||
|
v-model="notification.channels"
|
||
2 years ago
|
:rules="[v => !!v || `${$t('general.required')}`]"
|
||
3 years ago
|
:items="teamsChannels"
|
||
|
item-text="channel"
|
||
|
label="Select Teams channels"
|
||
|
multiple
|
||
|
outlined
|
||
|
dense
|
||
|
class="caption"
|
||
|
/>
|
||
|
</template>
|
||
|
<template v-if="hook.notification.type === 'Discord'">
|
||
|
<v-combobox
|
||
|
v-if="discordChannels"
|
||
|
v-model="notification.channels"
|
||
2 years ago
|
:rules="[v => !!v || `${$t('general.required')}`]"
|
||
3 years ago
|
:items="discordChannels"
|
||
|
item-text="channel"
|
||
|
label="Select Discord channels"
|
||
|
multiple
|
||
|
outlined
|
||
|
dense
|
||
|
class="caption"
|
||
|
/>
|
||
|
</template>
|
||
|
<template v-if="hook.notification.type === 'Mattermost'">
|
||
|
<v-combobox
|
||
|
v-if="mattermostChannels"
|
||
|
v-model="notification.channels"
|
||
2 years ago
|
:rules="[v => !!v || `${$t('general.required')}`]"
|
||
3 years ago
|
:items="mattermostChannels"
|
||
|
item-text="channel"
|
||
|
label="Select Mattermost channels"
|
||
|
multiple
|
||
|
outlined
|
||
|
dense
|
||
|
class="caption"
|
||
|
/>
|
||
|
</template>
|
||
|
|
||
|
<template v-if="inputs[hook.notification.type] && notification">
|
||
|
<template v-for="input in inputs[hook.notification.type]">
|
||
|
<v-textarea
|
||
|
v-if="input.type === 'LongText'"
|
||
|
:key="input.key"
|
||
|
v-model="notification[input.key]"
|
||
|
class="caption"
|
||
|
dense
|
||
|
outlined
|
||
|
:label="input.label"
|
||
2 years ago
|
:rules="[v => !input.required || !!v || `${$t('general.required')}`]"
|
||
3 years ago
|
/>
|
||
|
<v-text-field
|
||
|
v-else
|
||
|
:key="input.key"
|
||
|
v-model="notification[input.key]"
|
||
|
class="caption"
|
||
|
dense
|
||
|
outlined
|
||
|
:label="input.label"
|
||
2 years ago
|
:rules="[v => !input.required || !!v || `${$t('general.required')}`]"
|
||
3 years ago
|
/>
|
||
|
</template>
|
||
|
</template>
|
||
|
</v-card-text>
|
||
|
|
||
3 years ago
|
<v-card-text>
|
||
2 years ago
|
<v-card class="nc-filter-wrapper">
|
||
3 years ago
|
<v-card-text>
|
||
|
<v-checkbox
|
||
|
v-model="hook.condition"
|
||
|
dense
|
||
|
hide-details
|
||
3 years ago
|
class="mt-1 nc-check-box-hook-condition"
|
||
3 years ago
|
label="On Condition"
|
||
|
/>
|
||
|
|
||
|
<column-filter
|
||
|
v-if="hook.condition"
|
||
|
:key="key"
|
||
|
ref="filter"
|
||
|
v-model="filters"
|
||
|
:meta="meta"
|
||
|
:field-list="fieldList"
|
||
|
dense
|
||
|
style="max-width: 100%"
|
||
|
:hook-id="hook.id"
|
||
|
web-hook
|
||
|
/>
|
||
|
</v-card-text>
|
||
|
</v-card>
|
||
|
</v-card-text>
|
||
3 years ago
|
<v-card-text>
|
||
|
<span class="caption grey--text">
|
||
2 years ago
|
<em>Available context variables are <strong>data and user</strong></em>
|
||
3 years ago
|
<v-tooltip top>
|
||
|
<template #activator="{ on }">
|
||
2 years ago
|
<v-icon small color="grey" class="ml-2" v-on="on">mdi-information</v-icon>
|
||
3 years ago
|
</template>
|
||
|
<span class="caption">
|
||
2 years ago
|
<strong>data</strong> : Row data <br />
|
||
|
<strong>user</strong> : User information<br />
|
||
3 years ago
|
</span>
|
||
|
</v-tooltip>
|
||
2 years ago
|
<br />
|
||
|
<a href="https://docs.nocodb.com/developer-resources/webhooks/">
|
||
3 years ago
|
<!--Document Reference-->
|
||
2 years ago
|
{{ $t('labels.docReference') }}
|
||
3 years ago
|
</a>
|
||
|
</span>
|
||
|
|
||
|
<webhooks-test
|
||
|
ref="webhookTest"
|
||
|
class="mt-3"
|
||
|
:model-id="meta.id"
|
||
|
hide-test-btn
|
||
|
:hook="{
|
||
2 years ago
|
...hook,
|
||
|
filters,
|
||
|
notification: {
|
||
|
...hook.notification,
|
||
|
payload: notification,
|
||
|
},
|
||
3 years ago
|
}"
|
||
|
/>
|
||
|
</v-card-text>
|
||
|
</v-form>
|
||
|
<span v-else />
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
2 years ago
|
import WebhooksTest from '~/components/project/tableTabs/webhook/WebhooksTest';
|
||
|
import WebhookEvent from '~/components/project/tableTabs/webhook/WebhookEvent';
|
||
|
import HttpWebhook from '~/components/project/tableTabs/webhook/HttpWebhook';
|
||
|
import ColumnFilter from '~/components/project/spreadsheet/components/ColumnFilter';
|
||
3 years ago
|
export default {
|
||
|
name: 'WebhookEditor',
|
||
3 years ago
|
components: { ColumnFilter, HttpWebhook, WebhookEvent, WebhooksTest },
|
||
3 years ago
|
props: {
|
||
2 years ago
|
meta: Object,
|
||
3 years ago
|
},
|
||
|
data: () => ({
|
||
3 years ago
|
loading: false,
|
||
|
notification: {
|
||
|
method: 'POST',
|
||
2 years ago
|
body: '{{ json data }}',
|
||
3 years ago
|
},
|
||
3 years ago
|
hook: {
|
||
3 years ago
|
title: 'Webhook',
|
||
3 years ago
|
notification: {
|
||
2 years ago
|
type: 'URL',
|
||
|
},
|
||
3 years ago
|
},
|
||
|
valid: false,
|
||
|
apps: {},
|
||
|
slackChannels: null,
|
||
|
teamsChannels: null,
|
||
|
discordChannels: null,
|
||
|
mattermostChannels: null,
|
||
|
enableCondition: false,
|
||
|
notificationList: [
|
||
|
'URL',
|
||
|
'Email',
|
||
|
'Slack',
|
||
|
'Microsoft Teams',
|
||
|
'Discord',
|
||
|
'Mattermost',
|
||
|
'Twilio',
|
||
2 years ago
|
'Whatsapp Twilio',
|
||
3 years ago
|
],
|
||
|
filters: [],
|
||
|
notificationIcon: {
|
||
|
URL: 'mdi-link',
|
||
|
Email: 'mdi-email',
|
||
|
Slack: 'mdi-slack',
|
||
|
'Microsoft Teams': 'mdi-microsoft-teams',
|
||
|
Discord: 'mdi-discord',
|
||
|
Mattermost: 'mdi-chat',
|
||
|
'Whatsapp Twilio': 'mdi-whatsapp',
|
||
2 years ago
|
Twilio: 'mdi-cellphone-message',
|
||
3 years ago
|
},
|
||
|
inputs: {
|
||
|
Email: [
|
||
|
{
|
||
|
key: 'to',
|
||
|
label: 'To Address',
|
||
|
placeholder: 'To Address',
|
||
|
type: 'SingleLineText',
|
||
2 years ago
|
required: true,
|
||
3 years ago
|
},
|
||
|
{
|
||
|
key: 'subject',
|
||
|
label: 'Subject',
|
||
|
placeholder: 'Subject',
|
||
|
type: 'SingleLineText',
|
||
2 years ago
|
required: true,
|
||
3 years ago
|
},
|
||
|
{
|
||
|
key: 'body',
|
||
|
label: 'Body',
|
||
|
placeholder: 'Body',
|
||
|
type: 'LongText',
|
||
2 years ago
|
required: true,
|
||
|
},
|
||
3 years ago
|
],
|
||
|
Slack: [
|
||
|
{
|
||
|
key: 'body',
|
||
|
label: 'Body',
|
||
|
placeholder: 'Body',
|
||
|
type: 'LongText',
|
||
2 years ago
|
required: true,
|
||
|
},
|
||
3 years ago
|
],
|
||
|
'Microsoft Teams': [
|
||
|
{
|
||
|
key: 'body',
|
||
|
label: 'Body',
|
||
|
placeholder: 'Body',
|
||
|
type: 'LongText',
|
||
2 years ago
|
required: true,
|
||
|
},
|
||
3 years ago
|
],
|
||
|
Discord: [
|
||
|
{
|
||
|
key: 'body',
|
||
|
label: 'Body',
|
||
|
placeholder: 'Body',
|
||
|
type: 'LongText',
|
||
2 years ago
|
required: true,
|
||
|
},
|
||
3 years ago
|
],
|
||
|
Mattermost: [
|
||
|
{
|
||
|
key: 'body',
|
||
|
label: 'Body',
|
||
|
placeholder: 'Body',
|
||
|
type: 'LongText',
|
||
2 years ago
|
required: true,
|
||
|
},
|
||
3 years ago
|
],
|
||
|
Twilio: [
|
||
|
{
|
||
|
key: 'body',
|
||
|
label: 'Body',
|
||
|
placeholder: 'Body',
|
||
|
type: 'LongText',
|
||
2 years ago
|
required: true,
|
||
3 years ago
|
},
|
||
|
{
|
||
|
key: 'to',
|
||
|
label: 'Comma separated Mobile #',
|
||
|
placeholder: 'Comma separated Mobile #',
|
||
|
type: 'LongText',
|
||
2 years ago
|
required: true,
|
||
|
},
|
||
3 years ago
|
],
|
||
|
'Whatsapp Twilio': [
|
||
|
{
|
||
|
key: 'body',
|
||
|
label: 'Body',
|
||
|
placeholder: 'Body',
|
||
|
type: 'LongText',
|
||
2 years ago
|
required: true,
|
||
3 years ago
|
},
|
||
|
{
|
||
|
key: 'to',
|
||
|
label: 'Comma separated Mobile #',
|
||
|
placeholder: 'Comma separated Mobile #',
|
||
|
type: 'LongText',
|
||
2 years ago
|
required: true,
|
||
|
},
|
||
|
],
|
||
|
},
|
||
3 years ago
|
}),
|
||
|
created() {
|
||
2 years ago
|
this.loadPluginList();
|
||
3 years ago
|
},
|
||
|
methods: {
|
||
|
async loadPluginList() {
|
||
|
try {
|
||
|
// const plugins = await this.$store.dispatch('sqlMgr/ActSqlOp', [null, 'xcPluginList'])
|
||
2 years ago
|
const plugins = (await this.$api.plugin.list()).list;
|
||
3 years ago
|
// plugins.push(...plugins.splice(0, 3))
|
||
|
this.apps = plugins.reduce((o, p) => {
|
||
2 years ago
|
p.tags = p.tags ? p.tags.split(',') : [];
|
||
|
p.parsedInput = p.input && JSON.parse(p.input);
|
||
|
o[p.title] = p;
|
||
|
return o;
|
||
|
}, {});
|
||
3 years ago
|
} catch (e) {}
|
||
|
},
|
||
|
addNewHook() {
|
||
2 years ago
|
this.onEventChange();
|
||
|
this.$refs.form.resetValidation();
|
||
3 years ago
|
},
|
||
|
async onNotTypeChange() {
|
||
2 years ago
|
this.notification = {};
|
||
3 years ago
|
if (this.hook.notification.type === 'Slack') {
|
||
2 years ago
|
this.slackChannels = (this.apps && this.apps.Slack && this.apps.Slack.parsedInput) || [];
|
||
3 years ago
|
}
|
||
|
if (this.hook.notification.type === 'Microsoft Teams') {
|
||
|
this.teamsChannels =
|
||
2 years ago
|
(this.apps && this.apps['Microsoft Teams'] && this.apps['Microsoft Teams'].parsedInput) || [];
|
||
3 years ago
|
}
|
||
|
if (this.hook.notification.type === 'Discord') {
|
||
2 years ago
|
this.discordChannels = (this.apps && this.apps.Discord && this.apps.Discord.parsedInput) || [];
|
||
3 years ago
|
}
|
||
|
if (this.hook.notification.type === 'Mattermost') {
|
||
2 years ago
|
this.mattermostChannels = (this.apps && this.apps.Mattermost && this.apps.Mattermost.parsedInput) || [];
|
||
3 years ago
|
}
|
||
3 years ago
|
if (this.hook.notification.type === 'URL') {
|
||
2 years ago
|
this.notification = this.notification || {};
|
||
|
this.$set(this.notification, 'body', '{{ json data }}');
|
||
3 years ago
|
}
|
||
2 years ago
|
this.$nextTick(() => this.$refs.form.validate());
|
||
3 years ago
|
},
|
||
|
async onEventChange() {
|
||
2 years ago
|
const { notification: { payload, type } = {}, ...hook } = this.hook;
|
||
3 years ago
|
|
||
|
this.hook = {
|
||
|
...hook,
|
||
|
notification: {
|
||
2 years ago
|
type,
|
||
|
},
|
||
|
};
|
||
3 years ago
|
// this.enableCondition = !!(this.hook && this.hook.condition && Object.keys(this.hook.condition).length)
|
||
2 years ago
|
await this.onNotTypeChange();
|
||
|
this.notification = payload;
|
||
3 years ago
|
if (this.hook.notification.type === 'Slack') {
|
||
|
this.notification.webhook_url =
|
||
|
this.notification.webhook_url &&
|
||
2 years ago
|
this.notification.webhook_url.map(v => this.slackChannels.find(s => v.webhook_url === s.webhook_url));
|
||
3 years ago
|
}
|
||
|
if (this.hook.notification.type === 'Microsoft Teams') {
|
||
|
this.notification.webhook_url =
|
||
|
this.notification.webhook_url &&
|
||
2 years ago
|
this.notification.webhook_url.map(v => this.teamsChannels.find(s => v.webhook_url === s.webhook_url));
|
||
3 years ago
|
}
|
||
|
if (this.hook.notification.type === 'Discord') {
|
||
|
this.notification.webhook_url =
|
||
|
this.notification.webhook_url &&
|
||
2 years ago
|
this.notification.webhook_url.map(v => this.discordChannels.find(s => v.webhook_url === s.webhook_url));
|
||
3 years ago
|
}
|
||
|
if (this.hook.notification.type === 'Mattermost') {
|
||
|
this.notification.webhook_url =
|
||
|
this.notification.webhook_url &&
|
||
2 years ago
|
this.notification.webhook_url.map(v => this.mattermostChannels.find(s => v.webhook_url === s.webhook_url));
|
||
3 years ago
|
}
|
||
|
if (this.hook.notification.type === 'URL') {
|
||
2 years ago
|
this.notification = this.notification || {};
|
||
|
this.$set(this.notification, 'body', this.notification.body || '{{ json data }}');
|
||
3 years ago
|
}
|
||
|
},
|
||
|
async saveHooks() {
|
||
|
if (!this.$refs.form.validate() || !this.valid || !this.hook.event) {
|
||
2 years ago
|
return;
|
||
3 years ago
|
}
|
||
2 years ago
|
this.loading = true;
|
||
3 years ago
|
try {
|
||
2 years ago
|
let res;
|
||
3 years ago
|
if (this.hook.id) {
|
||
|
res = await this.$api.dbTableWebhook.update(this.hook.id, {
|
||
|
...this.hook,
|
||
|
notification: {
|
||
|
...this.hook.notification,
|
||
2 years ago
|
payload: this.notification,
|
||
|
},
|
||
|
});
|
||
3 years ago
|
} else {
|
||
|
res = await this.$api.dbTableWebhook.create(this.meta.id, {
|
||
|
...this.hook,
|
||
|
notification: {
|
||
|
...this.hook.notification,
|
||
2 years ago
|
payload: this.notification,
|
||
|
},
|
||
|
});
|
||
3 years ago
|
}
|
||
|
|
||
|
if (!this.hook.id && res) {
|
||
2 years ago
|
this.hook.id = res.id;
|
||
3 years ago
|
}
|
||
|
if (this.$refs.filter) {
|
||
|
await this.$refs.filter.applyChanges(false, {
|
||
2 years ago
|
hookId: this.hook.id,
|
||
|
});
|
||
3 years ago
|
}
|
||
|
|
||
2 years ago
|
this.$toast.success('Webhook details updated successfully').goAway(3000);
|
||
3 years ago
|
} catch (e) {
|
||
2 years ago
|
this.$toast.error(e.message).goAway(3000);
|
||
3 years ago
|
}
|
||
2 years ago
|
this.loading = false;
|
||
3 years ago
|
|
||
|
this.$e('a:webhook:add', {
|
||
|
operation: this.hook.operation,
|
||
|
condition: this.hook.condition,
|
||
2 years ago
|
notification: this.hook.notification.type,
|
||
|
});
|
||
|
},
|
||
|
},
|
||
|
};
|
||
3 years ago
|
</script>
|
||
|
|
||
|
<style scoped>
|
||
3 years ago
|
/deep/ .nc-filter-wrapper label {
|
||
|
font-size: 0.75rem !important;
|
||
|
}
|
||
3 years ago
|
</style>
|