1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
| {
"name": "Twitter Tweet A
nalyzer",
"nodes": [
{
"parameters": {
"formTitle": "Tweet Analyzer",
"formFields": {
"values": [
{
"fieldLabel": "Tweet URL",
"placeholder": "https://x.com/username/status/1234567890",
"requiredField": true
}
]
},
"options": {}
},
"type": "n8n-nodes-base.formTrigger",
"typeVersion": 2.2,
"position": [
-480,
100
],
"id": "a7fa3440-aa5d-42aa-a3b4-417b3975a8aa",
"name": "On form submission",
"webhookId": "791ad1b4-eee4-4d00-97c6-5b0852c78ae2"
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict",
"version": 2
},
"conditions": [
{
"id": "21171dd5-e8d4-4264-8332-274b585dd8e2",
"leftValue": "={{ $json['Tweet URL'] }}",
"rightValue": "^https?:\\/\\/(www\\.)?(twitter|x)\\.com\\/.+\\/status\\/\\d+",
"operator": {
"type": "string",
"operation": "regex"
}
}
],
"combinator": "and"
},
"options": {}
},
"type": "n8n-nodes-base.if",
"typeVersion": 2.2,
"position": [
-240,
100
],
"id": "f6dc641a-abe9-43c0-aac6-e68724b7784c",
"name": "If"
},
{
"parameters": {
"promptType": "define",
"text": "=You are a professional political and social media analyst who always responds in a specific JSON format.\n\nYour task is to analyze the following tweet replies and generate a structured, professional report.\n\nTweet Replies to Analyze:\n\n{{ $json.replyText }}\n\nInstructions for the Report Content:\nThe report should be written in Markdown and help the author understand how their message was received. Base all insights on the actual content and language used in the replies.\n\nThe Markdown report must follow this structure:\n\nExecutive Summary: A one-paragraph summary of the overall reception (sentiment, surprises, tone).\n\nSentiment Breakdown: Approximate percentages (positive/neutral/negative), characteristics of each group, and representative examples.\n\nNarrative Analysis: 3–5 recurring narratives, each with a description, quotes, and a note on whether it's organic or strategic.\n\nInfluential or Viral Replies: 3–5 standout replies with an explanation of their impact.\n\nAudience Insight: Analysis of audience expectations, misunderstandings, and perceptions.\n\nStrategic Observations: Suggestions for improvement, timing factors, and signals of pushback.\n\nFinal Output Format:\nYour entire response MUST be a single, valid JSON object. Do not include any text before or after the JSON. The JSON object must have a single key named report_text, where the value is the complete Markdown report you generated.\n\nEXAMPLE OF THE REQUIRED OUTPUT STRUCTURE:\n\n\n{\n \"report_text\": \"# Full Sentiment & Narrative Report\\n\\n## 1. Executive Summary\\nOverall, the tweet received a polarized response, with strong support from one segment of the audience and significant criticism from another. The tone was largely passionate, with very few neutral replies.\\n\\n## 2. Sentiment Breakdown\\n- **Positive: 45%** - Supporters focused on the policy's benefits, using words like \\\"commonsense\\\" and \\\"necessary.\\\"\\n- **Negative: 55%** - Critics raised concerns about unintended consequences and government overreach.\"\n}",
"options": {}
},
"type": "@n8n/n8n-nodes-langchain.agent",
"typeVersion": 1.9,
"position": [
780,
0
],
"id": "c7b57c7b-1e5a-4aae-bff4-0c5787daf0c0",
"name": "AI Agent"
},
{
"parameters": {
"jsCode": "// Get the JSON string from the AI output and parse it into a real object.\nconst parsedData = JSON.parse($input.first().json.output);\n\n// Now, access the 'report_text' key from the parsed object.\nconst fullReport = parsedData.report_text;\n\n// Check if the report text exists.\nif (!fullReport) {\n throw new Error(\"The key 'report_text' was not found in the AI's JSON output after parsing. Please ensure the AI prompt correctly instructs the model to use this key.\");\n}\n\n// --- Helper function to extract content for a specific section ---\n// This robust function remains the same.\nfunction extractSection(text, title) {\n // Use a case-insensitive regex that handles various markdown headings (##, ###) and optional numbering.\n const regex = new RegExp(\n `^##+\\\\s*(?:\\\\d+\\\\.\\\\s*)?${title}\\\\s*\\\\n([\\\\s\\\\S]*?)(?=^##+|$)`,\n 'gmi'\n );\n const match = regex.exec(text);\n return match ? match[1].trim() : `Section \"${title}\" not found`;\n}\n\n// --- Define the sections you want to extract ---\nconst executiveSummary = extractSection(fullReport, 'Executive Summary');\nconst sentimentBreakdown = extractSection(fullReport, 'Sentiment Breakdown');\nconst narrativeAnalysis = extractSection(fullReport, 'Narrative Analysis');\nconst influentialReplies = extractSection(fullReport, 'Influential or Viral Replies');\nconst audienceInsight = extractSection(fullReport, 'Audience Insight');\nconst strategicObservations = extractSection(fullReport, 'Strategic Observations');\n\n// --- Return the data ---\nreturn {\n executiveSummary,\n sentimentBreakdown,\n narrativeAnalysis,\n influentialReplies,\n audienceInsight,\n strategicObservations\n};"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1140,
0
],
"id": "78e50b0d-db3d-409b-a2cf-cd10cd202304",
"name": "Code2"
},
{
"parameters": {
"operation": "appendOrUpdate",
"documentId": {
"__rl": true,
"value": "11mUAWW8fkQVfNSHT68IytC0Slw-DRbeLhdn8Ztvyg5k",
"mode": "list",
"cachedResultName": "Tweet Analyzer",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/11mUAWW8fkQVfNSHT68IytC0Slw-DRbeLhdn8Ztvyg5k/edit?usp=drivesdk"
},
"sheetName": {
"__rl": true,
"value": "gid=0",
"mode": "list",
"cachedResultName": "Sheet1",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/11mUAWW8fkQVfNSHT68IytC0Slw-DRbeLhdn8Ztvyg5k/edit#gid=0"
},
"columns": {
"mappingMode": "defineBelow",
"value": {
"Executive Summary": "={{ $json.executiveSummary }}",
"Sentiment Breakdown": "={{ $json.sentimentBreakdown }}",
"Narrative Analysis": "={{ $json.narrativeAnalysis }}",
"Influential Replies": "={{ $json.influentialReplies }}",
"Audience Insight": "={{ $json.audienceInsight }}",
"Strategic Observations": "={{ $json.strategicObservations }}",
"Tweet URL": "={{ $('On form submission').item.json['Tweet URL'] }}"
},
"matchingColumns": [
"Tweet URL"
],
"schema": [
{
"id": "Tweet URL",
"displayName": "Tweet URL",
"required": false,
"defaultMatch": false,
"display": true,
"type": "string",
"canBeUsedToMatch": true,
"removed": false
},
{
"id": "Executive Summary",
"displayName": "Executive Summary",
"required": false,
"defaultMatch": false,
"display": true,
"type": "string",
"canBeUsedToMatch": true
},
{
"id": "Sentiment Breakdown",
"displayName": "Sentiment Breakdown",
"required": false,
"defaultMatch": false,
"display": true,
"type": "string",
"canBeUsedToMatch": true
},
{
"id": "Narrative Analysis",
"displayName": "Narrative Analysis",
"required": false,
"defaultMatch": false,
"display": true,
"type": "string",
"canBeUsedToMatch": true
},
{
"id": "Influential Replies",
"displayName": "Influential Replies",
"required": false,
"defaultMatch": false,
"display": true,
"type": "string",
"canBeUsedToMatch": true
},
{
"id": "Audience Insight",
"displayName": "Audience Insight",
"required": false,
"defaultMatch": false,
"display": true,
"type": "string",
"canBeUsedToMatch": true
},
{
"id": "Strategic Observations",
"displayName": "Strategic Observations",
"required": false,
"defaultMatch": false,
"display": true,
"type": "string",
"canBeUsedToMatch": true
}
],
"attemptToConvertTypes": false,
"convertFieldsToString": false
},
"options": {}
},
"type": "n8n-nodes-base.googleSheets",
"typeVersion": 4.5,
"position": [
1400,
0
],
"id": "9644be77-2708-4867-ae12-910258cd92e0",
"name": "Google Sheets"
},
{
"parameters": {
"operation": "completion",
"respondWith": "showText",
"responseText": "Incorrect tweet URL, please re-run the workflow"
},
"type": "n8n-nodes-base.form",
"typeVersion": 1,
"position": [
80,
280
],
"id": "38fd5a3d-1e1e-4c49-b6a6-bdf97983bf47",
"name": "Incorrect Form URL",
"webhookId": "7c8d5f22-ee5d-4f2b-8952-90037207ac41"
},
{
"parameters": {
"operation": "completion",
"completionTitle": "Tweet Processing",
"options": {}
},
"type": "n8n-nodes-base.form",
"typeVersion": 1,
"position": [
0,
0
],
"id": "5f3ffb31-8cf6-4a46-a342-7ec3a48cd099",
"name": "Successful Form Submission",
"webhookId": "9e9ff477-7710-43fe-a4a9-fab2ddf34b3a"
},
{
"parameters": {
"method": "POST",
"url": "APIFY URL",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"includeNestedReplies\": false,\n \"postUrls\": [\n \"{{ $json['Tweet URL'] }}\"\n ],\n \"resultsLimit\": 5\n}",
"options": {}
},
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
280,
0
],
"id": "d83c0630-8d3f-457a-bf50-cf41298de0c6",
"name": "HTTP Request1"
},
{
"parameters": {
"fieldsToAggregate": {
"fieldToAggregate": [
{
"fieldToAggregate": "replyText"
}
]
},
"options": {}
},
"type": "n8n-nodes-base.aggregate",
"typeVersion": 1,
"position": [
520,
0
],
"id": "bb6ec4ba-954e-4cfe-bf42-ef7bd7632f65",
"name": "Aggregate"
},
{
"parameters": {
"model": "deepseek/deepseek-r1:free",
"options": {}
},
"type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
"typeVersion": 1,
"position": [
680,
300
],
"id": "fb99e727-f3af-4f5b-9541-73008caeb329",
"name": "OpenRouter Chat Model"
}
],
"pinData": {},
"connections": {
"On form submission": {
"main": [
[
{
"node": "If",
"type": "main",
"index": 0
}
]
]
},
"If": {
"main": [
[
{
"node": "Successful Form Submission",
"type": "main",
"index": 0
}
],
[
{
"node": "Incorrect Form URL",
"type": "main",
"index": 0
}
]
]
},
"AI Agent": {
"main": [
[
{
"node": "Code2",
"type": "main",
"index": 0
}
]
]
},
"Code2": {
"main": [
[
{
"node": "Google Sheets",
"type": "main",
"index": 0
}
]
]
},
"Successful Form Submission": {
"main": [
[
{
"node": "HTTP Request1",
"type": "main",
"index": 0
}
]
]
},
"HTTP Request1": {
"main": [
[
{
"node": "Aggregate",
"type": "main",
"index": 0
}
]
]
},
"Aggregate": {
"main": [
[
{
"node": "AI Agent",
"type": "main",
"index": 0
}
]
]
},
"OpenRouter Chat Model": {
"ai_languageModel": [
[
{
"node": "AI Agent",
"type": "ai_languageModel",
"index": 0
}
]
]
}
},
"active": false,
"settings": {
"executionOrder": "v1"
},
"versionId": "6aa4f295-a9b8-4f6c-97c2-705b49ec4c46",
"meta": {
"instanceId": "bf63e2f51dbc3f9b426b65f04f21e6baece93c635479343f7aa1d53bce881f40"
},
"id": "tIVoDRAsAfDr3LAF",
"tags": []
}
|