Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 88f35ac

Browse files
Esievesunlei
authored andcommitted
feat: Slack
1 parent 4571f6f commit 88f35ac

File tree

5 files changed

+74
-27485
lines changed

5 files changed

+74
-27485
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { ConfigToType } from "openblocks-sdk/dataSource";
2+
3+
export const dataSourceConfig = {
4+
type: "dataSource",
5+
params: [
6+
{
7+
key: "webhookURL",
8+
label: "Webhook URL",
9+
type: "password",
10+
tooltip:
11+
"[Documentation](https://my.slack.com/apps/new/A0F7XDUAZ-incoming-webhooks)",
12+
rules: [
13+
{ required: true, message: "Please input your webhook URL" },
14+
],
15+
}
16+
],
17+
} as const;
18+
19+
export type DataSourceDataType = ConfigToType<typeof dataSourceConfig>;

server/node-service/src/plugins/slack/index.ts

Lines changed: 14 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,22 @@
1-
import _ from "lodash";
2-
import { OpenAPIV3, OpenAPI } from "openapi-types";
3-
import { ConfigToType, DataSourcePlugin } from "openblocks-sdk/dataSource";
4-
import { runOpenApi } from "../openApi";
5-
import { parseOpenApi, ParseOpenApiOptions } from "../openApi/parse";
1+
import { PluginContext } from "openblocks-sdk/dataSource";
2+
import queryConfig, { ActionDataType } from "./queryConfig";
3+
import { dataSourceConfig, DataSourceDataType } from "./dataSourceConfig";
4+
import run from "./run";
65

7-
import spec from "./slack.spec.json";
8-
9-
const dataSourceConfig = {
10-
type: "dataSource",
11-
params: [],
12-
} as const;
13-
14-
const parseOptions: ParseOpenApiOptions = {
15-
actionLabel: (method: string, path: string, operation: OpenAPI.Operation) => {
16-
return _.upperFirst(operation.operationId || "");
17-
},
18-
};
19-
20-
type DataSourceConfigType = ConfigToType<typeof dataSourceConfig>;
21-
22-
const slackPlugin: DataSourcePlugin<any, DataSourceConfigType> = {
6+
const slackPlugin = {
237
id: "slack",
248
name: "Slack",
259
icon: "slack.svg",
26-
category: "api",
10+
category: "database",
2711
dataSourceConfig,
28-
queryConfig: async () => {
29-
const { actions, categories } = await parseOpenApi(
30-
spec as unknown as OpenAPI.Document,
31-
parseOptions
32-
);
33-
return {
34-
type: "query",
35-
label: "Action",
36-
categories: {
37-
label: "Category",
38-
items: categories,
39-
},
40-
actions,
41-
};
42-
},
43-
run: function (actionData, dataSourceConfig): Promise<any> {
44-
const runApiDsConfig = {
45-
url: "",
46-
serverURL: "",
47-
dynamicParamsConfig: dataSourceConfig,
48-
};
49-
return runOpenApi(actionData, runApiDsConfig, spec as unknown as OpenAPIV3.Document);
12+
queryConfig: queryConfig,
13+
14+
run: async (action: ActionDataType, dataSourceConfig: DataSourceDataType, ctx: PluginContext) => {
15+
try {
16+
return await run(action, dataSourceConfig);
17+
} catch (e) {
18+
throw e;
19+
}
5020
},
5121
};
5222

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { ConfigToType } from "openblocks-sdk/dataSource";
2+
3+
const queryConfig = {
4+
type: "query",
5+
label: "Action",
6+
actions: [
7+
{
8+
actionName: "Query",
9+
label: "Query",
10+
params: [
11+
{
12+
label: "Message",
13+
key: "message",
14+
type: "jsonInput",
15+
},
16+
{
17+
label: "Channel",
18+
key: "channel",
19+
type: "textInput",
20+
}
21+
],
22+
},
23+
],
24+
} as const;
25+
26+
export type ActionDataType = ConfigToType<typeof queryConfig>;
27+
28+
export default queryConfig;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { DataSourceDataType } from "./dataSourceConfig";
2+
import { ActionDataType } from "./queryConfig";
3+
import { fetch } from "../../common/fetch";
4+
5+
export default async function run(action: ActionDataType, dataSourceConfig: DataSourceDataType) {
6+
const params = new URLSearchParams();
7+
params.append('payload', JSON.stringify({ channel: action.channel, text: action.message }));
8+
9+
return await fetch(dataSourceConfig.webhookURL, {
10+
method: 'POST',
11+
body: params,
12+
}).then(value => value.text())
13+
}

0 commit comments

Comments
 (0)