slack/ts/slack.classes.slackme.ts
2019-09-18 12:27:52 +02:00

34 lines
929 B
TypeScript

import * as plugins from './slack.plugins';
import { IMessageOptions } from './slack.classes.slackmessage';
export class Slackme {
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(messageOptionsArg: IMessageOptions, channelArg: string = 'status', tsArg?: string) {
let requestBody: any = {
channel: channelArg,
attachments: [messageOptionsArg]
}
let postUrl = this.postUrl;
if (tsArg) {
requestBody = {
...requestBody,
ts: tsArg
}
postUrl = this.updateUrl;
}
const response = await plugins.smartrequest.postJson(postUrl, {
headers: {
'Authorization': `Bearer ${this.slackToken}`
},
requestBody
});
return response;
}
}