2018-09-15 20:23:05 +00:00
|
|
|
import * as plugins from './slack.plugins';
|
|
|
|
import { Slackme } from './slack.classes.slackme';
|
2017-09-17 12:53:00 +00:00
|
|
|
|
2017-09-17 13:25:00 +00:00
|
|
|
export interface IAttachmentField {
|
2018-09-15 20:23:05 +00:00
|
|
|
title: string;
|
|
|
|
value: string;
|
|
|
|
short?: boolean;
|
2017-09-17 13:25:00 +00:00
|
|
|
}
|
|
|
|
|
2017-09-17 12:53:00 +00:00
|
|
|
export interface IMessageOptions {
|
|
|
|
/**
|
|
|
|
* "Required plain-text summary of the attachment."
|
|
|
|
*/
|
2018-09-15 20:23:05 +00:00
|
|
|
fallback?: string;
|
2017-09-17 12:53:00 +00:00
|
|
|
/**
|
|
|
|
* a side color
|
|
|
|
*/
|
2018-09-15 20:23:05 +00:00
|
|
|
color?: string;
|
2017-09-17 12:53:00 +00:00
|
|
|
/**
|
|
|
|
* a message to show above
|
|
|
|
*/
|
2018-09-15 20:23:05 +00:00
|
|
|
pretext?: string;
|
2017-09-17 13:25:00 +00:00
|
|
|
/**
|
|
|
|
* author name of the attachment
|
|
|
|
*/
|
2018-09-15 20:23:05 +00:00
|
|
|
author_name?: string;
|
2017-09-17 13:25:00 +00:00
|
|
|
/**
|
|
|
|
* a link to the author
|
|
|
|
*/
|
2018-09-15 20:23:05 +00:00
|
|
|
author_link?: string;
|
2017-09-17 13:25:00 +00:00
|
|
|
/**
|
|
|
|
* a string to the author
|
|
|
|
*/
|
2018-09-15 20:23:05 +00:00
|
|
|
author_icon?: string;
|
2017-09-17 13:25:00 +00:00
|
|
|
/**
|
|
|
|
* a title for the attachment
|
|
|
|
*/
|
2018-09-15 20:23:05 +00:00
|
|
|
title?: string;
|
2017-09-17 13:25:00 +00:00
|
|
|
/**
|
|
|
|
* a link for the title
|
|
|
|
*/
|
2018-09-15 20:23:05 +00:00
|
|
|
title_link?: string;
|
2017-09-17 12:53:00 +00:00
|
|
|
/**
|
|
|
|
* the main text of the message
|
|
|
|
*/
|
2018-09-15 20:23:05 +00:00
|
|
|
text?: string;
|
|
|
|
fields?: IAttachmentField[];
|
|
|
|
image_url?: string;
|
|
|
|
thumb_url?: string;
|
|
|
|
footer?: string;
|
|
|
|
footer_icon?: string;
|
2017-09-17 12:53:00 +00:00
|
|
|
/**
|
|
|
|
* timestamp as epoch time
|
|
|
|
*/
|
2018-09-15 20:23:05 +00:00
|
|
|
ts?: number;
|
2017-09-17 12:53:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export class SlackMessage {
|
2018-09-15 20:23:05 +00:00
|
|
|
slackmeRef: Slackme;
|
|
|
|
messageOptions: IMessageOptions;
|
2018-01-10 20:45:25 +00:00
|
|
|
constructor(messageOptionsArg: IMessageOptions, slackmeArg?: Slackme) {
|
|
|
|
if (slackmeArg) {
|
2018-09-15 20:23:05 +00:00
|
|
|
this.slackmeRef = slackmeArg;
|
2018-01-10 20:45:25 +00:00
|
|
|
}
|
2018-09-15 20:23:05 +00:00
|
|
|
this.messageOptions = messageOptionsArg;
|
2018-01-10 20:45:25 +00:00
|
|
|
}
|
2019-09-05 11:08:42 +00:00
|
|
|
async sendToRoom(roomNameArg: string) {
|
2018-09-15 20:23:05 +00:00
|
|
|
if (this.slackmeRef) {
|
2019-09-05 11:08:42 +00:00
|
|
|
await this.slackmeRef.sendMessage(this.messageOptions, roomNameArg);
|
|
|
|
} else {
|
|
|
|
throw new Error('you need to set a slackRef before sending the message!');
|
2018-01-10 20:45:25 +00:00
|
|
|
}
|
2017-09-17 12:53:00 +00:00
|
|
|
}
|
|
|
|
}
|