From 7d512b6a81a351d71c8cc4bfe46e1d1210d9d2ce Mon Sep 17 00:00:00 2001 From: "Simen A. W. Olsen" Date: Sun, 12 Feb 2023 01:35:13 +0100 Subject: [PATCH] fix: require channel to be set for api method --- src/methods/api.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/methods/api.ts b/src/methods/api.ts index 1a84940..6f85faa 100644 --- a/src/methods/api.ts +++ b/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'; @@ -11,9 +12,18 @@ export class SlackApiMethod implements SlackMethod { async send(entry: LogEntry): Promise { 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, }); } }