feat: Convert all app files to JS
This commit is contained in:
@@ -1,13 +1,4 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
|
||||
type FindMessageOptions = {
|
||||
query: string;
|
||||
sortBy: string;
|
||||
sortDirection: string;
|
||||
count: number;
|
||||
};
|
||||
|
||||
const findMessage = async ($: IGlobalVariable, options: FindMessageOptions) => {
|
||||
const findMessage = async ($, options) => {
|
||||
const params = {
|
||||
query: options.query,
|
||||
sort: options.sortBy,
|
@@ -1,5 +1,5 @@
|
||||
import defineAction from '../../../../helpers/define-action';
|
||||
import findMessage from './find-message';
|
||||
import defineAction from '../../../../helpers/define-action.js';
|
||||
import findMessage from './find-message.js';
|
||||
|
||||
export default defineAction({
|
||||
name: 'Find a message',
|
||||
@@ -9,7 +9,7 @@ export default defineAction({
|
||||
{
|
||||
label: 'Search Query',
|
||||
key: 'query',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
description:
|
||||
'Search query to use for finding matching messages. See the Slack Search Documentation for more information on constructing a query.',
|
||||
@@ -18,7 +18,7 @@ export default defineAction({
|
||||
{
|
||||
label: 'Sort by',
|
||||
key: 'sortBy',
|
||||
type: 'dropdown' as const,
|
||||
type: 'dropdown',
|
||||
description:
|
||||
'Sort messages by their match strength or by their date. Default is score.',
|
||||
required: true,
|
||||
@@ -38,7 +38,7 @@ export default defineAction({
|
||||
{
|
||||
label: 'Sort direction',
|
||||
key: 'sortDirection',
|
||||
type: 'dropdown' as const,
|
||||
type: 'dropdown',
|
||||
description:
|
||||
'Sort matching messages in ascending or descending order. Default is descending.',
|
||||
required: true,
|
||||
@@ -59,9 +59,9 @@ export default defineAction({
|
||||
|
||||
async run($) {
|
||||
const parameters = $.step.parameters;
|
||||
const query = parameters.query as string;
|
||||
const sortBy = parameters.sortBy as string;
|
||||
const sortDirection = parameters.sortDirection as string;
|
||||
const query = parameters.query;
|
||||
const sortBy = parameters.sortBy;
|
||||
const sortDirection = parameters.sortDirection;
|
||||
const count = 1;
|
||||
|
||||
const messages = await findMessage($, {
|
@@ -1,4 +1,4 @@
|
||||
import defineAction from '../../../../helpers/define-action';
|
||||
import defineAction from '../../../../helpers/define-action.js';
|
||||
|
||||
export default defineAction({
|
||||
name: 'Find user by email',
|
||||
@@ -8,7 +8,7 @@ export default defineAction({
|
||||
{
|
||||
label: 'Email',
|
||||
key: 'email',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
variables: true,
|
||||
},
|
||||
@@ -16,11 +16,11 @@ export default defineAction({
|
||||
|
||||
async run($) {
|
||||
const params = {
|
||||
email: $.step.parameters.email as string,
|
||||
email: $.step.parameters.email,
|
||||
};
|
||||
|
||||
const { data } = await $.http.get('/users.lookupByEmail', {
|
||||
params
|
||||
params,
|
||||
});
|
||||
|
||||
if (data.ok) {
|
11
packages/backend/src/apps/slack/actions/index.js
Normal file
11
packages/backend/src/apps/slack/actions/index.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import findMessage from './find-message/index.js';
|
||||
import findUserByEmail from './find-user-by-email/index.js';
|
||||
import sendMessageToChannel from './send-a-message-to-channel/index.js';
|
||||
import sendDirectMessage from './send-a-direct-message/index.js';
|
||||
|
||||
export default [
|
||||
findMessage,
|
||||
findUserByEmail,
|
||||
sendMessageToChannel,
|
||||
sendDirectMessage,
|
||||
];
|
@@ -1,6 +0,0 @@
|
||||
import findMessage from './find-message';
|
||||
import findUserByEmail from './find-user-by-email';
|
||||
import sendMessageToChannel from './send-a-message-to-channel';
|
||||
import sendDirectMessage from './send-a-direct-message';
|
||||
|
||||
export default [findMessage, findUserByEmail, sendMessageToChannel, sendDirectMessage];
|
@@ -1,15 +1,16 @@
|
||||
import defineAction from '../../../../helpers/define-action';
|
||||
import postMessage from './post-message';
|
||||
import defineAction from '../../../../helpers/define-action.js';
|
||||
import postMessage from './post-message.js';
|
||||
|
||||
export default defineAction({
|
||||
name: 'Send a direct message',
|
||||
key: 'sendDirectMessage',
|
||||
description: 'Sends a direct message to a user or yourself from the Slackbot.',
|
||||
description:
|
||||
'Sends a direct message to a user or yourself from the Slackbot.',
|
||||
arguments: [
|
||||
{
|
||||
label: 'To username',
|
||||
key: 'toUsername',
|
||||
type: 'dropdown' as const,
|
||||
type: 'dropdown',
|
||||
required: true,
|
||||
description: 'Pick a user to send the message to.',
|
||||
variables: true,
|
||||
@@ -27,7 +28,7 @@ export default defineAction({
|
||||
{
|
||||
label: 'Message text',
|
||||
key: 'message',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: 'The content of your new message.',
|
||||
variables: true,
|
||||
@@ -35,7 +36,7 @@ export default defineAction({
|
||||
{
|
||||
label: 'Send as a bot?',
|
||||
key: 'sendAsBot',
|
||||
type: 'dropdown' as const,
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
value: false,
|
||||
description:
|
@@ -1,23 +1,14 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
import { URL } from 'url';
|
||||
|
||||
type TData = {
|
||||
channel: string;
|
||||
text: string;
|
||||
username?: string;
|
||||
icon_url?: string;
|
||||
icon_emoji?: string;
|
||||
};
|
||||
|
||||
const postMessage = async ($: IGlobalVariable) => {
|
||||
const postMessage = async ($) => {
|
||||
const { parameters } = $.step;
|
||||
const toUsername = parameters.toUsername as string;
|
||||
const text = parameters.message as string;
|
||||
const sendAsBot = parameters.sendAsBot as boolean;
|
||||
const botName = parameters.botName as string;
|
||||
const botIcon = parameters.botIcon as string;
|
||||
const toUsername = parameters.toUsername;
|
||||
const text = parameters.message;
|
||||
const sendAsBot = parameters.sendAsBot;
|
||||
const botName = parameters.botName;
|
||||
const botIcon = parameters.botIcon;
|
||||
|
||||
const data: TData = {
|
||||
const data = {
|
||||
channel: toUsername,
|
||||
text,
|
||||
};
|
@@ -1,5 +1,5 @@
|
||||
import defineAction from '../../../../helpers/define-action';
|
||||
import postMessage from './post-message';
|
||||
import defineAction from '../../../../helpers/define-action.js';
|
||||
import postMessage from './post-message.js';
|
||||
|
||||
export default defineAction({
|
||||
name: 'Send a message to channel',
|
||||
@@ -9,7 +9,7 @@ export default defineAction({
|
||||
{
|
||||
label: 'Channel',
|
||||
key: 'channel',
|
||||
type: 'dropdown' as const,
|
||||
type: 'dropdown',
|
||||
required: true,
|
||||
description: 'Pick a channel to send the message to.',
|
||||
variables: true,
|
||||
@@ -27,7 +27,7 @@ export default defineAction({
|
||||
{
|
||||
label: 'Message text',
|
||||
key: 'message',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: 'The content of your new message.',
|
||||
variables: true,
|
||||
@@ -35,7 +35,7 @@ export default defineAction({
|
||||
{
|
||||
label: 'Send as a bot?',
|
||||
key: 'sendAsBot',
|
||||
type: 'dropdown' as const,
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
value: false,
|
||||
description:
|
@@ -1,23 +1,14 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
import { URL } from 'url';
|
||||
|
||||
type TData = {
|
||||
channel: string;
|
||||
text: string;
|
||||
username?: string;
|
||||
icon_url?: string;
|
||||
icon_emoji?: string;
|
||||
};
|
||||
|
||||
const postMessage = async ($: IGlobalVariable) => {
|
||||
const postMessage = async ($) => {
|
||||
const { parameters } = $.step;
|
||||
const channelId = parameters.channel as string;
|
||||
const text = parameters.message as string;
|
||||
const sendAsBot = parameters.sendAsBot as boolean;
|
||||
const botName = parameters.botName as string;
|
||||
const botIcon = parameters.botIcon as string;
|
||||
const channelId = parameters.channel;
|
||||
const text = parameters.message;
|
||||
const sendAsBot = parameters.sendAsBot;
|
||||
const botName = parameters.botName;
|
||||
const botIcon = parameters.botIcon;
|
||||
|
||||
const data: TData = {
|
||||
const data = {
|
||||
channel: channelId,
|
||||
text,
|
||||
};
|
@@ -1,4 +1,3 @@
|
||||
import { IField, IGlobalVariable } from '@automatisch/types';
|
||||
import qs from 'qs';
|
||||
|
||||
const scopes = [
|
||||
@@ -43,13 +42,13 @@ const userScopes = [
|
||||
'users:read.email',
|
||||
];
|
||||
|
||||
export default async function generateAuthUrl($: IGlobalVariable) {
|
||||
export default async function generateAuthUrl($) {
|
||||
const oauthRedirectUrlField = $.app.auth.fields.find(
|
||||
(field: IField) => field.key == 'oAuthRedirectUrl'
|
||||
(field) => field.key == 'oAuthRedirectUrl'
|
||||
);
|
||||
const redirectUri = oauthRedirectUrlField.value as string;
|
||||
const redirectUri = oauthRedirectUrlField.value;
|
||||
const searchParams = qs.stringify({
|
||||
client_id: $.auth.data.consumerKey as string,
|
||||
client_id: $.auth.data.consumerKey,
|
||||
redirect_uri: redirectUri,
|
||||
scope: scopes.join(','),
|
||||
user_scope: userScopes.join(','),
|
@@ -1,13 +1,13 @@
|
||||
import generateAuthUrl from './generate-auth-url';
|
||||
import verifyCredentials from './verify-credentials';
|
||||
import isStillVerified from './is-still-verified';
|
||||
import generateAuthUrl from './generate-auth-url.js';
|
||||
import verifyCredentials from './verify-credentials.js';
|
||||
import isStillVerified from './is-still-verified.js';
|
||||
|
||||
export default {
|
||||
fields: [
|
||||
{
|
||||
key: 'oAuthRedirectUrl',
|
||||
label: 'OAuth Redirect URL',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
readOnly: true,
|
||||
value: '{WEB_APP_URL}/app/slack/connections/add',
|
||||
@@ -19,7 +19,7 @@ export default {
|
||||
{
|
||||
key: 'consumerKey',
|
||||
label: 'API Key',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
readOnly: false,
|
||||
value: null,
|
||||
@@ -30,7 +30,7 @@ export default {
|
||||
{
|
||||
key: 'consumerSecret',
|
||||
label: 'API Secret',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
readOnly: false,
|
||||
value: null,
|
@@ -0,0 +1,8 @@
|
||||
import getCurrentUser from '../common/get-current-user.js';
|
||||
|
||||
const isStillVerified = async ($) => {
|
||||
const user = await getCurrentUser($);
|
||||
return !!user.id;
|
||||
};
|
||||
|
||||
export default isStillVerified;
|
@@ -1,9 +0,0 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
import getCurrentUser from '../common/get-current-user';
|
||||
|
||||
const isStillVerified = async ($: IGlobalVariable) => {
|
||||
const user = await getCurrentUser($);
|
||||
return !!user.id;
|
||||
};
|
||||
|
||||
export default isStillVerified;
|
@@ -1,11 +1,10 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
import getCurrentUser from '../common/get-current-user';
|
||||
import getCurrentUser from '../common/get-current-user.js';
|
||||
|
||||
const verifyCredentials = async ($: IGlobalVariable) => {
|
||||
const verifyCredentials = async ($) => {
|
||||
const oauthRedirectUrlField = $.app.auth.fields.find(
|
||||
(field) => field.key == 'oAuthRedirectUrl'
|
||||
);
|
||||
const redirectUri = oauthRedirectUrlField.value as string;
|
||||
const redirectUri = oauthRedirectUrlField.value;
|
||||
const params = {
|
||||
code: $.auth.data.code,
|
||||
client_id: $.auth.data.consumerKey,
|
@@ -1,6 +1,4 @@
|
||||
import { TBeforeRequest } from '@automatisch/types';
|
||||
|
||||
const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
|
||||
const addAuthHeader = ($, requestConfig) => {
|
||||
const authData = $.auth.data;
|
||||
if (
|
||||
requestConfig.headers &&
|
@@ -1,8 +1,6 @@
|
||||
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
||||
|
||||
const getCurrentUser = async ($: IGlobalVariable): Promise<IJSONObject> => {
|
||||
const getCurrentUser = async ($) => {
|
||||
const params = {
|
||||
user: $.auth.data.userId as string,
|
||||
user: $.auth.data.userId,
|
||||
};
|
||||
const response = await $.http.get('/users.info', { params });
|
||||
const currentUser = response.data.user;
|
4
packages/backend/src/apps/slack/dynamic-data/index.js
Normal file
4
packages/backend/src/apps/slack/dynamic-data/index.js
Normal file
@@ -0,0 +1,4 @@
|
||||
import listChannels from './list-channels/index.js';
|
||||
import listUsers from './list-users/index.js';
|
||||
|
||||
export default [listChannels, listUsers];
|
@@ -1,4 +0,0 @@
|
||||
import listChannels from './list-channels';
|
||||
import listUsers from './list-users';
|
||||
|
||||
export default [listChannels, listUsers];
|
@@ -0,0 +1,43 @@
|
||||
export default {
|
||||
name: 'List channels',
|
||||
key: 'listChannels',
|
||||
|
||||
async run($) {
|
||||
const channels = {
|
||||
data: [],
|
||||
error: null,
|
||||
};
|
||||
|
||||
let nextCursor;
|
||||
do {
|
||||
const response = await $.http.get('/conversations.list', {
|
||||
params: {
|
||||
types: 'public_channel,private_channel',
|
||||
cursor: nextCursor,
|
||||
limit: 1000,
|
||||
},
|
||||
});
|
||||
|
||||
nextCursor = response.data.response_metadata?.next_cursor;
|
||||
|
||||
if (response.data.error === 'missing_scope') {
|
||||
throw new Error(
|
||||
`Missing "${response.data.needed}" scope while authorizing. Please, reconnect your connection!`
|
||||
);
|
||||
}
|
||||
|
||||
if (response.data.ok === false) {
|
||||
throw new Error(JSON.stringify(response.data, null, 2));
|
||||
}
|
||||
|
||||
for (const channel of response.data.channels) {
|
||||
channels.data.push({
|
||||
value: channel.id,
|
||||
name: channel.name,
|
||||
});
|
||||
}
|
||||
} while (nextCursor);
|
||||
|
||||
return channels;
|
||||
},
|
||||
};
|
@@ -1,65 +0,0 @@
|
||||
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
||||
|
||||
type TChannel = {
|
||||
id: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
type TConversationListResponseData = {
|
||||
channels: TChannel[],
|
||||
response_metadata?: {
|
||||
next_cursor: string
|
||||
};
|
||||
needed?: string;
|
||||
error?: string;
|
||||
ok: boolean;
|
||||
}
|
||||
|
||||
type TResponse = {
|
||||
data: TConversationListResponseData;
|
||||
}
|
||||
|
||||
export default {
|
||||
name: 'List channels',
|
||||
key: 'listChannels',
|
||||
|
||||
async run($: IGlobalVariable) {
|
||||
const channels: {
|
||||
data: IJSONObject[];
|
||||
error: IJSONObject | null;
|
||||
} = {
|
||||
data: [],
|
||||
error: null,
|
||||
};
|
||||
|
||||
let nextCursor;
|
||||
do {
|
||||
const response: TResponse = await $.http.get('/conversations.list', {
|
||||
params: {
|
||||
types: 'public_channel,private_channel',
|
||||
cursor: nextCursor,
|
||||
limit: 1000,
|
||||
}
|
||||
});
|
||||
|
||||
nextCursor = response.data.response_metadata?.next_cursor;
|
||||
|
||||
if (response.data.error === 'missing_scope') {
|
||||
throw new Error(`Missing "${response.data.needed}" scope while authorizing. Please, reconnect your connection!`);
|
||||
}
|
||||
|
||||
if (response.data.ok === false) {
|
||||
throw new Error(JSON.stringify(response.data, null, 2));
|
||||
}
|
||||
|
||||
for (const channel of response.data.channels) {
|
||||
channels.data.push({
|
||||
value: channel.id as string,
|
||||
name: channel.name as string,
|
||||
});
|
||||
}
|
||||
} while (nextCursor);
|
||||
|
||||
return channels;
|
||||
},
|
||||
};
|
@@ -0,0 +1,43 @@
|
||||
export default {
|
||||
name: 'List users',
|
||||
key: 'listUsers',
|
||||
|
||||
async run($) {
|
||||
const users = {
|
||||
data: [],
|
||||
error: null,
|
||||
};
|
||||
|
||||
let nextCursor;
|
||||
|
||||
do {
|
||||
const response = await $.http.get('/users.list', {
|
||||
params: {
|
||||
cursor: nextCursor,
|
||||
limit: 1000,
|
||||
},
|
||||
});
|
||||
|
||||
nextCursor = response.data.response_metadata?.next_cursor;
|
||||
|
||||
if (response.data.error === 'missing_scope') {
|
||||
throw new Error(
|
||||
`Missing "${response.data.needed}" scope while authorizing. Please, reconnect your connection!`
|
||||
);
|
||||
}
|
||||
|
||||
if (response.data.ok === false) {
|
||||
throw new Error(JSON.stringify(response.data, null, 2));
|
||||
}
|
||||
|
||||
for (const member of response.data.members) {
|
||||
users.data.push({
|
||||
value: member.id,
|
||||
name: member.profile.real_name_normalized,
|
||||
});
|
||||
}
|
||||
} while (nextCursor);
|
||||
|
||||
return users;
|
||||
},
|
||||
};
|
@@ -1,66 +0,0 @@
|
||||
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
||||
|
||||
type TMember = {
|
||||
id: string;
|
||||
profile: {
|
||||
real_name_normalized: string;
|
||||
};
|
||||
}
|
||||
|
||||
type TUserListResponseData = {
|
||||
members: TMember[],
|
||||
response_metadata?: {
|
||||
next_cursor: string
|
||||
};
|
||||
needed?: string;
|
||||
error?: string;
|
||||
ok: boolean;
|
||||
}
|
||||
|
||||
type TResponse = {
|
||||
data: TUserListResponseData;
|
||||
}
|
||||
|
||||
export default {
|
||||
name: 'List users',
|
||||
key: 'listUsers',
|
||||
|
||||
async run($: IGlobalVariable) {
|
||||
const users: {
|
||||
data: IJSONObject[];
|
||||
error: IJSONObject | null;
|
||||
} = {
|
||||
data: [],
|
||||
error: null,
|
||||
};
|
||||
|
||||
let nextCursor;
|
||||
do {
|
||||
const response: TResponse = await $.http.get('/users.list', {
|
||||
params: {
|
||||
cursor: nextCursor,
|
||||
limit: 1000,
|
||||
}
|
||||
});
|
||||
|
||||
nextCursor = response.data.response_metadata?.next_cursor;
|
||||
|
||||
if (response.data.error === 'missing_scope') {
|
||||
throw new Error(`Missing "${response.data.needed}" scope while authorizing. Please, reconnect your connection!`);
|
||||
}
|
||||
|
||||
if (response.data.ok === false) {
|
||||
throw new Error(JSON.stringify(response.data, null, 2));
|
||||
}
|
||||
|
||||
for (const member of response.data.members) {
|
||||
users.data.push({
|
||||
value: member.id as string,
|
||||
name: member.profile.real_name_normalized as string,
|
||||
});
|
||||
}
|
||||
} while (nextCursor);
|
||||
|
||||
return users;
|
||||
},
|
||||
};
|
3
packages/backend/src/apps/slack/dynamic-fields/index.js
Normal file
3
packages/backend/src/apps/slack/dynamic-fields/index.js
Normal file
@@ -0,0 +1,3 @@
|
||||
import listFieldsAfterSendAsBot from './send-as-bot/index.js';
|
||||
|
||||
export default [listFieldsAfterSendAsBot];
|
@@ -1,3 +0,0 @@
|
||||
import listFieldsAfterSendAsBot from './send-as-bot';
|
||||
|
||||
export default [listFieldsAfterSendAsBot];
|
@@ -1,16 +1,14 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
|
||||
export default {
|
||||
name: 'List fields after send as bot',
|
||||
key: 'listFieldsAfterSendAsBot',
|
||||
|
||||
async run($: IGlobalVariable) {
|
||||
async run($) {
|
||||
if ($.step.parameters.sendAsBot) {
|
||||
return [
|
||||
{
|
||||
label: 'Bot name',
|
||||
key: 'botName',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
value: 'Automatisch',
|
||||
description:
|
||||
@@ -20,7 +18,7 @@ export default {
|
||||
{
|
||||
label: 'Bot icon',
|
||||
key: 'botIcon',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: false,
|
||||
description:
|
||||
'Either an image url or an emoji available to your team (surrounded by :). For example, https://example.com/icon_256.png or :robot_face:',
|
@@ -1,9 +1,9 @@
|
||||
import defineApp from '../../helpers/define-app';
|
||||
import addAuthHeader from './common/add-auth-header';
|
||||
import actions from './actions';
|
||||
import auth from './auth';
|
||||
import dynamicData from './dynamic-data';
|
||||
import dynamicFields from './dynamic-fields';
|
||||
import defineApp from '../../helpers/define-app.js';
|
||||
import addAuthHeader from './common/add-auth-header.js';
|
||||
import actions from './actions/index.js';
|
||||
import auth from './auth/index.js';
|
||||
import dynamicData from './dynamic-data/index.js';
|
||||
import dynamicFields from './dynamic-fields/index.js';
|
||||
|
||||
export default defineApp({
|
||||
name: 'Slack',
|
Reference in New Issue
Block a user