Skip to content

Commit 7d5d57d

Browse files
authored
feat: add Twitch action to fetch channel streams (#14)
1 parent e057fde commit 7d5d57d

File tree

2 files changed

+79
-1
lines changed

2 files changed

+79
-1
lines changed

nodes/Twitch/Twitch.node.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import {
2+
IDataObject,
3+
IExecuteFunctions,
4+
INodeType,
5+
INodeTypeDescription,
6+
} from 'n8n-workflow';
7+
8+
import { twitchApiRequest } from './GenericFunctions.js';
9+
10+
export class Twitch implements INodeType {
11+
description: INodeTypeDescription = {
12+
displayName: 'Twitch',
13+
name: 'twitch',
14+
icon: 'file:twitch.svg',
15+
group: ['transform'],
16+
version: 1,
17+
description: 'Interact with Twitch',
18+
defaults: {
19+
name: 'Twitch',
20+
},
21+
inputs: ['main'],
22+
outputs: ['main'],
23+
credentials: [
24+
{
25+
name: 'twitchApi',
26+
required: true,
27+
},
28+
],
29+
properties: [
30+
{
31+
displayName: 'Operation',
32+
name: 'operation',
33+
type: 'options',
34+
noDataExpression: true,
35+
default: 'getChannelStreams',
36+
options: [
37+
{
38+
name: 'Get Channel Streams',
39+
value: 'getChannelStreams',
40+
action: 'Get channel streams',
41+
},
42+
],
43+
},
44+
{
45+
displayName: 'Channel Name',
46+
name: 'channel_name',
47+
type: 'string',
48+
required: true,
49+
default: '',
50+
description: 'Name of the channel whose streams to retrieve',
51+
},
52+
],
53+
};
54+
55+
async execute(this: IExecuteFunctions) {
56+
const items = this.getInputData();
57+
const returnData: IDataObject[] = [];
58+
59+
for (let i = 0; i < items.length; i++) {
60+
const channelName = this.getNodeParameter('channel_name', i) as string;
61+
62+
const response = await twitchApiRequest.call(
63+
this,
64+
'GET',
65+
'/streams',
66+
{},
67+
{ user_login: channelName },
68+
);
69+
70+
if (Array.isArray(response.data)) {
71+
returnData.push(...response.data);
72+
}
73+
}
74+
75+
return [this.helpers.returnJsonArray(returnData)];
76+
}
77+
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
"dist/credentials/TwitchApi.credentials.js"
4949
],
5050
"nodes": [
51-
"dist/nodes/Twitch/TwitchTrigger.node.js"
51+
"dist/nodes/Twitch/TwitchTrigger.node.js",
52+
"dist/nodes/Twitch/Twitch.node.js"
5253
]
5354
},
5455
"devDependencies": {

0 commit comments

Comments
 (0)