Skip to content

Commit

Permalink
fix: require channel to be set for api method
Browse files Browse the repository at this point in the history
  • Loading branch information
simenandre committed Feb 12, 2023
1 parent 45b7298 commit 7d512b6
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/methods/api.ts
@@ -1,4 +1,5 @@
import { WebClient } from '@slack/web-api';
import invariant from 'ts-invariant';
import { parseLog } from '../parse-log';
import type { LogEntry, SlackApiOptions, SlackMethod } from '../types';

Expand All @@ -11,9 +12,18 @@ export class SlackApiMethod implements SlackMethod {

async send(entry: LogEntry): Promise<void> {
const parsedLog = await parseLog(entry);

if (!parsedLog) {
return;
}

const channel = parsedLog.channel ?? this.config.defaultChannel;

invariant(channel, 'No channel provided for Slack API method.');

await this.client.chat.postMessage({
channel: this.config.defaultChannel ?? '',
...parsedLog,
channel,
});
}
}

0 comments on commit 7d512b6

Please sign in to comment.