{ "createdAt": "2025-02-13T05:12:09.233Z", "updatedAt": "2025-02-13T05:12:28.000Z", "id": "ayzMOr3NuwyzSudK", "name": "test_twitter", "active": true, "nodes": [ { "parameters": { "operation": "executeQuery", "query": "select location from schedule a where a.id = {{$('Webhook').item.json.body.schedule_id}};\n", "options": {} }, "id": "6e86c67c-9c7a-4c51-9785-23db8d4b1e45", "name": "get_location", "type": "n8n-nodes-base.mySql", "typeVersion": 2.4, "position": [ 160, 840 ], "credentials": { "mySql": { "id": "09oRI0DULmEzD9l8", "name": "SL-DB" } } }, { "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 = JSON.parse($('Webhook').item.json.body.info).full_text.replace(/https:\\/\\/[^\\s]+/g, '').replaceAll(/[ \\t\\n\\r]+/g, ' ').replaceAll(\"\\\"\", '” ');\nconsole.log(info);\nuser_id = JSON.parse($('Webhook').item.json.body.info).id;\ntext_info['full_text'] = info;\noutput_info['text'] = JSON.stringify(text_info);\noutput_info['msg_info'] = info;\noutput_info['user_id'] = user_id;\nreturn output_info;" }, "id": "b0d081ec-6b7a-4191-bf79-d8b929000012", "name": "get_info", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ -220, 360 ] }, { "parameters": { "operation": "executeQuery", "query": "CALL insert_news_source({{ (JSON.stringify($json.data))}},{{ JSON.stringify(JSON.stringify($json.label_data)) }},{{ JSON.stringify(JSON.stringify($json.artificial_label_data)) }});", "options": {} }, "id": "d2a882c0-83cb-499b-bfb9-fc186ee42491", "name": "insert_city_news", "type": "n8n-nodes-base.mySql", "typeVersion": 2.4, "position": [ 920, 820 ], "credentials": { "mySql": { "id": "09oRI0DULmEzD9l8", "name": "SL-DB" } } }, { "parameters": { "jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\ncontent_all = {};\nfor(let item_index =0; item_index < result_data.length;item_index++){\n item_data = result_data[item_index].json;\n if('location' in item_data){\n content_all['location'] = item_data['location'];\n }else if('label_data' in item_data){\n content_all['label'] = item_data['label_data'];\n }else if('artificial_label_data' in item_data){\n content_all['artificial_label'] = item_data['artificial_label_data'];\n }\n};\nconsole.log(content_all);\nlocation_data_list = JSON.parse(content_all.location);\ninfo_data_list = JSON.parse($('Webhook').all()[0].json.body.info);\nschedule_id = $('Webhook').all()[0].json.body.schedule_id;\nlabel_data_list = content_all.label;\nartificial_label_data_list = content_all.artificial_label;\nif(artificial_label_data_list.length>0 && location_data_list.length>0){\n artificial_label_data_list[0]['city_code'] = location_data_list[0].cityCode;\n}\ninfo_data_list['full_text'] = info_data_list.full_text.replace(/https:\\/\\/[^\\s]+/g, '');\ntranster_answer_data = $('get_transter_answer').all()[0].json.answer.full_text;\ninfo_data_list['full_text_ch'] = transter_answer_data;\noutput_all = [];\noutput_all_data = {};\noutput_news_data_str = \"\";\noutput_news_url_data_str = \"\";\noutput_news_label_data_str = \"\";\nfull_text_new = info_data_list.full_text.replace(/'/g, \"’\").replace(/\"/g, \"”\");\nfull_text_ch_new = info_data_list.full_text_ch.replace(/'/g, \"’\").replace(/\"/g, \"”\");\nnews_item_data = \"\";\nnews_item_data = news_item_data+\"(\";\nnews_item_data += \"'\"+full_text_new+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+full_text_ch_new+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.url+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.name+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.screen_name+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.profile_image_url+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'0'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.favourite_count+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.retweet_count+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.view_count+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'zh_cn'\";\nnews_item_data += ',';\nnews_item_data += 'STR_TO_DATE(\\''+info_data_list.created_at+'\\',\\'%Y-%m-%d %H:%i:%s\\')';\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.id+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+schedule_id+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'twitter'\";\nnews_item_data += ',';\nnews_item_data += \"'1'\";\nnews_item_data += ')';\nfor (let i = 0; i < location_data_list.length; i++) {\n city_code = location_data_list[i].cityCode;\n item_data = \"(\";\n item_data += \"'\"+city_code+\"'\";\n item_data += ',';\n item_data += '@last_insert_id';\n item_data += '),';\n output_news_data_str += item_data;\n};\nimages_url = info_data_list.images_url;\nvideos_url = info_data_list.videos_url;\nfunction isEmptyString(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value || value.trim() == '' || value.trim() == 'null' || value.trim() == 'None') {\n return true;\n }\n return false;\n};\nfor (let i = 0; i < images_url.length; i++) {\n image_url_data = images_url[i];\n original_url = image_url_data.original_url;\n thumbnail_url = image_url_data.thumbnail_url;\n if(isEmptyString(original_url) && isEmptyString(thumbnail_url)){\n continue;\n }else{\n image_item_data = \"(\";\n image_item_data += \"'\"+original_url+\"'\";\n image_item_data += ',';\n if(isEmptyString(thumbnail_url)){\n image_item_data += null;\n }else{\n image_item_data += \"'\"+thumbnail_url+\"'\";\n }\n image_item_data += ',';\n image_item_data += '0';\n image_item_data += ',';\n image_item_data += '@last_insert_id';\n image_item_data += '),';\n output_news_url_data_str += image_item_data;\n }\n};\nfor (let i = 0; i < videos_url.length; i++) {\n video_url = videos_url[i];\n video_item_data = \"(\";\n video_item_data += \"'\"+video_url+\"'\";\n video_item_data += ',';\n video_item_data += null;\n video_item_data += ',';\n video_item_data += '2';\n video_item_data += ',';\n video_item_data += '@last_insert_id';\n video_item_data += '),';\n output_news_url_data_str += video_item_data;\n};\nif(output_news_url_data_str.length == 0){\n output_news_url_data_str = \"('','','',''),\"\n}\noutput_all_data['city_data'] = output_news_data_str.slice(0,output_news_data_str.length-1);\noutput_all_data['urls_data'] = output_news_url_data_str.slice(0,output_news_url_data_str.length-1);\noutput_all_data['news_data'] = news_item_data;\noutput_all_data['news_id'] = info_data_list.id;\noutput_all_data_temp = {};\noutput_all_data_temp['data'] = JSON.stringify(output_all_data);\noutput_all_data_temp['label_data'] = label_data_list;\noutput_all_data_temp['artificial_label_data'] = artificial_label_data_list;\noutput_all.push(output_all_data_temp);\nreturn output_all;" }, "id": "074bdda0-c3e3-4f51-b6bc-532c742292cf", "name": "get_city_news_sql", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 660, 820 ] }, { "parameters": { "operation": "executeQuery", "query": "update news_source set likes = {{ JSON.parse( $('Webhook').item.json.body.info).favourite_count }} ,forward = {{ JSON.parse( $('Webhook').item.json.body.info).retweet_count }},hot = {{ JSON.parse( $('Webhook').item.json.body.info).view_count }} where news_uid = {{ JSON.stringify(JSON.parse( $('Webhook').item.json.body.info).id) }}\n", "options": {} }, "id": "85817c35-b2ce-4872-8479-4548a5e2b276", "name": "update_city_news", "type": "n8n-nodes-base.mySql", "typeVersion": 2.4, "position": [ 160, 1300 ], "credentials": { "mySql": { "id": "09oRI0DULmEzD9l8", "name": "SL-DB" } } }, { "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict" }, "conditions": [ { "id": "a1541edc-9637-4ac2-83a6-902ee9d29af6", "leftValue": "={{ $json.count.toString() }}", "rightValue": "=0", "operator": { "type": "string", "operation": "equals" } } ], "combinator": "and" }, "options": {} }, "id": "dc70a167-aef7-4ade-85c6-a26cb2b290e7", "name": "insert_or_update", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [ -500, 860 ] }, { "parameters": { "operation": "executeQuery", "query": "select IFNULL(count(id), 0) as count from news_source where news_uid ={{JSON.stringify(JSON.parse($json.body.info).id) }};\n", "options": {} }, "id": "ceb1f94f-10dc-47f2-b6fe-c84e2c98bc44", "name": "is_exists_news", "type": "n8n-nodes-base.mySql", "typeVersion": 2.4, "position": [ -740, 860 ], "alwaysOutputData": false, "credentials": { "mySql": { "id": "09oRI0DULmEzD9l8", "name": "SL-DB" } } }, { "parameters": { "method": "POST", "url": "http://172.31.0.160/v1/completion-messages", "sendHeaders": true, "specifyHeaders": "json", "jsonHeaders": "{\n \"Authorization\": \"Bearer app-KRXKS2lXohYjnIKmuYxSncem\",\n \"Content-Type\": \"application/json\"\n}", "sendBody": true, "specifyBody": "json", "jsonBody": "={\n \"inputs\": {\"record_json\":\"{{$json.text.replaceAll(/\"/g, '\\\\\"')}}\",\"language\":\"中文\"},\n \"response_mode\": \"blocking\",\n \"user\": \"sl_backend_twitter\"\n}", "options": {} }, "id": "6145fdcb-90cc-40a6-9977-5ffa984fceb1", "name": "translate_dify", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ -40, 360 ] }, { "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 isEmptyString(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value || value.trim() === '') {\n return true;\n }\n return false;\n};\nfunction isEmpty(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value) {\n return true;\n }\n return false;\n};\nlabel_data_list = [];\nartificial_label_data_list = [];\nlabel_data_arr = $input.all();\nlabel_result_list = [];\nartificial_label_result_list = [];\nfor(var label_index=0;label_index0){\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;\nreturn answer_data;" }, "id": "d8a587f3-5d55-4619-837d-41f0f24a94b0", "name": "get_transter_answer", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 140, 360 ] }, { "parameters": { "method": "POST", "url": "http://172.31.0.160/v1/workflows/run", "sendHeaders": true, "specifyHeaders": "json", "jsonHeaders": "{\n \"Authorization\": \"Bearer app-SRHXAMF0iYxuCJD5cnHYgtJZ\",\n \"Content-Type\": \"application/json\"\n}", "sendBody": true, "specifyBody": "json", "jsonBody": "={\n \"inputs\": {\"msg_info\":\"{{$('get_info').item.json.msg_info.replaceAll(/\"/g, '\\\\\"')}}\"},\n \"response_mode\": \"blocking\",\n \"user\": \"sl_backend_twitter\"\n}", "options": {} }, "id": "12c6c784-94fc-4c8b-9244-1366ce52e2af", "name": "natural_label_dify", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 400, 480 ] }, { "parameters": { "method": "POST", "url": "http://172.31.0.160/v1/workflows/run", "sendHeaders": true, "specifyHeaders": "json", "jsonHeaders": "{\n \"Authorization\": \"Bearer app-HCbsiZmUCzP8Vdqb2meKXQSb\",\n \"Content-Type\": \"application/json\"\n}", "sendBody": true, "specifyBody": "json", "jsonBody": "={\n \"inputs\": {\"msg_info\":\"{{$json.answer.full_text.replaceAll(/\"/g, '\\\\\"')}}\"},\n \"response_mode\": \"blocking\",\n \"user\": \"sl_backend_twitter\"\n}", "options": {} }, "id": "876be9b2-24ea-4166-bdcc-6acaed3f9697", "name": "artificial_label_dify", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 400, 280 ] }, { "parameters": { "httpMethod": "POST", "path": "twitter/translate/ch/test", "authentication": "headerAuth", "options": { "allowedOrigins": "*", "rawBody": false } }, "id": "9eaddc81-9c24-4aef-9ce8-7e4542b55b8b", "name": "Webhook", "type": "n8n-nodes-base.webhook", "typeVersion": 2, "position": [ -1000, 860 ], "webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07", "credentials": { "httpHeaderAuth": { "id": "1fHtEpWRIg2mFYBe", "name": "Header Auth account" } } }, { "parameters": {}, "id": "d8e717bd-263c-4ab3-9b55-c644b99a81ee", "name": "merge_label", "type": "n8n-nodes-base.merge", "typeVersion": 3, "position": [ 620, 380 ] }, { "parameters": {}, "id": "23a95c09-ccca-439a-b7d2-e6b3c99e4d42", "name": "get_answer_location", "type": "n8n-nodes-base.merge", "typeVersion": 3, "position": [ 400, 820 ] }, { "parameters": { "operation": "executeQuery", "query": "select location from schedule a where a.id = {{$('Webhook').item.json.body.schedule_id}};\n", "options": {} }, "id": "2c58ed5a-e5b6-4b29-9d54-eb3ff6cdbf21", "name": "get_city_code", "type": "n8n-nodes-base.mySql", "typeVersion": 2.4, "position": [ 160, 1080 ], "credentials": { "mySql": { "id": "09oRI0DULmEzD9l8", "name": "SL-DB" } } }, { "parameters": { "jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\ncontent_all = {};\nfor(let item_index =0; item_index < result_data.length;item_index++){\n item_data = result_data[item_index].json;\n if('location' in item_data){\n content_all['location'] = item_data['location'];\n }\n};\nlocation_data_list = JSON.parse(content_all.location);\ninfo_data_list = JSON.parse($('Webhook').all()[0].json.body.info);\noutput_news_data_str = '';\noutput_all_data = {};\noutput_all = [];\noutput_city_code_list = [];\nfor (let i = 0; i < location_data_list.length; i++) {\n city_code = location_data_list[i].cityCode;\n output_city_code_list.push(city_code);\n};\noutput_all_data['city_code'] = output_city_code_list;\noutput_all_data['news_id'] = info_data_list.id;\noutput_all.push(output_all_data);\nconsole.log(output_all);\nreturn output_all;" }, "id": "20594f0b-7af8-4009-b86b-8e5850947c7a", "name": "get_city_code_info", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 400, 1080 ] }, { "parameters": { "operation": "executeQuery", "query": "CALL insert_news_city({{ JSON.stringify(JSON.stringify($json.city_code))}},{{ JSON.stringify(JSON.stringify($json.news_id)) }});", "options": {} }, "id": "8417d3d8-1afb-4c15-9bd5-68a9ceeba588", "name": "insert_city_data", "type": "n8n-nodes-base.mySql", "typeVersion": 2.4, "position": [ 660, 1080 ], "credentials": { "mySql": { "id": "09oRI0DULmEzD9l8", "name": "SL-DB" } } } ], "connections": { "get_location": { "main": [ [ { "node": "get_answer_location", "type": "main", "index": 1 } ] ] }, "get_info": { "main": [ [ { "node": "translate_dify", "type": "main", "index": 0 } ] ] }, "get_city_news_sql": { "main": [ [ { "node": "insert_city_news", "type": "main", "index": 0 } ] ] }, "insert_or_update": { "main": [ [ { "node": "get_info", "type": "main", "index": 0 }, { "node": "get_location", "type": "main", "index": 0 } ], [ { "node": "get_city_code", "type": "main", "index": 0 }, { "node": "update_city_news", "type": "main", "index": 0 } ] ] }, "is_exists_news": { "main": [ [ { "node": "insert_or_update", "type": "main", "index": 0 } ] ] }, "translate_dify": { "main": [ [ { "node": "get_transter_answer", "type": "main", "index": 0 } ] ] }, "get_label_answer": { "main": [ [ { "node": "get_answer_location", "type": "main", "index": 0 } ] ] }, "get_transter_answer": { "main": [ [ { "node": "artificial_label_dify", "type": "main", "index": 0 }, { "node": "natural_label_dify", "type": "main", "index": 0 } ] ] }, "natural_label_dify": { "main": [ [ { "node": "merge_label", "type": "main", "index": 1 } ] ] }, "artificial_label_dify": { "main": [ [ { "node": "merge_label", "type": "main", "index": 0 } ] ] }, "Webhook": { "main": [ [ { "node": "is_exists_news", "type": "main", "index": 0 } ] ] }, "merge_label": { "main": [ [ { "node": "get_label_answer", "type": "main", "index": 0 } ] ] }, "get_answer_location": { "main": [ [ { "node": "get_city_news_sql", "type": "main", "index": 0 } ] ] }, "get_city_code": { "main": [ [ { "node": "get_city_code_info", "type": "main", "index": 0 } ] ] }, "get_city_code_info": { "main": [ [ { "node": "insert_city_data", "type": "main", "index": 0 } ] ] } }, "settings": { "executionOrder": "v1" }, "staticData": null, "meta": null, "pinData": null, "versionId": "f445181e-bbd7-4bb6-998a-4a31f0638554", "triggerCount": 1, "shared": [ { "createdAt": "2025-02-13T05:12:09.240Z", "updatedAt": "2025-02-13T05:12:09.240Z", "role": "workflow:owner", "workflowId": "ayzMOr3NuwyzSudK", "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": [] }