feat(Update the way SlackMessage works and create a proper readme):

This commit is contained in:
2018-01-10 21:45:25 +01:00
parent 2b34315495
commit 2eae91d9e0
15 changed files with 293 additions and 267 deletions

View File

@ -1,33 +1,2 @@
import * as plugins from './slackme.plugins'
import { SlackMessage } from './slackme.classes.slackmessage'
export interface ISlackmeMessage {
message: string,
author: string,
}
export {
SlackMessage
}
export class Slackme {
private baseUrl = 'https://hooks.slack.com/services/'
private postRoute: string
constructor (postRouteArg: string) {
this.postRoute = postRouteArg
}
sendMessage(messageArg: SlackMessage, channelArg: string = 'general') {
plugins.smartrequest.post(`${this.baseUrl}${this.postRoute}`,{
headers: {
'Content-Type': 'application/json'
},
requestBody: {
channel: channelArg,
attachments: [
messageArg.messageOptions
]
}
})
}
}
export * from './slackme.classes.slackme'
export * from './slackme.classes.slackmessage'

View File

@ -0,0 +1,24 @@
import * as plugins from './slackme.plugins'
import { IMessageOptions } from './slackme.classes.slackmessage'
export class Slackme {
private baseUrl = 'https://hooks.slack.com/services/'
private postRoute: string
constructor (postRouteArg: string) {
this.postRoute = postRouteArg
}
sendMessage(messageOptionsArg: IMessageOptions, channelArg: string = 'general') {
plugins.smartrequest.post(`${this.baseUrl}${this.postRoute}`,{
headers: {
'Content-Type': 'application/json'
},
requestBody: {
channel: channelArg,
attachments: [
messageOptionsArg
]
}
})
}
}

View File

@ -1,4 +1,5 @@
import * as plugins from './slackme.plugins'
import { Slackme } from './slackme.classes.slackme'
export interface IAttachmentField {
title: string
@ -55,8 +56,17 @@ export interface IMessageOptions {
}
export class SlackMessage {
slackmeRef: Slackme
messageOptions: IMessageOptions
constructor(messageOptions: IMessageOptions) {
this.messageOptions = messageOptions
constructor(messageOptionsArg: IMessageOptions, slackmeArg?: Slackme) {
if (slackmeArg) {
this.slackmeRef = slackmeArg
}
this.messageOptions = messageOptionsArg
}
sendToRoom(roomNameArg: string) {
if(this.slackmeRef) {
this.slackmeRef.sendMessage(this.messageOptions, roomNameArg)
}
}
}

View File

@ -1,5 +1,3 @@
import 'typings-global'
import * as smartrequest from 'smartrequest'
export {