Skip to content

Commit

Permalink
feat: support github.com/bjerkio/nestjs-slack@v1
Browse files Browse the repository at this point in the history
  • Loading branch information
simenandre committed Aug 30, 2021
1 parent de2cde7 commit 4c0a3b0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
32 changes: 28 additions & 4 deletions src/methods/api.ts
Expand Up @@ -17,9 +17,33 @@ export class SlackApiMethod implements SlackMethod {
return;
}

await this.client.chat.postMessage({
channel: this.config.defaultChannel,
text: entry.jsonPayload?.message ?? entry.textPayload,
});
if (
entry.operation?.producer === 'github.com/bjerkio/nestjs-slack@v1' &&
typeof entry.jsonPayload?.message !== 'string'
) {
await this.client.chat.postMessage({
channel: this.config.defaultChannel,
...entry.jsonPayload.message.slack,
});
return;
}

if (
entry.jsonPayload?.message &&
typeof entry.jsonPayload?.message === 'string'
) {
await this.client.chat.postMessage({
channel: this.config.defaultChannel,
text: entry.jsonPayload?.message,
});
return;
}

if (entry.textPayload) {
await this.client.chat.postMessage({
channel: this.config.defaultChannel,
text: entry.textPayload,
});
}
}
}
13 changes: 12 additions & 1 deletion src/types.ts
Expand Up @@ -72,13 +72,24 @@ export const LogEntry = rt.Record({
rt.Literal('ALERT'),
rt.Literal('EMERGENCY'),
),
operation: rt.Dictionary(rt.String, rt.String).optional(),

textPayload: rt.String.optional(),
jsonPayload: rt
.Record({
slack: rt.Guard((x): x is SlackMessageRequest => true),
})
.And(rt.Record({ message: rt.String }).asPartial())
.And(
rt
.Record({
message: rt.String.Or(
rt.Record({
slack: rt.Guard((x): x is SlackMessageRequest => true),
}),
),
})
.asPartial(),
)
.And(rt.Unknown)
.optional(),
});
Expand Down

0 comments on commit 4c0a3b0

Please sign in to comment.