Skip to content

Commit df604c4

Browse files
author
Echo
committed
fix(mattermost): merge commands config + be lenient on DM channel lookup
1 parent 48b0d2d commit df604c4

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

extensions/mattermost/src/mattermost/accounts.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,21 @@ function mergeMattermostAccountConfig(
6565
const { accounts: _ignored, ...base } = (cfg.channels?.mattermost ??
6666
{}) as MattermostAccountConfig & { accounts?: unknown };
6767
const account = resolveAccountConfig(cfg, accountId) ?? {};
68-
return { ...base, ...account };
68+
69+
// Shallow merging is fine for most keys, but `commands` should be merged
70+
// so that account-specific overrides (callbackPath/callbackUrl) do not
71+
// accidentally reset global settings like `native: true`.
72+
const mergedCommands = {
73+
...(base.commands ?? {}),
74+
...(account.commands ?? {}),
75+
};
76+
77+
const merged = { ...base, ...account };
78+
if (Object.keys(mergedCommands).length > 0) {
79+
merged.commands = mergedCommands;
80+
}
81+
82+
return merged;
6983
}
7084

7185
function resolveMattermostRequireMention(config: MattermostAccountConfig): boolean | undefined {

extensions/mattermost/src/mattermost/slash-http.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,13 @@ async function authorizeSlashInvocation(params: {
146146

147147
const channelType = channelInfo?.type ?? undefined;
148148
const isDirectMessage = channelType?.toUpperCase() === "D";
149-
const kind = isDirectMessage
149+
const kind: SlashInvocationAuth["kind"] = isDirectMessage
150150
? "direct"
151-
: channelType?.toUpperCase() === "G"
152-
? "group"
153-
: "channel";
151+
: channelInfo
152+
? channelType?.toUpperCase() === "G"
153+
? "group"
154+
: "channel"
155+
: "direct";
154156

155157
const chatType = kind === "direct" ? "direct" : kind === "group" ? "group" : "channel";
156158

0 commit comments

Comments
 (0)