fix(core): update
This commit is contained in:
@ -1,2 +1,2 @@
|
||||
export * from './slack.classes.slackme';
|
||||
export * from './slack.classes.slackaccount';
|
||||
export * from './slack.classes.slackmessage';
|
||||
|
47
ts/slack.classes.slackaccount.ts
Normal file
47
ts/slack.classes.slackaccount.ts
Normal file
@ -0,0 +1,47 @@
|
||||
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: {
|
||||
messageOptionsArg: IMessageOptions;
|
||||
channelArg: string;
|
||||
ts?: string;
|
||||
mode: 'new' | 'threaded' | 'update';
|
||||
}) {
|
||||
let requestBody: any = {
|
||||
channel: optionsArg.channelArg,
|
||||
attachments: [optionsArg.messageOptionsArg]
|
||||
};
|
||||
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
|
||||
|
||||
}
|
||||
}
|
||||
const response = await plugins.smartrequest.postJson(postUrl, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${this.slackToken}`
|
||||
},
|
||||
requestBody
|
||||
});
|
||||
return response;
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
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(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;
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
import * as plugins from './slack.plugins';
|
||||
import { SlackAccount } from './slack.classes.slackme';
|
||||
import { SlackAccount } from './slack.classes.slackaccount';
|
||||
|
||||
export interface IAttachmentField {
|
||||
title: string;
|
||||
@ -66,13 +66,23 @@ export class SlackMessage {
|
||||
|
||||
async updateAndSend(messageOptionsArg: IMessageOptions) {
|
||||
this.messageOptions = messageOptionsArg;
|
||||
await this.sendToRoom(this.channel);
|
||||
await this.sendToRoom(this.channel, 'update');
|
||||
}
|
||||
|
||||
async sendToRoom(roomNameArg: string) {
|
||||
this.channel = roomNameArg;
|
||||
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.slackmeRef) {
|
||||
const response = await this.slackmeRef.sendMessage(this.messageOptions, roomNameArg, this.ts);
|
||||
const response = await this.slackmeRef.sendMessage({
|
||||
channelArg: this.channel,
|
||||
messageOptionsArg: this.messageOptions,
|
||||
mode: modeArg,
|
||||
ts: this.ts
|
||||
});
|
||||
this.ts = response.body.message.ts;
|
||||
this.channel = response.body.channel;
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user