Files
aio-01d4-stu/Last3Mon/70/answers/70-lab02-challenge-sms.json
T

309 lines
7.1 KiB
JSON
Raw Normal View History

{
"name": "answer · 70 Lab 02 challenge (SMS uses the module)",
"nodes": [
{
"name": "SMS webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
0,
300
],
"parameters": {
"httpMethod": "POST",
"path": "my-sms",
"responseMode": "responseNode",
"options": {}
}
},
{
"name": "Has facts?",
"type": "n8n-nodes-base.if",
"typeVersion": 2.2,
"position": [
200,
300
],
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict",
"version": 2
},
"conditions": [
{
"id": "c0",
"leftValue": "={{ $json.body.facts }}",
"rightValue": "",
"operator": {
"type": "string",
"operation": "notEmpty",
"singleValue": true
}
}
],
"combinator": "and"
},
"options": {}
}
},
{
"name": "Reject empty",
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1.1,
"position": [
420,
520
],
"parameters": {
"respondWith": "json",
"responseBody": "{ \"error\": \"facts are required\" }",
"options": {
"responseCode": 400
}
}
},
{
"name": "SMS agent",
"type": "@n8n/n8n-nodes-langchain.agent",
"typeVersion": 3.1,
"position": [
420,
300
],
"parameters": {
"promptType": "define",
"text": "=사실:\n{{ $('SMS webhook').first().json.body.facts }}",
"options": {
"systemMessage": "You write one Korean SMS (text message) from the facts only: at most 80 characters, one or two sentences. Copy every date and time exactly. No phone numbers, e-mail addresses or links. Return only the SMS text.",
"maxIterations": 2
}
}
},
{
"name": "OpenAI chat model",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"typeVersion": 1.2,
"position": [
380,
520
],
"parameters": {
"model": {
"__rl": true,
"mode": "id",
"value": "gpt-4.1-mini"
},
"options": {
"temperature": 0
}
},
"credentials": {
"openAiApi": {
"id": "openAiCourse0001",
"name": "OpenAI (.env)"
}
}
},
{
"name": "Build draft",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
640,
300
],
"parameters": {
"jsCode": "// The writer's text, without code fences.\nreturn [{ json: { draft: String($json.output ?? '').trim().replace(/^```\\w*\\s*|```$/g, '').trim() } }];"
}
},
{
"name": "Rule check module",
"type": "n8n-nodes-base.executeWorkflow",
"typeVersion": 1.2,
"position": [
860,
300
],
"parameters": {
"workflowId": {
"__rl": true,
"mode": "id",
"value": "modRuleCheck01"
},
"workflowInputs": {
"mappingMode": "defineBelow",
"value": {
"facts": "={{ $('SMS webhook').first().json.body.facts }}",
"draft": "={{ $json.draft }}",
"max_length": 80,
"required_phrases": "={{ [] }}"
},
"matchingColumns": [],
"schema": [
{
"id": "facts",
"displayName": "facts",
"required": false,
"defaultMatch": false,
"display": true,
"canBeUsedToMatch": true,
"type": "string",
"removed": false
},
{
"id": "draft",
"displayName": "draft",
"required": false,
"defaultMatch": false,
"display": true,
"canBeUsedToMatch": true,
"type": "string",
"removed": false
},
{
"id": "max_length",
"displayName": "max_length",
"required": false,
"defaultMatch": false,
"display": true,
"canBeUsedToMatch": true,
"type": "number",
"removed": false
},
{
"id": "required_phrases",
"displayName": "required_phrases",
"required": false,
"defaultMatch": false,
"display": true,
"canBeUsedToMatch": true,
"type": "array",
"removed": false
}
],
"attemptToConvertTypes": false,
"convertFieldsToString": true
},
"options": {}
}
},
{
"name": "Build result",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1080,
300
],
"parameters": {
"jsCode": "// The SMS contract: { sms, published, codes }.\nreturn [{ json: { sms: $('Build draft').first().json.draft, published: $json.passed === true, codes: $json.codes ?? [] } }];"
}
},
{
"name": "Send result",
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1.1,
"position": [
1300,
300
],
"parameters": {
"respondWith": "json",
"responseBody": "={{ $json }}",
"options": {}
}
}
],
"connections": {
"SMS webhook": {
"main": [
[
{
"node": "Has facts?",
"type": "main",
"index": 0
}
]
]
},
"Has facts?": {
"main": [
[
{
"node": "SMS agent",
"type": "main",
"index": 0
}
],
[
{
"node": "Reject empty",
"type": "main",
"index": 0
}
]
]
},
"OpenAI chat model": {
"ai_languageModel": [
[
{
"node": "SMS agent",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"SMS agent": {
"main": [
[
{
"node": "Build draft",
"type": "main",
"index": 0
}
]
]
},
"Build draft": {
"main": [
[
{
"node": "Rule check module",
"type": "main",
"index": 0
}
]
]
},
"Rule check module": {
"main": [
[
{
"node": "Build result",
"type": "main",
"index": 0
}
]
]
},
"Build result": {
"main": [
[
{
"node": "Send result",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
}
}