Skip to content

Commit d4e83d6

Browse files
committed
fix: return the channel id from methods that return it as channel.id
1 parent 1c1e442 commit d4e83d6

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

src/client.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,19 @@ export default class Client {
5454
});
5555
try {
5656
/**
57-
* @type {webapi.WebAPICallResult & MessageResult=}
57+
* @type {webapi.WebAPICallResult & import("@slack/web-api").ChatPostMessageResponse & import("@slack/web-api").ConversationsCreateResponse}
5858
*/
5959
const response = await client.apiCall(
6060
config.inputs.method,
6161
config.content.values,
6262
);
6363
config.core.setOutput("ok", response.ok);
6464
config.core.setOutput("response", JSON.stringify(response));
65-
if (response.channel) {
66-
config.core.setOutput("channel_id", response.channel);
65+
if (response.channel?.id ?? response.channel) {
66+
config.core.setOutput(
67+
"channel_id",
68+
response.channel?.id ?? response.channel,
69+
);
6770
}
6871
if (response.message?.thread_ts) {
6972
config.core.setOutput("thread_ts", response.message.thread_ts);

test/client.spec.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,44 @@ describe("client", () => {
107107
}
108108
});
109109

110+
it("calls 'conversations.create' with the given token and content", async () => {
111+
try {
112+
const args = {
113+
name: "pull-request-review-010101",
114+
};
115+
const response = {
116+
ok: true,
117+
channel: {
118+
id: "C0101010101",
119+
name: "pull-request-review-010101",
120+
is_channel: true,
121+
created: 1730425428,
122+
},
123+
};
124+
mocks.core.getInput.withArgs("method").returns("chat.postMessage");
125+
mocks.core.getInput.withArgs("token").returns("xoxb-example");
126+
mocks.core.getInput.withArgs("payload").returns(JSON.stringify(args));
127+
mocks.api.resolves(response);
128+
await send(mocks.core);
129+
assert.deepEqual(mocks.api.getCall(0).firstArg, "chat.postMessage");
130+
assert.deepEqual(mocks.api.getCall(0).lastArg, args);
131+
assert.equal(mocks.core.setOutput.getCall(0).firstArg, "ok");
132+
assert.equal(mocks.core.setOutput.getCall(0).lastArg, true);
133+
assert.equal(mocks.core.setOutput.getCall(1).firstArg, "response");
134+
assert.equal(
135+
mocks.core.setOutput.getCall(1).lastArg,
136+
JSON.stringify(response),
137+
);
138+
assert.equal(mocks.core.setOutput.getCall(2).firstArg, "channel_id");
139+
assert.equal(mocks.core.setOutput.getCall(2).lastArg, "C0101010101");
140+
assert.equal(mocks.core.setOutput.getCall(3).firstArg, "time");
141+
assert.equal(mocks.core.setOutput.getCalls().length, 4);
142+
} catch (error) {
143+
console.error(error);
144+
assert.fail("Unexpected error when calling the method");
145+
}
146+
});
147+
110148
it("calls 'files.uploadV2' with the provided token and content", async () => {
111149
try {
112150
const args = {

0 commit comments

Comments
 (0)