@grvpandey11/backstage-plugin-scaffolder-backend-module-ms-teams 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,89 @@
1
+ # backstage-plugin-scaffolder-backend-module-ms-teams
2
+
3
+ This is a `ms-teams` actions plugin for the `scaffolder-backend` in Backstage.
4
+
5
+ This contains a collection of actions for using to send Microsoft Teams messages.
6
+
7
+ ## Prerequisites
8
+
9
+ - Node must be installed in the environment
10
+
11
+ - You must have a Microsoft Teams webhook URL available to send messages to
12
+
13
+ ## Getting Started
14
+
15
+ In the root directory of your Backstage project:
16
+
17
+ ```shell
18
+ yarn add --cwd packages/backend @grvpandey11/backstage-plugin-scaffolder-backend-module-ms-teams
19
+ ```
20
+
21
+ Add the actions you'd like to the scaffolder:
22
+
23
+ ```typescript
24
+ // packages/backend/src/plugins/scaffolder.ts
25
+
26
+ import {
27
+ createSendTeamsMessageViaWebhookAction
28
+ } from '@grvpandey11/backstage-plugin-scaffolder-backend-module-ms-teams'
29
+
30
+ import { ScmIntegrations } from '@backstage/integration';
31
+ import { createBuiltinActions, createRouter } from '@backstage/plugin-scaffolder-backend';
32
+
33
+ ...
34
+
35
+ const integrations = ScmIntegrations.fromConfig(env.config);
36
+ const builtInActions = createBuiltinActions({
37
+ catalogClient,
38
+ integrations,
39
+ config: env.config,
40
+ reader: env.reader
41
+ });
42
+
43
+ const actions = [
44
+ createSendTeamsMessageViaWebhookAction({config: env.config}),
45
+ ...builtInActions
46
+ ];
47
+
48
+ return await createRouter({
49
+ logger: env.logger,
50
+ config: env.config,
51
+ database: env.database,
52
+ reader: env.reader,
53
+ catalogClient,
54
+ actions
55
+ });
56
+ ```
57
+
58
+ Add a ms-teams configuration section to your app-config.yaml.
59
+
60
+ > You can omit this by providing a webhook URL in the input of the step in your scaffolder template, but it must be present in one place or the other.
61
+
62
+ ```yaml
63
+ # app-config.yaml
64
+
65
+ ms-teams:
66
+ webhookUrl: "https://your-url.com"
67
+ ```
68
+
69
+ ## Example of using the send message action in a template
70
+
71
+ ```yaml
72
+ apiVersion: scaffolder.backstage.io/v1beta3
73
+ kind: Template
74
+ metadata:
75
+ name: ms-teams-demo
76
+ title: Microsoft Teams message demo
77
+ description: Send a message via MS Teams
78
+ spec:
79
+ owner: user:grvpandey11
80
+ type: service
81
+
82
+ steps:
83
+ - id: send-ms-teams-message
84
+ name: Send message
85
+ action: ms-teams:sendMessage
86
+ input:
87
+ message: "Hello, world!"
88
+ webhookUrl: "https://your-url.com" # optional if the URL is supplied in the app-config.yaml
89
+ ```
@@ -0,0 +1,64 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
6
+ var axios = require('axios');
7
+ var errors = require('@backstage/errors');
8
+
9
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
10
+
11
+ var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
12
+
13
+ function createSendTeamsMessageViaWebhookAction(options) {
14
+ const { config } = options;
15
+ return pluginScaffolderNode.createTemplateAction({
16
+ id: "ms-teams:sendMessage",
17
+ description: "Sends a Microsoft Teams message via a webhook",
18
+ schema: {
19
+ input: {
20
+ type: "object",
21
+ required: ["message"],
22
+ properties: {
23
+ message: {
24
+ title: "Message",
25
+ description: "The message to send via webhook",
26
+ type: "string"
27
+ },
28
+ webhookUrl: {
29
+ title: "Webhook URL",
30
+ description: "The Microsoft Teams webhook URL to send the request to. The URL must either be specified here or in the Backstage config",
31
+ type: "string"
32
+ }
33
+ }
34
+ }
35
+ },
36
+ async handler(ctx) {
37
+ var _a;
38
+ const webhookUrl = (_a = config.getOptionalString("ms-teams.webhookUrl")) != null ? _a : ctx.input.webhookUrl;
39
+ if (!webhookUrl) {
40
+ throw new errors.InputError(
41
+ "Webhook URL is not specified in either the app-config or the action input. This must be specified in at least one place in order to send a message"
42
+ );
43
+ }
44
+ const body = {
45
+ text: ctx.input.message
46
+ };
47
+ const result = await axios__default["default"].post(webhookUrl, body);
48
+ if (result.status !== 200) {
49
+ ctx.logger.error(
50
+ `Something went wrong while trying to send a request to the Teams webhook URL - StatusCode ${result.status}`
51
+ );
52
+ ctx.logger.debug(`Response body: ${result.data}`);
53
+ ctx.logger.debug(`Webhook URL: ${webhookUrl}`);
54
+ ctx.logger.debug(`Input message: ${ctx.input.message}`);
55
+ throw new Error(
56
+ `Something went wrong while trying to send a request to the Teams webhook URL - StatusCode ${result.status}`
57
+ );
58
+ }
59
+ }
60
+ });
61
+ }
62
+
63
+ exports.createSendTeamsMessageViaWebhookAction = createSendTeamsMessageViaWebhookAction;
64
+ //# sourceMappingURL=index.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs.js","sources":["../src/actions/ms-teams/send-ms-teams-message.ts"],"sourcesContent":["import { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport axios from 'axios';\nimport { Config } from '@backstage/config';\nimport { InputError } from '@backstage/errors';\n\n/**\n * Creates a `msteams:sendMessage` Scaffolder action.\n *\n * @public\n */\nexport function createSendTeamsMessageViaWebhookAction(options: {\n config: Config;\n }) {\n const { config } = options;\n \n return createTemplateAction<{\n message: string;\n webhookUrl?: string;\n }>({\n id: 'ms-teams:sendMessage',\n description: 'Sends a Microsoft Teams message via a webhook',\n schema: {\n input: {\n type: 'object',\n required: ['message'],\n properties: {\n message: {\n title: 'Message',\n description: 'The message to send via webhook',\n type: 'string',\n },\n webhookUrl: {\n title: 'Webhook URL',\n description:\n 'The Microsoft Teams webhook URL to send the request to. The URL must either be specified here or in the Backstage config',\n type: 'string',\n },\n },\n },\n },\n async handler(ctx) {\n const webhookUrl =\n config.getOptionalString('ms-teams.webhookUrl') ?? ctx.input.webhookUrl;\n \n if (!webhookUrl) {\n throw new InputError(\n 'Webhook URL is not specified in either the app-config or the action input. This must be specified in at least one place in order to send a message',\n );\n }\n \n const body = {\n text: ctx.input.message,\n };\n \n const result = await axios.post(webhookUrl, body);\n \n if (result.status !== 200) {\n ctx.logger.error(\n `Something went wrong while trying to send a request to the Teams webhook URL - StatusCode ${result.status}`,\n );\n ctx.logger.debug(`Response body: ${result.data}`);\n ctx.logger.debug(`Webhook URL: ${webhookUrl}`);\n ctx.logger.debug(`Input message: ${ctx.input.message}`);\n throw new Error(\n `Something went wrong while trying to send a request to the Teams webhook URL - StatusCode ${result.status}`,\n );\n }\n },\n });\n }\n"],"names":["createTemplateAction","InputError","axios"],"mappings":";;;;;;;;;;;;AAUO,SAAS,uCAAuC,OAElD,EAAA;AACD,EAAM,MAAA,EAAE,QAAW,GAAA,OAAA,CAAA;AAEnB,EAAA,OAAOA,yCAGJ,CAAA;AAAA,IACD,EAAI,EAAA,sBAAA;AAAA,IACJ,WAAa,EAAA,+CAAA;AAAA,IACb,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,IAAM,EAAA,QAAA;AAAA,QACN,QAAA,EAAU,CAAC,SAAS,CAAA;AAAA,QACpB,UAAY,EAAA;AAAA,UACV,OAAS,EAAA;AAAA,YACP,KAAO,EAAA,SAAA;AAAA,YACP,WAAa,EAAA,iCAAA;AAAA,YACb,IAAM,EAAA,QAAA;AAAA,WACR;AAAA,UACA,UAAY,EAAA;AAAA,YACV,KAAO,EAAA,aAAA;AAAA,YACP,WACE,EAAA,0HAAA;AAAA,YACF,IAAM,EAAA,QAAA;AAAA,WACR;AAAA,SACF;AAAA,OACF;AAAA,KACF;AAAA,IACA,MAAM,QAAQ,GAAK,EAAA;AAxCzB,MAAA,IAAA,EAAA,CAAA;AAyCQ,MAAA,MAAM,cACJ,EAAO,GAAA,MAAA,CAAA,iBAAA,CAAkB,qBAAqB,CAA9C,KAAA,IAAA,GAAA,EAAA,GAAmD,IAAI,KAAM,CAAA,UAAA,CAAA;AAE/D,MAAA,IAAI,CAAC,UAAY,EAAA;AACf,QAAA,MAAM,IAAIC,iBAAA;AAAA,UACR,oJAAA;AAAA,SACF,CAAA;AAAA,OACF;AAEA,MAAA,MAAM,IAAO,GAAA;AAAA,QACX,IAAA,EAAM,IAAI,KAAM,CAAA,OAAA;AAAA,OAClB,CAAA;AAEA,MAAA,MAAM,MAAS,GAAA,MAAMC,yBAAM,CAAA,IAAA,CAAK,YAAY,IAAI,CAAA,CAAA;AAEhD,MAAI,IAAA,MAAA,CAAO,WAAW,GAAK,EAAA;AACzB,QAAA,GAAA,CAAI,MAAO,CAAA,KAAA;AAAA,UACT,CAAA,0FAAA,EAA6F,OAAO,MAAM,CAAA,CAAA;AAAA,SAC5G,CAAA;AACA,QAAA,GAAA,CAAI,MAAO,CAAA,KAAA,CAAM,CAAkB,eAAA,EAAA,MAAA,CAAO,IAAI,CAAE,CAAA,CAAA,CAAA;AAChD,QAAA,GAAA,CAAI,MAAO,CAAA,KAAA,CAAM,CAAgB,aAAA,EAAA,UAAU,CAAE,CAAA,CAAA,CAAA;AAC7C,QAAA,GAAA,CAAI,OAAO,KAAM,CAAA,CAAA,eAAA,EAAkB,GAAI,CAAA,KAAA,CAAM,OAAO,CAAE,CAAA,CAAA,CAAA;AACtD,QAAA,MAAM,IAAI,KAAA;AAAA,UACR,CAAA,0FAAA,EAA6F,OAAO,MAAM,CAAA,CAAA;AAAA,SAC5G,CAAA;AAAA,OACF;AAAA,KACF;AAAA,GACD,CAAA,CAAA;AACH;;;;"}
@@ -0,0 +1,17 @@
1
+ import * as _backstage_plugin_scaffolder_node from '@backstage/plugin-scaffolder-node';
2
+ import * as _backstage_types from '@backstage/types';
3
+ import { Config } from '@backstage/config';
4
+
5
+ /**
6
+ * Creates a `msteams:sendMessage` Scaffolder action.
7
+ *
8
+ * @public
9
+ */
10
+ declare function createSendTeamsMessageViaWebhookAction(options: {
11
+ config: Config;
12
+ }): _backstage_plugin_scaffolder_node.TemplateAction<{
13
+ message: string;
14
+ webhookUrl?: string | undefined;
15
+ }, _backstage_types.JsonObject>;
16
+
17
+ export { createSendTeamsMessageViaWebhookAction };
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@grvpandey11/backstage-plugin-scaffolder-backend-module-ms-teams",
3
+ "description": "The Microsoft Teams module for @backstage/plugin-scaffolder-backend",
4
+ "version": "1.0.0",
5
+ "main": "dist/index.cjs.js",
6
+ "types": "dist/index.d.ts",
7
+ "license": "Apache-2.0",
8
+ "private": false,
9
+ "publishConfig": {
10
+ "access": "public",
11
+ "main": "dist/index.cjs.js",
12
+ "types": "dist/index.d.ts"
13
+ },
14
+ "backstage": {
15
+ "role": "backend-plugin-module"
16
+ },
17
+ "scripts": {
18
+ "start": "backstage-cli package start",
19
+ "build": "backstage-cli package build",
20
+ "lint": "backstage-cli package lint",
21
+ "test": "backstage-cli package test",
22
+ "clean": "backstage-cli package clean",
23
+ "prepack": "backstage-cli package prepack",
24
+ "postpack": "backstage-cli package postpack"
25
+ },
26
+ "dependencies": {
27
+ "@backstage/backend-common": "^0.19.0",
28
+ "@backstage/config": "^1.0.8",
29
+ "@backstage/errors": "^1.2.1",
30
+ "@backstage/plugin-scaffolder-node": "^0.1.5",
31
+ "@types/express": "*",
32
+ "axios": "^1.4.0",
33
+ "express": "^4.17.1",
34
+ "express-promise-router": "^4.1.0",
35
+ "node-fetch": "^2.6.7",
36
+ "winston": "^3.2.1",
37
+ "yn": "^4.0.0"
38
+ },
39
+ "devDependencies": {
40
+ "@backstage/cli": "^0.22.8",
41
+ "@types/supertest": "^2.0.12",
42
+ "msw": "^1.0.0",
43
+ "supertest": "^6.2.4"
44
+ },
45
+ "files": [
46
+ "dist"
47
+ ]
48
+ }
package/src/index.ts ADDED
@@ -0,0 +1,8 @@
1
+ /***/
2
+ /**
3
+ * The Ms Teams module for @backstage/plugin-scaffolder-backend.
4
+ *
5
+ * @packageDocumentation
6
+ */
7
+
8
+ export * from './actions';