{ "createdAt": "2025-04-03T04:56:41.542Z", "updatedAt": "2025-04-07T10:04:42.000Z", "id": "JrGxnBveuh26kpLw", "name": "fy_test", "active": false, "nodes": [ { "parameters": { "method": "POST", "url": "http://172.31.0.160/v1/completion-messages", "sendHeaders": true, "specifyHeaders": "json", "jsonHeaders": "{\n \"Authorization\": \"Bearer app-fxQiMsg03GrJCtwNfLRtnD4R\",\n \"Content-Type\": \"application/json\"\n}", "sendBody": true, "specifyBody": "json", "jsonBody": "={\n \"inputs\": {\"record_json\":\"{{JSON.stringify($json.text).replaceAll(/\"/g, '\\\\\"')}}\",\"language\":\"中文\"},\n \"response_mode\": \"blocking\",\n \"user\": \"sl_backend_twitter\"\n}", "options": {} }, "id": "874fc343-aab6-45e9-963d-6f09e323d218", "name": "translate_dify", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 1300, 280 ] }, { "parameters": { "jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\n//answer = \"```json{\\\"test1\\\":\\\"test\\\"}```\";\nfunction findAllIndexes(str, charToFind) {\n const regex = new RegExp(charToFind, 'g');\n let indexes = [];\n let result;\n while ((result = regex.exec(str)) !== null) {\n indexes.push(result.index);\n }\n return indexes;\n}\nfunction isValidJSON(str) {\n try {\n JSON.parse(str);\n return true;\n } catch (e) {\n return false;\n }\n}\nfunction autoCompleteJSON(str) {\n if (isValidJSON(str)) {\n return str;\n }\n if (!str.includes('\"}') || (str.includes('\"}') && !str.endsWith('\"}'))) {\n str = str.replaceAll(\"}\",\"\");\n }\n str = retainSingleOccurrence(str,'}');\n // console.log(str);\n let missing = '';\n if (!str.endsWith('\"}')) {\n if (str.endsWith('\"')) {\n missing += '}'\n }else{\n missing += '\"}'\n }\n }\n str = str+missing;\n // console.log(str);\n return str;\n}\nfunction retainSingleOccurrence(str, subStr) {\n // 检查字符串是否包含子字符串\n if (!str.includes(subStr)) {\n return str;\n }\n // 使用正则表达式删除多余的子字符串\n // 使用全局匹配标志 g 和正则表达式来匹配所有子字符串\n // 注意:这里假设子字符串不会与其他文本重叠\n const regex = new RegExp(`(${subStr})(?=.*${subStr})`, 'g');\n let result = str.replace(regex, '');\n return result;\n}\n// answer =$input.all()[0].json.data.outputs.result.answer;\nanswer =$input.all()[0].json.answer;\nindexes = findAllIndexes(answer,\"```\");\nanswer_str = '';\nif(indexes.length>0){\n answer_str = answer.slice(indexes[0]+7, indexes[1]);\n}else{\n answer_str = answer;\n}\nanswer_str = answer_str.replace(/\\s+/g, '');\nanswer_data_json = JSON.parse(autoCompleteJSON(answer_str));\nanswer_data = {};\nanswer_data[\"answer\"] = answer_data_json;\nconsole.log(answer_data_json);\nreturn answer_data;" }, "id": "d809825d-fcab-4728-ac24-114570e77466", "name": "get_transter_answer", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 1520, 280 ] }, { "parameters": { "jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nlet output_info = {};\nlet text_info = {};\ninfo = $('Webhook').item.json.body.info.replace(/https:\\/\\/[^\\s]+/g, '').replaceAll(/[ \\t\\n\\r]+/g, ' ');\n// console.log(info);\noutput_info['text'] = info;\nreturn output_info;" }, "id": "bb9f1fe7-817e-44b6-97ee-ce3550bb5cd0", "name": "get_info", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 1080, 280 ] }, { "parameters": { "operation": "executeQuery", "query": "CALL update_news_source_fy({{JSON.stringify($json.answer.toJsonString())}});", "options": {} }, "id": "69108b4b-1e4c-4288-9dd9-b80b3e960cf2", "name": "update_news", "type": "n8n-nodes-base.mySql", "typeVersion": 2.4, "position": [ 1740, 280 ], "credentials": { "mySql": { "id": "09oRI0DULmEzD9l8", "name": "SL-DB" } } }, { "parameters": { "httpMethod": "POST", "path": "twitter/search/fy/test", "authentication": "headerAuth", "options": { "allowedOrigins": "*", "rawBody": false } }, "id": "a3e091cd-f33f-48f3-a69d-e5ac0d68f158", "name": "Webhook", "type": "n8n-nodes-base.webhook", "typeVersion": 2, "position": [ 880, 280 ], "webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07", "credentials": { "httpHeaderAuth": { "id": "U87Wvnvu9oQ5Zapo", "name": "Header Auth account" } } } ], "connections": { "translate_dify": { "main": [ [ { "node": "get_transter_answer", "type": "main", "index": 0 } ] ] }, "get_transter_answer": { "main": [ [ { "node": "update_news", "type": "main", "index": 0 } ] ] }, "get_info": { "main": [ [ { "node": "translate_dify", "type": "main", "index": 0 } ] ] }, "Webhook": { "main": [ [ { "node": "get_info", "type": "main", "index": 0 } ] ] } }, "settings": { "executionOrder": "v1" }, "staticData": null, "meta": { "templateCredsSetupCompleted": true }, "pinData": {}, "versionId": "99f1033b-6aea-4d93-8c68-96f7edea2bab", "triggerCount": 0, "shared": [ { "createdAt": "2025-04-03T04:56:41.551Z", "updatedAt": "2025-04-03T04:56:41.551Z", "role": "workflow:owner", "workflowId": "JrGxnBveuh26kpLw", "projectId": "C7zKoCDdmGgzUqSW", "project": { "createdAt": "2024-08-23T06:31:21.275Z", "updatedAt": "2024-08-23T06:41:43.608Z", "id": "C7zKoCDdmGgzUqSW", "name": "周 卫 ", "type": "personal", "projectRelations": [ { "createdAt": "2024-08-23T06:31:21.275Z", "updatedAt": "2024-08-23T06:31:21.275Z", "role": "project:personalOwner", "userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882", "projectId": "C7zKoCDdmGgzUqSW", "user": { "createdAt": "2024-08-23T06:31:16.119Z", "updatedAt": "2025-03-19T06:19:26.514Z", "id": "3f0021b4-d0a7-4db6-af21-5ef829c47882", "email": "zhouwei@ssish.com", "firstName": "周", "lastName": "卫", "personalizationAnswers": { "companyType": "education", "role": "business-owner", "automationBeneficiary": "my-team", "companySize": "20-99", "reportedSource": "friend", "version": "v4", "personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z", "personalization_survey_n8n_version": "1.55.3" }, "settings": { "userActivated": true, "firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx", "userActivatedAt": 1725957335278, "npsSurvey": { "responded": true, "lastShownAt": 1742365155724 }, "isOnboarded": true }, "role": "global:owner", "disabled": false, "mfaEnabled": false, "isPending": false, "isOwner": true } } ] } } ], "tags": [] }