Compare commits
28 Commits
Author | SHA1 | Date | |
---|---|---|---|
91a99261d6 | |||
04872e7ae9 | |||
7937d9aeff | |||
07ea092dea | |||
ccc2fc689f | |||
9e3808bfee | |||
717dcab4ad | |||
6a8946f2b1 | |||
84e1624e64 | |||
b46d958f35 | |||
d044085739 | |||
3510767a72 | |||
ec17d7835e | |||
cb072d0f6a | |||
1240505227 | |||
09c0bc4e6f | |||
41f98b6869 | |||
e854a62eae | |||
ec86352b58 | |||
47f1e97386 | |||
f7e1df2e64 | |||
552d3dc211 | |||
f0d7e5c998 | |||
eeb1a99884 | |||
55e75766b7 | |||
7012782480 | |||
4cec262ed8 | |||
7d1f7c28d6 |
19
.gitignore
vendored
19
.gitignore
vendored
@ -1,5 +1,22 @@
|
||||
.nogit/
|
||||
node_modules/
|
||||
|
||||
# artifacts
|
||||
coverage/
|
||||
public/
|
||||
pages/
|
||||
|
||||
# installs
|
||||
node_modules/
|
||||
|
||||
# caches
|
||||
.yarn/
|
||||
.cache/
|
||||
.rpt2_cache
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_web/
|
||||
dist_serve/
|
||||
dist_ts_web/
|
||||
|
||||
# custom
|
@ -1,5 +1,5 @@
|
||||
# gitzone standard
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
# gitzone ci_default
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
@ -26,6 +26,7 @@ mirror:
|
||||
snyk:
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install -g snyk
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command snyk test
|
||||
@ -36,38 +37,29 @@ snyk:
|
||||
# ====================
|
||||
# test stage
|
||||
# ====================
|
||||
testLEGACY:
|
||||
stage: test
|
||||
script:
|
||||
- npmci node install legacy
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
allow_failure: true
|
||||
|
||||
testLTS:
|
||||
stage: test
|
||||
script:
|
||||
- npmci node install lts
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
testSTABLE:
|
||||
testStable:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
|
||||
testBuild:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
release:
|
||||
@ -86,19 +78,11 @@ release:
|
||||
# ====================
|
||||
codequality:
|
||||
stage: metadata
|
||||
image: docker:stable
|
||||
allow_failure: true
|
||||
services:
|
||||
- docker:stable-dind
|
||||
script:
|
||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
||||
- docker run
|
||||
--env SOURCE_CODE="$PWD"
|
||||
--volume "$PWD":/code
|
||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
||||
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
|
||||
artifacts:
|
||||
paths: [codeclimate.json]
|
||||
- npmci command npm install -g tslint typescript
|
||||
- npmci npm install
|
||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
@ -114,12 +98,15 @@ trigger:
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
image: hosttoday/ht-docker-dbase:npmci
|
||||
services:
|
||||
- docker:stable-dind
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci command npm install -g typedoc typescript
|
||||
- npmci command npm install -g @gitzone/tsdoc
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
||||
- npmci command tsdoc
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
@ -130,13 +117,3 @@ pages:
|
||||
paths:
|
||||
- public
|
||||
allow_failure: true
|
||||
|
||||
windowsCompatibility:
|
||||
image: stefanscherer/node-windows:10-build-tools
|
||||
stage: metadata
|
||||
script:
|
||||
- npm install & npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- windows
|
||||
allow_failure: true
|
||||
|
29
.vscode/launch.json
vendored
Normal file
29
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "current file",
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"args": [
|
||||
"${relativeFile}"
|
||||
],
|
||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"protocol": "inspector",
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
},
|
||||
{
|
||||
"name": "test.ts",
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"args": [
|
||||
"test/test.ts"
|
||||
],
|
||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"protocol": "inspector",
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
}
|
||||
]
|
||||
}
|
3
dist_ts/index.d.ts
vendored
Normal file
3
dist_ts/index.d.ts
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
export * from './slack.classes.slackaccount';
|
||||
export * from './slack.classes.slackmessage';
|
||||
export * from './slack.classes.slacklog';
|
16
dist_ts/index.js
Normal file
16
dist_ts/index.js
Normal file
@ -0,0 +1,16 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
||||
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
__exportStar(require("./slack.classes.slackaccount"), exports);
|
||||
__exportStar(require("./slack.classes.slackmessage"), exports);
|
||||
__exportStar(require("./slack.classes.slacklog"), exports);
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7QUFBQSwrREFBNkM7QUFDN0MsK0RBQTZDO0FBQzdDLDJEQUF5QyJ9
|
14
dist_ts/slack.classes.slackaccount.d.ts
vendored
Normal file
14
dist_ts/slack.classes.slackaccount.d.ts
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
import * as plugins from './slack.plugins';
|
||||
import { IMessageOptions } from './slack.classes.slackmessage';
|
||||
export declare class SlackAccount {
|
||||
private postUrl;
|
||||
private updateUrl;
|
||||
private slackToken;
|
||||
constructor(slackTokenArg: string);
|
||||
sendMessage(optionsArg: {
|
||||
messageOptions: IMessageOptions;
|
||||
channelArg: string;
|
||||
ts?: string;
|
||||
mode: 'new' | 'threaded' | 'update';
|
||||
}): Promise<plugins.smartrequest.IExtendedIncomingMessage>;
|
||||
}
|
65
dist_ts/slack.classes.slackaccount.js
Normal file
65
dist_ts/slack.classes.slackaccount.js
Normal file
@ -0,0 +1,65 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.SlackAccount = void 0;
|
||||
const plugins = __importStar(require("./slack.plugins"));
|
||||
class SlackAccount {
|
||||
constructor(slackTokenArg) {
|
||||
this.postUrl = 'https://slack.com/api/chat.postMessage';
|
||||
this.updateUrl = 'https://slack.com/api/chat.update';
|
||||
this.slackToken = slackTokenArg;
|
||||
}
|
||||
async sendMessage(optionsArg) {
|
||||
let requestBody = {
|
||||
channel: optionsArg.channelArg,
|
||||
text: optionsArg.messageOptions.text
|
||||
};
|
||||
if (optionsArg.messageOptions.fields) {
|
||||
requestBody = Object.assign(Object.assign({}, requestBody), { attachments: [
|
||||
{
|
||||
pretext: optionsArg.messageOptions.pretext,
|
||||
fields: optionsArg.messageOptions.fields,
|
||||
ts: optionsArg.messageOptions.ts,
|
||||
color: optionsArg.messageOptions.color
|
||||
}
|
||||
] });
|
||||
}
|
||||
let postUrl = this.postUrl;
|
||||
switch (true) {
|
||||
case optionsArg.ts && optionsArg.mode === 'update':
|
||||
requestBody = Object.assign(Object.assign({}, requestBody), { ts: optionsArg.ts });
|
||||
postUrl = this.updateUrl;
|
||||
break;
|
||||
case optionsArg.ts && optionsArg.mode === 'threaded':
|
||||
requestBody = Object.assign(Object.assign({}, requestBody), { thread_ts: optionsArg.ts });
|
||||
break;
|
||||
}
|
||||
const response = await plugins.smartrequest.postJson(postUrl, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${this.slackToken}`
|
||||
},
|
||||
requestBody
|
||||
});
|
||||
return response;
|
||||
}
|
||||
}
|
||||
exports.SlackAccount = SlackAccount;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2xhY2suY2xhc3Nlcy5zbGFja2FjY291bnQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbGFjay5jbGFzc2VzLnNsYWNrYWNjb3VudC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0FBQUEseURBQTJDO0FBRzNDLE1BQWEsWUFBWTtJQUl2QixZQUFZLGFBQXFCO1FBSHpCLFlBQU8sR0FBRyx3Q0FBd0MsQ0FBQztRQUNuRCxjQUFTLEdBQUcsbUNBQW1DLENBQUM7UUFHdEQsSUFBSSxDQUFDLFVBQVUsR0FBRyxhQUFhLENBQUM7SUFDbEMsQ0FBQztJQUVELEtBQUssQ0FBQyxXQUFXLENBQUMsVUFLakI7UUFDQyxJQUFJLFdBQVcsR0FBUTtZQUNyQixPQUFPLEVBQUUsVUFBVSxDQUFDLFVBQVU7WUFDOUIsSUFBSSxFQUFFLFVBQVUsQ0FBQyxjQUFjLENBQUMsSUFBSTtTQUNyQyxDQUFDO1FBRUYsSUFBSSxVQUFVLENBQUMsY0FBYyxDQUFDLE1BQU0sRUFBRTtZQUNwQyxXQUFXLG1DQUNOLFdBQVcsS0FDZCxXQUFXLEVBQUU7b0JBQ1g7d0JBQ0UsT0FBTyxFQUFFLFVBQVUsQ0FBQyxjQUFjLENBQUMsT0FBTzt3QkFDMUMsTUFBTSxFQUFFLFVBQVUsQ0FBQyxjQUFjLENBQUMsTUFBTTt3QkFDeEMsRUFBRSxFQUFFLFVBQVUsQ0FBQyxjQUFjLENBQUMsRUFBRTt3QkFDaEMsS0FBSyxFQUFFLFVBQVUsQ0FBQyxjQUFjLENBQUMsS0FBSztxQkFDdkM7aUJBQ0YsR0FDRixDQUFDO1NBQ0g7UUFFRCxJQUFJLE9BQU8sR0FBRyxJQUFJLENBQUMsT0FBTyxDQUFDO1FBRTNCLFFBQVEsSUFBSSxFQUFFO1lBQ1osS0FBSyxVQUFVLENBQUMsRUFBRSxJQUFJLFVBQVUsQ0FBQyxJQUFJLEtBQUssUUFBUTtnQkFDaEQsV0FBVyxtQ0FDTixXQUFXLEtBQ2QsRUFBRSxFQUFFLFVBQVUsQ0FBQyxFQUFFLEdBQ2xCLENBQUM7Z0JBQ0YsT0FBTyxHQUFHLElBQUksQ0FBQyxTQUFTLENBQUM7Z0JBQ3pCLE1BQU07WUFDUixLQUFLLFVBQVUsQ0FBQyxFQUFFLElBQUksVUFBVSxDQUFDLElBQUksS0FBSyxVQUFVO2dCQUNsRCxXQUFXLG1DQUNOLFdBQVcsS0FDZCxTQUFTLEVBQUUsVUFBVSxDQUFDLEVBQUUsR0FDekIsQ0FBQztnQkFDRixNQUFNO1NBQ1Q7UUFFRCxNQUFNLFFBQVEsR0FBRyxNQUFNLE9BQU8sQ0FBQyxZQUFZLENBQUMsUUFBUSxDQUFDLE9BQU8sRUFBRTtZQUM1RCxPQUFPLEVBQUU7Z0JBQ1AsYUFBYSxFQUFFLFVBQVUsSUFBSSxDQUFDLFVBQVUsRUFBRTthQUMzQztZQUNELFdBQVc7U0FDWixDQUFDLENBQUM7UUFDSCxPQUFPLFFBQVEsQ0FBQztJQUNsQixDQUFDO0NBQ0Y7QUEzREQsb0NBMkRDIn0=
|
13
dist_ts/slack.classes.slacklog.d.ts
vendored
Normal file
13
dist_ts/slack.classes.slacklog.d.ts
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
import { SlackAccount } from './slack.classes.slackaccount';
|
||||
import { SlackMessage } from './slack.classes.slackmessage';
|
||||
export declare class SlackLog {
|
||||
slackAccount: SlackAccount;
|
||||
slackMessage: SlackMessage;
|
||||
channelName: string;
|
||||
completeLog: string;
|
||||
constructor(optionsArg: {
|
||||
slackAccount: SlackAccount;
|
||||
channelName: string;
|
||||
});
|
||||
sendLogLine(logText: string): Promise<void>;
|
||||
}
|
27
dist_ts/slack.classes.slacklog.js
Normal file
27
dist_ts/slack.classes.slacklog.js
Normal file
@ -0,0 +1,27 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.SlackLog = void 0;
|
||||
const slack_classes_slackmessage_1 = require("./slack.classes.slackmessage");
|
||||
class SlackLog {
|
||||
constructor(optionsArg) {
|
||||
this.completeLog = ``;
|
||||
this.slackAccount = optionsArg.slackAccount;
|
||||
this.channelName = optionsArg.channelName;
|
||||
}
|
||||
async sendLogLine(logText) {
|
||||
if (!this.slackMessage) {
|
||||
this.slackMessage = new slack_classes_slackmessage_1.SlackMessage(this.slackAccount, {
|
||||
text: '``` log is loading... ```'
|
||||
});
|
||||
await this.slackMessage.sendToRoom(this.channelName);
|
||||
}
|
||||
const date = new Date();
|
||||
this.completeLog +=
|
||||
`${date.getHours()}:${date.getMinutes()}:${date.getSeconds()} - ` + logText + '\n';
|
||||
await this.slackMessage.updateAndSend({
|
||||
text: '```\n' + this.completeLog + '\n```'
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.SlackLog = SlackLog;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2xhY2suY2xhc3Nlcy5zbGFja2xvZy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NsYWNrLmNsYXNzZXMuc2xhY2tsb2cudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBQ0EsNkVBQTREO0FBRTVELE1BQWEsUUFBUTtJQU9uQixZQUFZLFVBQStEO1FBRnBFLGdCQUFXLEdBQUcsRUFBRSxDQUFDO1FBR3RCLElBQUksQ0FBQyxZQUFZLEdBQUcsVUFBVSxDQUFDLFlBQVksQ0FBQztRQUM1QyxJQUFJLENBQUMsV0FBVyxHQUFHLFVBQVUsQ0FBQyxXQUFXLENBQUM7SUFDNUMsQ0FBQztJQUNNLEtBQUssQ0FBQyxXQUFXLENBQUMsT0FBZTtRQUN0QyxJQUFJLENBQUMsSUFBSSxDQUFDLFlBQVksRUFBRTtZQUN0QixJQUFJLENBQUMsWUFBWSxHQUFHLElBQUkseUNBQVksQ0FBQyxJQUFJLENBQUMsWUFBWSxFQUFFO2dCQUN0RCxJQUFJLEVBQUUsMkJBQTJCO2FBQ2xDLENBQUMsQ0FBQztZQUNILE1BQU0sSUFBSSxDQUFDLFlBQVksQ0FBQyxVQUFVLENBQUMsSUFBSSxDQUFDLFdBQVcsQ0FBQyxDQUFDO1NBQ3REO1FBQ0QsTUFBTSxJQUFJLEdBQUcsSUFBSSxJQUFJLEVBQUUsQ0FBQztRQUN4QixJQUFJLENBQUMsV0FBVztZQUNkLEdBQUcsSUFBSSxDQUFDLFFBQVEsRUFBRSxJQUFJLElBQUksQ0FBQyxVQUFVLEVBQUUsSUFBSSxJQUFJLENBQUMsVUFBVSxFQUFFLEtBQUssR0FBRyxPQUFPLEdBQUcsSUFBSSxDQUFDO1FBQ3JGLE1BQU0sSUFBSSxDQUFDLFlBQVksQ0FBQyxhQUFhLENBQUM7WUFDcEMsSUFBSSxFQUFFLE9BQU8sR0FBRyxJQUFJLENBQUMsV0FBVyxHQUFHLE9BQU87U0FDM0MsQ0FBQyxDQUFDO0lBQ0wsQ0FBQztDQUNGO0FBekJELDRCQXlCQyJ9
|
62
dist_ts/slack.classes.slackmessage.d.ts
vendored
Normal file
62
dist_ts/slack.classes.slackmessage.d.ts
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
import * as plugins from './slack.plugins';
|
||||
import { SlackAccount } from './slack.classes.slackaccount';
|
||||
export interface IAttachmentField {
|
||||
title: string;
|
||||
value: string;
|
||||
short?: boolean;
|
||||
}
|
||||
export interface IMessageOptions {
|
||||
/**
|
||||
* "Required plain-text summary of the attachment."
|
||||
*/
|
||||
fallback?: string;
|
||||
/**
|
||||
* a side color
|
||||
*/
|
||||
color?: string;
|
||||
/**
|
||||
* a message to show above
|
||||
*/
|
||||
pretext?: string;
|
||||
/**
|
||||
* author name of the attachment
|
||||
*/
|
||||
author_name?: string;
|
||||
/**
|
||||
* a link to the author
|
||||
*/
|
||||
author_link?: string;
|
||||
/**
|
||||
* a string to the author
|
||||
*/
|
||||
author_icon?: string;
|
||||
/**
|
||||
* a title for the attachment
|
||||
*/
|
||||
title?: string;
|
||||
/**
|
||||
* a link for the title
|
||||
*/
|
||||
title_link?: string;
|
||||
/**
|
||||
* the main text of the message
|
||||
*/
|
||||
text?: string;
|
||||
fields?: IAttachmentField[];
|
||||
image_url?: string;
|
||||
thumb_url?: string;
|
||||
footer?: string;
|
||||
footer_icon?: string;
|
||||
ts?: number;
|
||||
}
|
||||
export declare class SlackMessage {
|
||||
slackAccountRef: SlackAccount;
|
||||
messageOptions: IMessageOptions;
|
||||
channel: string;
|
||||
ts: string;
|
||||
requestRunning: plugins.smartpromise.Deferred<unknown>;
|
||||
constructor(slackAccountArg: SlackAccount, messageOptionsArg: IMessageOptions);
|
||||
updateAndSend(messageOptionsArg: IMessageOptions): Promise<void>;
|
||||
startThread(messageOptionsArg: IMessageOptions): Promise<void>;
|
||||
sendToRoom(channelNameArg: string, modeArg?: 'new' | 'update' | 'threaded'): Promise<void>;
|
||||
}
|
61
dist_ts/slack.classes.slackmessage.js
Normal file
61
dist_ts/slack.classes.slackmessage.js
Normal file
@ -0,0 +1,61 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.SlackMessage = void 0;
|
||||
const plugins = __importStar(require("./slack.plugins"));
|
||||
class SlackMessage {
|
||||
constructor(slackAccountArg, messageOptionsArg) {
|
||||
this.requestRunning = plugins.smartpromise.defer();
|
||||
if (slackAccountArg) {
|
||||
this.slackAccountRef = slackAccountArg;
|
||||
}
|
||||
this.messageOptions = messageOptionsArg;
|
||||
this.requestRunning.resolve();
|
||||
}
|
||||
async updateAndSend(messageOptionsArg) {
|
||||
this.messageOptions = messageOptionsArg;
|
||||
await this.sendToRoom(this.channel, 'update');
|
||||
}
|
||||
async startThread(messageOptionsArg) {
|
||||
this.messageOptions = messageOptionsArg;
|
||||
this.sendToRoom(this.channel, 'threaded');
|
||||
}
|
||||
async sendToRoom(channelNameArg, modeArg = 'new') {
|
||||
this.channel = channelNameArg;
|
||||
if (this.slackAccountRef) {
|
||||
const response = await this.slackAccountRef.sendMessage({
|
||||
channelArg: this.channel,
|
||||
messageOptions: this.messageOptions,
|
||||
mode: modeArg,
|
||||
ts: this.ts
|
||||
});
|
||||
if (modeArg === 'new') {
|
||||
this.ts = response.body.message.ts;
|
||||
this.channel = response.body.channel;
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new Error('you need to set a slackRef before sending the message!');
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.SlackMessage = SlackMessage;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2xhY2suY2xhc3Nlcy5zbGFja21lc3NhZ2UuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbGFjay5jbGFzc2VzLnNsYWNrbWVzc2FnZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0FBQUEseURBQTJDO0FBc0QzQyxNQUFhLFlBQVk7SUFRdkIsWUFBWSxlQUE2QixFQUFFLGlCQUFrQztRQUZ0RSxtQkFBYyxHQUFHLE9BQU8sQ0FBQyxZQUFZLENBQUMsS0FBSyxFQUFFLENBQUM7UUFHbkQsSUFBSSxlQUFlLEVBQUU7WUFDbkIsSUFBSSxDQUFDLGVBQWUsR0FBRyxlQUFlLENBQUM7U0FDeEM7UUFDRCxJQUFJLENBQUMsY0FBYyxHQUFHLGlCQUFpQixDQUFDO1FBQ3hDLElBQUksQ0FBQyxjQUFjLENBQUMsT0FBTyxFQUFFLENBQUM7SUFDaEMsQ0FBQztJQUVELEtBQUssQ0FBQyxhQUFhLENBQUMsaUJBQWtDO1FBQ3BELElBQUksQ0FBQyxjQUFjLEdBQUcsaUJBQWlCLENBQUM7UUFDeEMsTUFBTSxJQUFJLENBQUMsVUFBVSxDQUFDLElBQUksQ0FBQyxPQUFPLEVBQUUsUUFBUSxDQUFDLENBQUM7SUFDaEQsQ0FBQztJQUVELEtBQUssQ0FBQyxXQUFXLENBQUMsaUJBQWtDO1FBQ2xELElBQUksQ0FBQyxjQUFjLEdBQUcsaUJBQWlCLENBQUM7UUFDeEMsSUFBSSxDQUFDLFVBQVUsQ0FBQyxJQUFJLENBQUMsT0FBTyxFQUFFLFVBQVUsQ0FBQyxDQUFDO0lBQzVDLENBQUM7SUFFRCxLQUFLLENBQUMsVUFBVSxDQUFDLGNBQXNCLEVBQUUsVUFBeUMsS0FBSztRQUNyRixJQUFJLENBQUMsT0FBTyxHQUFHLGNBQWMsQ0FBQztRQUM5QixJQUFJLElBQUksQ0FBQyxlQUFlLEVBQUU7WUFDeEIsTUFBTSxRQUFRLEdBQUcsTUFBTSxJQUFJLENBQUMsZUFBZSxDQUFDLFdBQVcsQ0FBQztnQkFDdEQsVUFBVSxFQUFFLElBQUksQ0FBQyxPQUFPO2dCQUN4QixjQUFjLEVBQUUsSUFBSSxDQUFDLGNBQWM7Z0JBQ25DLElBQUksRUFBRSxPQUFPO2dCQUNiLEVBQUUsRUFBRSxJQUFJLENBQUMsRUFBRTthQUNaLENBQUMsQ0FBQztZQUNILElBQUksT0FBTyxLQUFLLEtBQUssRUFBRTtnQkFDckIsSUFBSSxDQUFDLEVBQUUsR0FBRyxRQUFRLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQyxFQUFFLENBQUM7Z0JBQ25DLElBQUksQ0FBQyxPQUFPLEdBQUcsUUFBUSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUM7YUFDdEM7U0FDRjthQUFNO1lBQ0wsTUFBTSxJQUFJLEtBQUssQ0FBQyx3REFBd0QsQ0FBQyxDQUFDO1NBQzNFO0lBQ0gsQ0FBQztDQUNGO0FBM0NELG9DQTJDQyJ9
|
3
dist_ts/slack.plugins.d.ts
vendored
Normal file
3
dist_ts/slack.plugins.d.ts
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
import * as smartrequest from '@pushrocks/smartrequest';
|
||||
export { smartpromise, smartrequest };
|
28
dist_ts/slack.plugins.js
Normal file
28
dist_ts/slack.plugins.js
Normal file
@ -0,0 +1,28 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.smartrequest = exports.smartpromise = void 0;
|
||||
// pushrocks scope
|
||||
const smartpromise = __importStar(require("@pushrocks/smartpromise"));
|
||||
exports.smartpromise = smartpromise;
|
||||
const smartrequest = __importStar(require("@pushrocks/smartrequest"));
|
||||
exports.smartrequest = smartrequest;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2xhY2sucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NsYWNrLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OztBQUFBLGtCQUFrQjtBQUNsQixzRUFBd0Q7QUFHL0Msb0NBQVk7QUFGckIsc0VBQXdEO0FBRWpDLG9DQUFZIn0=
|
@ -2,5 +2,15 @@
|
||||
"npmci": {
|
||||
"npmGlobalTools": [],
|
||||
"npmAccessLevel": "public"
|
||||
},
|
||||
"gitzone": {
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "mojoio",
|
||||
"gitrepo": "slack",
|
||||
"shortDescription": "slack api abstraction for the mojo.io ecosystem",
|
||||
"npmPackagename": "@mojoio/slack",
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
25217
package-lock.json
generated
25217
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
38
package.json
38
package.json
@ -1,25 +1,39 @@
|
||||
{
|
||||
"name": "@pushrocks/slack",
|
||||
"version": "2.0.4",
|
||||
"name": "@mojoio/slack",
|
||||
"version": "3.0.5",
|
||||
"private": false,
|
||||
"description": "API abstraction for mojoio",
|
||||
"description": "slack api abstraction for the mojo.io ecosystem",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"test": "tstest test/",
|
||||
"build": "tsbuild"
|
||||
"build": "tsbuild --web"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.0.22",
|
||||
"@gitzone/tsrun": "^1.1.12",
|
||||
"@gitzone/tstest": "^1.0.15",
|
||||
"@pushrocks/qenv": "^2.0.2",
|
||||
"@pushrocks/tapbundle": "^3.0.7",
|
||||
"@types/node": "^10.9.4"
|
||||
"@gitzone/tsbuild": "^2.1.25",
|
||||
"@gitzone/tsrun": "^1.2.17",
|
||||
"@gitzone/tstest": "^1.0.54",
|
||||
"@pushrocks/qenv": "^4.0.10",
|
||||
"@pushrocks/tapbundle": "^3.2.14",
|
||||
"@types/node": "^16.4.1",
|
||||
"tslint": "^6.1.3",
|
||||
"tslint-config-prettier": "^1.18.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"smartrequest": "^1.0.6"
|
||||
}
|
||||
"@pushrocks/smartpromise": "^3.1.6",
|
||||
"@pushrocks/smartrequest": "^1.1.52"
|
||||
},
|
||||
"files": [
|
||||
"ts/*",
|
||||
"ts_web/*",
|
||||
"dist/*",
|
||||
"dist_web/*",
|
||||
"dist_ts_web/*",
|
||||
"assets/*",
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
]
|
||||
}
|
||||
|
40
readme.md
40
readme.md
@ -1,26 +1,20 @@
|
||||
# slackme
|
||||
# @mojoio/slack
|
||||
slack api abstraction for the mojo.io ecosystem
|
||||
|
||||
API abstraction for mojoio
|
||||
|
||||
## Availabililty
|
||||
|
||||
[](https://www.npmjs.com/package/slackme)
|
||||
[](https://GitLab.com/mojoio/slackme)
|
||||
[](https://github.com/mojoio/slackme)
|
||||
[](https://mojoio.gitlab.io/slackme/)
|
||||
## Availabililty and Links
|
||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@mojoio/slack)
|
||||
* [gitlab.com (source)](https://gitlab.com/mojoio/slack)
|
||||
* [github.com (source mirror)](https://github.com/mojoio/slack)
|
||||
* [docs (typedoc)](https://mojoio.gitlab.io/slack/)
|
||||
|
||||
## Status for master
|
||||
|
||||
[](https://GitLab.com/mojoio/slackme/commits/master)
|
||||
[](https://GitLab.com/mojoio/slackme/commits/master)
|
||||
[](https://www.npmjs.com/package/slackme)
|
||||
[](https://david-dm.org/mojoio/slackme)
|
||||
[](https://www.bithound.io/github/mojoio/slackme/master/dependencies/npm)
|
||||
[](https://www.bithound.io/github/mojoio/slackme)
|
||||
[](https://snyk.io/test/npm/slackme)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](https://standardjs.com/)
|
||||
[](https://gitlab.com/mojoio/slack/commits/master)
|
||||
[](https://gitlab.com/mojoio/slack/commits/master)
|
||||
[](https://www.npmjs.com/package/@mojoio/slack)
|
||||
[](https://snyk.io/test/npm/@mojoio/slack)
|
||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
[](https://prettier.io/)
|
||||
|
||||
## Usage
|
||||
|
||||
@ -104,9 +98,9 @@ mySlackMessage.title = 'another Title'
|
||||
mySlackMessage.sendToRoom('anotherroom')
|
||||
```
|
||||
|
||||
For further information read the linked docs at the top of this README.
|
||||
For further information read the linked docs at the top of this readme.
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||
|
||||
[](https://mojo.io)
|
||||
[](https://maintainedby.lossless.com)
|
||||
|
144
test/test.ts
144
test/test.ts
@ -5,38 +5,126 @@ let testQenv = new Qenv(process.cwd(), process.cwd() + '/.nogit');
|
||||
|
||||
import * as slackme from '../ts/index';
|
||||
|
||||
let testSlackme: slackme.Slackme;
|
||||
let testSlackAccount: slackme.SlackAccount;
|
||||
let testSlackMessage: slackme.SlackMessage;
|
||||
|
||||
tap.test('should create a valid slackme instance', async () => {
|
||||
testSlackme = new slackme.Slackme(process.env.SLACK_TOKEN);
|
||||
tap.test('should create a valid slackme instance', async tools => {
|
||||
testSlackAccount = new slackme.SlackAccount(testQenv.getEnvVarOnDemand('SLACK_TOKEN'));
|
||||
});
|
||||
|
||||
tap.test('should send a message to Slack', async () => {
|
||||
testSlackMessage = new slackme.SlackMessage(
|
||||
{
|
||||
author_name: 'GitLab CI',
|
||||
author_link: 'https://gitlab.com/',
|
||||
pretext: '*Good News*: Build successfull!',
|
||||
color: '#3cb371',
|
||||
fields: [
|
||||
{
|
||||
title: 'Branch',
|
||||
value: 'Lossless Cloud',
|
||||
short: true
|
||||
},
|
||||
{
|
||||
title: 'Product ID',
|
||||
value: 'pushrocks',
|
||||
short: true
|
||||
}
|
||||
],
|
||||
ts: new Date().getTime() / 1000
|
||||
},
|
||||
testSlackme
|
||||
);
|
||||
testSlackme.sendMessage(testSlackMessage.messageOptions, 'random');
|
||||
testSlackMessage.sendToRoom('random');
|
||||
tap.test('should send a message to Slack', async tools => {
|
||||
const messageOptions = {
|
||||
author_name: 'GitLab CI',
|
||||
author_link: 'https://gitlab.com/',
|
||||
pretext: '*Good News*: Build successfull!',
|
||||
color: '#3cb371',
|
||||
fields: [
|
||||
{
|
||||
title: 'Branch',
|
||||
value: 'Lossless Cloud',
|
||||
short: true
|
||||
},
|
||||
{
|
||||
title: 'Product ID',
|
||||
value: 'pushrocks',
|
||||
short: true
|
||||
}
|
||||
]
|
||||
};
|
||||
await testSlackAccount.sendMessage({
|
||||
channelArg: 'random',
|
||||
messageOptions: messageOptions,
|
||||
mode: 'new'
|
||||
});
|
||||
});
|
||||
|
||||
tap.test('should send a message to Slack by directly calling the message', async tools => {
|
||||
testSlackMessage = new slackme.SlackMessage(testSlackAccount, {
|
||||
author_name: 'GitLab CI',
|
||||
author_link: 'https://gitlab.com/',
|
||||
pretext: '*Good News*: Build successfull!',
|
||||
color: '#3cb371',
|
||||
fields: [
|
||||
{
|
||||
title: 'Branch',
|
||||
value: 'Lossless Cloud',
|
||||
short: true
|
||||
},
|
||||
{
|
||||
title: 'Product ID',
|
||||
value: 'pushrocks',
|
||||
short: true
|
||||
}
|
||||
]
|
||||
});
|
||||
await testSlackMessage.sendToRoom('random');
|
||||
await tools.delayFor(1000);
|
||||
await testSlackMessage.updateAndSend({
|
||||
author_name: 'GitLab CI',
|
||||
author_link: 'https://gitlab.com/',
|
||||
pretext: '*Good News*: Build successfull!',
|
||||
color: '#3cb371',
|
||||
fields: [
|
||||
{
|
||||
title: 'Branch',
|
||||
value: 'Lossless Studio',
|
||||
short: true
|
||||
},
|
||||
{
|
||||
title: 'Product ID',
|
||||
value: 'pushrocks',
|
||||
short: true
|
||||
}
|
||||
]
|
||||
});
|
||||
await testSlackMessage.updateAndSend({
|
||||
author_name: 'GitLab CI',
|
||||
author_link: 'https://gitlab.com/',
|
||||
pretext: '*Good News*: Build successfull!',
|
||||
color: '#3cb371',
|
||||
fields: [
|
||||
{
|
||||
title: 'Branch',
|
||||
value: 'Lossless Studio',
|
||||
short: true
|
||||
},
|
||||
{
|
||||
title: 'Product ID',
|
||||
value: 'onboard.me',
|
||||
short: true
|
||||
}
|
||||
]
|
||||
});
|
||||
await testSlackMessage.startThread({
|
||||
author_name: 'Lossless Compliance',
|
||||
author_link: 'https://gitlab.com/',
|
||||
pretext: '*Good News*: Build successfull!',
|
||||
color: '#3cb371',
|
||||
fields: [
|
||||
{
|
||||
title: 'Branch',
|
||||
value: 'Lossless Studio',
|
||||
short: true
|
||||
},
|
||||
{
|
||||
title: 'Product ID',
|
||||
value: 'pushrocks',
|
||||
short: true
|
||||
}
|
||||
]
|
||||
});
|
||||
});
|
||||
|
||||
tap.test('should send logs', async () => {
|
||||
const slackLog = new slackme.SlackLog({
|
||||
slackAccount: testSlackAccount,
|
||||
channelName: 'random'
|
||||
});
|
||||
for (let i = 0; i < 30; i++) {
|
||||
await slackLog.sendLogLine('hi there');
|
||||
await slackLog.sendLogLine('so awesome');
|
||||
await slackLog.sendLogLine('really');
|
||||
}
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
@ -1,2 +1,3 @@
|
||||
export * from './slack.classes.slackme';
|
||||
export * from './slack.classes.slackaccount';
|
||||
export * from './slack.classes.slackmessage';
|
||||
export * from './slack.classes.slacklog';
|
||||
|
63
ts/slack.classes.slackaccount.ts
Normal file
63
ts/slack.classes.slackaccount.ts
Normal file
@ -0,0 +1,63 @@
|
||||
import * as plugins from './slack.plugins';
|
||||
import { IMessageOptions } from './slack.classes.slackmessage';
|
||||
|
||||
export class SlackAccount {
|
||||
private postUrl = 'https://slack.com/api/chat.postMessage';
|
||||
private updateUrl = 'https://slack.com/api/chat.update';
|
||||
private slackToken: string;
|
||||
constructor(slackTokenArg: string) {
|
||||
this.slackToken = slackTokenArg;
|
||||
}
|
||||
|
||||
async sendMessage(optionsArg: {
|
||||
messageOptions: IMessageOptions;
|
||||
channelArg: string;
|
||||
ts?: string;
|
||||
mode: 'new' | 'threaded' | 'update';
|
||||
}) {
|
||||
let requestBody: any = {
|
||||
channel: optionsArg.channelArg,
|
||||
text: optionsArg.messageOptions.text
|
||||
};
|
||||
|
||||
if (optionsArg.messageOptions.fields) {
|
||||
requestBody = {
|
||||
...requestBody,
|
||||
attachments: [
|
||||
{
|
||||
pretext: optionsArg.messageOptions.pretext,
|
||||
fields: optionsArg.messageOptions.fields,
|
||||
ts: optionsArg.messageOptions.ts,
|
||||
color: optionsArg.messageOptions.color
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
let postUrl = this.postUrl;
|
||||
|
||||
switch (true) {
|
||||
case optionsArg.ts && optionsArg.mode === 'update':
|
||||
requestBody = {
|
||||
...requestBody,
|
||||
ts: optionsArg.ts
|
||||
};
|
||||
postUrl = this.updateUrl;
|
||||
break;
|
||||
case optionsArg.ts && optionsArg.mode === 'threaded':
|
||||
requestBody = {
|
||||
...requestBody,
|
||||
thread_ts: optionsArg.ts
|
||||
};
|
||||
break;
|
||||
}
|
||||
|
||||
const response = await plugins.smartrequest.postJson(postUrl, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${this.slackToken}`
|
||||
},
|
||||
requestBody
|
||||
});
|
||||
return response;
|
||||
}
|
||||
}
|
29
ts/slack.classes.slacklog.ts
Normal file
29
ts/slack.classes.slacklog.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import { SlackAccount } from './slack.classes.slackaccount';
|
||||
import { SlackMessage } from './slack.classes.slackmessage';
|
||||
|
||||
export class SlackLog {
|
||||
public slackAccount: SlackAccount;
|
||||
public slackMessage: SlackMessage;
|
||||
public channelName: string;
|
||||
|
||||
public completeLog = ``;
|
||||
|
||||
constructor(optionsArg: { slackAccount: SlackAccount; channelName: string }) {
|
||||
this.slackAccount = optionsArg.slackAccount;
|
||||
this.channelName = optionsArg.channelName;
|
||||
}
|
||||
public async sendLogLine(logText: string) {
|
||||
if (!this.slackMessage) {
|
||||
this.slackMessage = new SlackMessage(this.slackAccount, {
|
||||
text: '``` log is loading... ```'
|
||||
});
|
||||
await this.slackMessage.sendToRoom(this.channelName);
|
||||
}
|
||||
const date = new Date();
|
||||
this.completeLog +=
|
||||
`${date.getHours()}:${date.getMinutes()}:${date.getSeconds()} - ` + logText + '\n';
|
||||
await this.slackMessage.updateAndSend({
|
||||
text: '```\n' + this.completeLog + '\n```'
|
||||
});
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
import * as plugins from './slack.plugins';
|
||||
import { IMessageOptions } from './slack.classes.slackmessage';
|
||||
|
||||
export class Slackme {
|
||||
private baseUrl = 'https://hooks.slack.com/services/';
|
||||
private postRoute: string;
|
||||
constructor(postRouteArg: string) {
|
||||
this.postRoute = postRouteArg;
|
||||
}
|
||||
|
||||
sendMessage(messageOptionsArg: IMessageOptions, channelArg: string = 'general') {
|
||||
plugins.smartrequest.post(`${this.baseUrl}${this.postRoute}`, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
requestBody: {
|
||||
channel: channelArg,
|
||||
attachments: [messageOptionsArg]
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
import * as plugins from './slack.plugins';
|
||||
import { Slackme } from './slack.classes.slackme';
|
||||
import { SlackAccount } from './slack.classes.slackaccount';
|
||||
|
||||
export interface IAttachmentField {
|
||||
title: string;
|
||||
@ -49,24 +49,50 @@ export interface IMessageOptions {
|
||||
thumb_url?: string;
|
||||
footer?: string;
|
||||
footer_icon?: string;
|
||||
/**
|
||||
* timestamp as epoch time
|
||||
*/
|
||||
ts?: number;
|
||||
}
|
||||
|
||||
export class SlackMessage {
|
||||
slackmeRef: Slackme;
|
||||
messageOptions: IMessageOptions;
|
||||
constructor(messageOptionsArg: IMessageOptions, slackmeArg?: Slackme) {
|
||||
if (slackmeArg) {
|
||||
this.slackmeRef = slackmeArg;
|
||||
public slackAccountRef: SlackAccount;
|
||||
public messageOptions: IMessageOptions;
|
||||
public channel: string;
|
||||
public ts: string;
|
||||
|
||||
public requestRunning = plugins.smartpromise.defer();
|
||||
|
||||
constructor(slackAccountArg: SlackAccount, messageOptionsArg: IMessageOptions) {
|
||||
if (slackAccountArg) {
|
||||
this.slackAccountRef = slackAccountArg;
|
||||
}
|
||||
this.messageOptions = messageOptionsArg;
|
||||
this.requestRunning.resolve();
|
||||
}
|
||||
sendToRoom(roomNameArg: string) {
|
||||
if (this.slackmeRef) {
|
||||
this.slackmeRef.sendMessage(this.messageOptions, roomNameArg);
|
||||
|
||||
async updateAndSend(messageOptionsArg: IMessageOptions) {
|
||||
this.messageOptions = messageOptionsArg;
|
||||
await this.sendToRoom(this.channel, 'update');
|
||||
}
|
||||
|
||||
async startThread(messageOptionsArg: IMessageOptions) {
|
||||
this.messageOptions = messageOptionsArg;
|
||||
this.sendToRoom(this.channel, 'threaded');
|
||||
}
|
||||
|
||||
async sendToRoom(channelNameArg: string, modeArg: 'new' | 'update' | 'threaded' = 'new') {
|
||||
this.channel = channelNameArg;
|
||||
if (this.slackAccountRef) {
|
||||
const response = await this.slackAccountRef.sendMessage({
|
||||
channelArg: this.channel,
|
||||
messageOptions: this.messageOptions,
|
||||
mode: modeArg,
|
||||
ts: this.ts
|
||||
});
|
||||
if (modeArg === 'new') {
|
||||
this.ts = response.body.message.ts;
|
||||
this.channel = response.body.channel;
|
||||
}
|
||||
} else {
|
||||
throw new Error('you need to set a slackRef before sending the message!');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
import * as smartrequest from 'smartrequest';
|
||||
// pushrocks scope
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
import * as smartrequest from '@pushrocks/smartrequest';
|
||||
|
||||
export { smartrequest };
|
||||
export { smartpromise, smartrequest };
|
||||
|
16
tslint.json
16
tslint.json
@ -1,3 +1,17 @@
|
||||
{
|
||||
"extends": "tslint-config-standard"
|
||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
||||
"rules": {
|
||||
"semicolon": [true, "always"],
|
||||
"no-console": false,
|
||||
"ordered-imports": false,
|
||||
"object-literal-sort-keys": false,
|
||||
"member-ordering": {
|
||||
"options":{
|
||||
"order": [
|
||||
"static-method"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"defaultSeverity": "warning"
|
||||
}
|
||||
|
Reference in New Issue
Block a user