slack/ts/slack.classes.slackme.ts

36 lines
991 B
TypeScript
Raw Normal View History

2018-09-15 20:23:05 +00:00
import * as plugins from './slack.plugins';
import { IMessageOptions } from './slack.classes.slackmessage';
export class Slackme {
2019-09-18 10:26:31 +00:00
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;
2018-09-15 20:23:05 +00:00
}
2019-09-18 10:26:31 +00:00
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
2018-09-15 20:23:05 +00:00
}
2019-09-18 10:26:31 +00:00
postUrl = this.updateUrl;
}
console.log(requestBody);
const response = await plugins.smartrequest.postJson(postUrl, {
headers: {
'Authorization': `Bearer ${this.slackToken}`
},
requestBody
2018-09-15 20:23:05 +00:00
});
2019-09-18 10:26:31 +00:00
console.log(response.body);
2019-09-08 17:37:13 +00:00
return response;
2018-09-15 20:23:05 +00:00
}
}