2024-01-24 22:53:06 +00:00
|
|
|
import * as plugins from './slack.plugins.js';
|
|
|
|
import {} from './slack.classes.slackmessage.js';
|
|
|
|
export class SlackAccount {
|
2021-07-23 11:53:33 +00:00
|
|
|
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) {
|
2024-01-24 22:53:06 +00:00
|
|
|
requestBody = {
|
|
|
|
...requestBody,
|
|
|
|
attachments: [
|
2021-07-23 11:53:33 +00:00
|
|
|
{
|
|
|
|
pretext: optionsArg.messageOptions.pretext,
|
|
|
|
fields: optionsArg.messageOptions.fields,
|
|
|
|
ts: optionsArg.messageOptions.ts,
|
|
|
|
color: optionsArg.messageOptions.color
|
|
|
|
}
|
2024-01-24 22:53:06 +00:00
|
|
|
]
|
|
|
|
};
|
2021-07-23 11:53:33 +00:00
|
|
|
}
|
|
|
|
let postUrl = this.postUrl;
|
|
|
|
switch (true) {
|
|
|
|
case optionsArg.ts && optionsArg.mode === 'update':
|
2024-01-24 22:53:06 +00:00
|
|
|
requestBody = {
|
|
|
|
...requestBody,
|
|
|
|
ts: optionsArg.ts
|
|
|
|
};
|
2021-07-23 11:53:33 +00:00
|
|
|
postUrl = this.updateUrl;
|
|
|
|
break;
|
|
|
|
case optionsArg.ts && optionsArg.mode === 'threaded':
|
2024-01-24 22:53:06 +00:00
|
|
|
requestBody = {
|
|
|
|
...requestBody,
|
|
|
|
thread_ts: optionsArg.ts
|
|
|
|
};
|
2021-07-23 11:53:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
const response = await plugins.smartrequest.postJson(postUrl, {
|
|
|
|
headers: {
|
|
|
|
Authorization: `Bearer ${this.slackToken}`
|
|
|
|
},
|
|
|
|
requestBody
|
|
|
|
});
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
}
|
2024-01-24 22:53:06 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2xhY2suY2xhc3Nlcy5zbGFja2FjY291bnQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbGFjay5jbGFzc2VzLnNsYWNrYWNjb3VudC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssT0FBTyxNQUFNLG9CQUFvQixDQUFDO0FBQzlDLE9BQU8sRUFBd0IsTUFBTSxpQ0FBaUMsQ0FBQztBQUV2RSxNQUFNLE9BQU8sWUFBWTtJQUl2QixZQUFZLGFBQXFCO1FBSHpCLFlBQU8sR0FBRyx3Q0FBd0MsQ0FBQztRQUNuRCxjQUFTLEdBQUcsbUNBQW1DLENBQUM7UUFHdEQsSUFBSSxDQUFDLFVBQVUsR0FBRyxhQUFhLENBQUM7SUFDbEMsQ0FBQztJQUVELEtBQUssQ0FBQyxXQUFXLENBQUMsVUFLakI7UUFDQyxJQUFJLFdBQVcsR0FBUTtZQUNyQixPQUFPLEVBQUUsVUFBVSxDQUFDLFVBQVU7WUFDOUIsSUFBSSxFQUFFLFVBQVUsQ0FBQyxjQUFjLENBQUMsSUFBSTtTQUNyQyxDQUFDO1FBRUYsSUFBSSxVQUFVLENBQUMsY0FBYyxDQUFDLE1BQU0sRUFBRSxDQUFDO1lBQ3JDLFdBQVcsR0FBRztnQkFDWixHQUFHLFdBQVc7Z0JBQ2QsV0FBVyxFQUFFO29CQUNYO3dCQUNFLE9BQU8sRUFBRSxVQUFVLENBQUMsY0FBYyxDQUFDLE9BQU87d0JBQzFDLE1BQU0sRUFBRSxVQUFVLENBQUMsY0FBYyxDQUFDLE1BQU07d0JBQ3hDLEVBQUUsR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