Skip to content

Commit c175e0f

Browse files
committed
[ACTION] Freshdesk - Canned Responses
1 parent 983cb96 commit c175e0f

File tree

5 files changed

+48
-39
lines changed

5 files changed

+48
-39
lines changed

components/freshdesk/actions/get-canned-response/get-canned-response.mjs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,19 @@ export default {
1313
},
1414
props: {
1515
freshdesk,
16+
cannedResponseFolderId: {
17+
propDefinition: [
18+
freshdesk,
19+
"cannedResponseFolderId",
20+
],
21+
},
1622
cannedResponseId: {
1723
propDefinition: [
1824
freshdesk,
1925
"cannedResponseId",
26+
({ cannedResponseFolderId }) => ({
27+
cannedResponseFolderId,
28+
}),
2029
],
2130
},
2231
},
@@ -29,7 +38,7 @@ export default {
2938
$,
3039
cannedResponseId,
3140
});
32-
response && $.export("$summary", `Successfully retrieved canned response: ${response.title}`);
41+
$.export("$summary", `Successfully retrieved canned response with ID \`${response.id}\``);
3342
return response;
3443
},
3544
};

components/freshdesk/actions/get-folder-canned-responses/get-folder-canned-responses.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import freshdesk from "../../freshdesk.app.mjs";
22

33
export default {
44
key: "freshdesk-get-folder-canned-responses",
5-
name: "Get Canned Responses in a Folder",
5+
name: "Get Canned Responses In A Folder",
66
description: "View all the details of canned responses in a folder. [See the documentation](https://developers.freshdesk.com/api/#get_details_of_canned_responses_in_a_folder)",
77
version: "0.0.1",
88
annotations: {
@@ -37,7 +37,7 @@ export default {
3737
folderId: cannedResponseFolderId,
3838
},
3939
});
40-
$.export("$summary", `Successfully retrieved ${responses.length} canned response(s) from folder`);
40+
$.export("$summary", `Successfully retrieved \`${responses.length}\` canned response(s) from folder`);
4141
return responses;
4242
},
4343
};

components/freshdesk/actions/list-all-folders/list-all-folders.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default {
2929
max: maxResults,
3030
args: {},
3131
});
32-
$.export("$summary", `Successfully retrieved ${folders.length} folder(s)`);
32+
$.export("$summary", `Successfully retrieved \`${folders.length}\` folder(s)`);
3333
return folders;
3434
},
3535
};

components/freshdesk/actions/list-folder-canned-responses/list-folder-canned-responses.mjs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import freshdesk from "../../freshdesk.app.mjs";
22

33
export default {
44
key: "freshdesk-list-folder-canned-responses",
5-
name: "List All Canned Responses in a Folder",
5+
name: "List All Canned Responses In A Folder",
66
description: "View all canned responses in a folder. [See the documentation](https://developers.freshdesk.com/api/#list_all_canned_responses_in_a_folder)",
77
version: "0.0.1",
88
annotations: {
@@ -22,14 +22,15 @@ export default {
2222
},
2323
async run({ $ }) {
2424
const {
25-
freshdesk, cannedResponseFolderId,
25+
freshdesk,
26+
cannedResponseFolderId,
2627
} = this;
27-
const response = await freshdesk.listFolderCannedResponses({
28+
const response = await freshdesk.listCannedResponses({
2829
$,
29-
folderId: cannedResponseFolderId,
30+
cannedResponseFolderId,
3031
});
3132
const responseCount = response?.canned_responses?.length || 0;
32-
$.export("$summary", `Successfully retrieved folder with ${responseCount} canned response(s)`);
33+
$.export("$summary", `Successfully retrieved \`${responseCount}\` canned response(s) from folder`);
3334
return response;
3435
},
3536
};

components/freshdesk/freshdesk.app.mjs

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -281,38 +281,42 @@ export default {
281281
return threads.map(({ id }) => id);
282282
},
283283
},
284-
cannedResponseId: {
284+
cannedResponseFolderId: {
285285
type: "integer",
286-
label: "Canned Response ID",
287-
description: "The ID of a canned response",
286+
label: "Canned Response Folder ID",
287+
description: "The ID of a canned response folder",
288288
async options({ page = 0 }) {
289-
const responses = await this.listAllCannedResponses({
289+
const folders = await this.listCannedResponseFolders({
290290
params: {
291291
page: page + 1,
292292
},
293293
});
294-
return responses.map(({
295-
id, title,
294+
return folders.map(({
295+
id, name,
296296
}) => ({
297-
label: title || id,
297+
label: name || id,
298298
value: id,
299299
}));
300300
},
301301
},
302-
cannedResponseFolderId: {
302+
cannedResponseId: {
303303
type: "integer",
304-
label: "Canned Response Folder ID",
305-
description: "The ID of a canned response folder",
306-
async options({ page = 0 }) {
307-
const folders = await this.listCannedResponseFolders({
304+
label: "Canned Response ID",
305+
description: "The ID of a canned response",
306+
async options({
307+
page = 0,
308+
cannedResponseFolderId,
309+
}) {
310+
const { canned_responses: responses } = await this.listCannedResponses({
311+
cannedResponseFolderId,
308312
params: {
309313
page: page + 1,
310314
},
311315
});
312-
return folders.map(({
313-
id, name,
316+
return responses.map(({
317+
id, title,
314318
}) => ({
315-
label: name || id,
319+
label: title || id,
316320
value: id,
317321
}));
318322
},
@@ -345,6 +349,7 @@ export default {
345349
$ = this, headers, ...args
346350
}) {
347351
return axios($, {
352+
debug: true,
348353
baseURL: `https://${this._getDomain()}/api/v2`,
349354
headers: this._getHeaders(headers),
350355
...args,
@@ -767,31 +772,25 @@ export default {
767772
...args,
768773
});
769774
},
770-
getCannedResponse({
771-
cannedResponseId, ...args
772-
}) {
773-
return this._makeRequest({
774-
url: `/canned_responses/${cannedResponseId}`,
775-
...args,
776-
});
777-
},
778-
listAllCannedResponses(args) {
775+
listCannedResponseFolders(args) {
779776
return this._makeRequest({
780-
url: "/canned_responses",
777+
url: "/canned_response_folders",
781778
...args,
782779
});
783780
},
784-
listCannedResponseFolders(args) {
781+
listCannedResponses({
782+
cannedResponseFolderId, ...args
783+
}) {
785784
return this._makeRequest({
786-
url: "/canned_response_folders",
785+
url: `/canned_response_folders/${cannedResponseFolderId}`,
787786
...args,
788787
});
789788
},
790-
listFolderCannedResponses({
791-
folderId, ...args
789+
getCannedResponse({
790+
cannedResponseId, ...args
792791
}) {
793792
return this._makeRequest({
794-
url: `/canned_response_folders/${folderId}`,
793+
url: `/canned_responses/${cannedResponseId}`,
795794
...args,
796795
});
797796
},

0 commit comments

Comments
 (0)