{ "kind": "open-flow-workflow", "version": 1, "name": "Check Whether a Twitch Stream Is Live", "content": { "modelVersion": 14, "document": { "bindings": {}, "graph": { "nodes": { "n_c2a8a81a8f11f9f2": { "name": "Enter a Twitch login", "kind": "start", "inputDefs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "login" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "clientId" } ] }, "n_8570a73316df5e78": { "inputs": { "login": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_c2a8a81a8f11f9f2", "output": "login" } ] }, "clientId": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_c2a8a81a8f11f9f2", "output": "clientId" } ] } }, "name": "Prepare the lookup", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "login" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "clientId" } ], "outputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "url" }, { "jsonSchema": { "type": "object", "additionalProperties": { "type": "string" } }, "nullable": false, "handle": "headers" } ], "name": "Prepare the lookup", "moduleId": "n_a47e5c799d0b1012", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_0bfadd0fc736856f": { "inputs": { "url": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_8570a73316df5e78", "output": "url" } ] }, "headers": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_8570a73316df5e78", "output": "headers" } ] }, "auth.token": { "kind": "unset" } }, "name": "Look up the stream", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "url" }, { "jsonSchema": { "type": "object", "additionalProperties": { "type": "string" } }, "nullable": true, "handle": "headers" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "auth.token" } ], "outputs": [ { "jsonSchema": {}, "nullable": true, "handle": "body" }, { "jsonSchema": { "type": "integer" }, "nullable": false, "handle": "statusCode" }, { "jsonSchema": { "type": "object", "additionalProperties": { "type": "string" } }, "nullable": false, "handle": "headers" } ], "name": "Look up the stream", "executor": { "method": "GET", "query": { "mode": "fields", "names": [] }, "headers": { "mode": "object", "names": [] }, "bodyFormat": "none", "authentication": { "type": "bearer" }, "responseFormat": "json", "statusPolicy": "success", "kind": "http-request" } } }, "n_fbd1e3c4902929b9": { "inputs": { "response": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_0bfadd0fc736856f", "output": "body" } ] } }, "name": "Interpret the result", "kind": "task", "task": { "inputs": [ { "jsonSchema": {}, "nullable": true, "handle": "response" } ], "outputs": [ { "jsonSchema": { "type": "boolean" }, "nullable": false, "handle": "online" }, { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": true, "handle": "stream" } ], "name": "Interpret the result", "moduleId": "n_d9b1e5536a7a39e4", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_00697c1949258ecb": { "name": "Stream status", "kind": "outputs", "outputDefs": [ { "jsonSchema": { "type": "boolean" }, "nullable": false, "handle": "online" }, { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": true, "handle": "stream" } ], "outputMappings": { "online": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_fbd1e3c4902929b9", "output": "online" } ] }, "stream": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_fbd1e3c4902929b9", "output": "stream" } ] } } } }, "edges": [ { "source": "n_c2a8a81a8f11f9f2", "target": "n_8570a73316df5e78" }, { "source": "n_8570a73316df5e78", "target": "n_0bfadd0fc736856f" }, { "source": "n_0bfadd0fc736856f", "target": "n_fbd1e3c4902929b9" }, { "source": "n_fbd1e3c4902929b9", "target": "n_00697c1949258ecb" } ] } }, "modules": { "n_a47e5c799d0b1012": { "name": "Prepare the lookup", "imports": [], "source": "export default function prepare({login,clientId}){if(!login.trim()||!clientId.trim())throw Error('Enter a Twitch login and client ID');return{url:'https://api.twitch.tv/helix/streams?user_login='+encodeURIComponent(login.trim()),headers:{'Client-Id':clientId.trim()}}}\n" }, "n_d9b1e5536a7a39e4": { "name": "Interpret the result", "imports": [], "source": "export default function normalize({response}){if(!response||!Array.isArray(response.data)||response.data.length>1)throw Error('Unexpected Twitch response');const x=response.data[0];if(!x)return{online:false,stream:null};if(typeof x.id!=='string'||typeof x.viewer_count!=='number'||typeof x.title!=='string'||typeof x.type!=='string'||typeof x.game_id!=='string')throw Error('Unexpected Twitch stream');return{online:true,stream:{id:x.id,viewersCount:x.viewer_count,title:x.title,type:x.type,game:x.game_id?{id:x.game_id}:null}}}\n" } } }, "presentation": { "designer": { "version": 1, "flow": { "direction": "vertical" } } } }