112 lines
2.6 KiB
JSON
112 lines
2.6 KiB
JSON
{
|
|
"name": "Telegram Assistant - AI Chat",
|
|
"nodes": [
|
|
{
|
|
"parameters": {
|
|
"httpMethod": "POST",
|
|
"path": "4e0e30c5-2360-49e5-a37c-e2558f811341",
|
|
"responseMode": "responseNode",
|
|
"options": {}
|
|
},
|
|
"id": "webhook-ai-1",
|
|
"name": "Webhook",
|
|
"type": "n8n-nodes-base.webhook",
|
|
"typeVersion": 1,
|
|
"position": [
|
|
240,
|
|
300
|
|
],
|
|
"webhookId": "4e0e30c5-2360-49e5-a37c-e2558f811341"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"method": "POST",
|
|
"url": "https://api.openai.com/v1/chat/completions",
|
|
"authentication": "predefinedCredentialType",
|
|
"nodeCredentialType": "openAiApi",
|
|
"sendBody": true,
|
|
"specifyBody": "json",
|
|
"jsonBody": "={\n \"model\": \"gpt-4o-mini\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"{{ $json.body.args }}\"\n }\n ],\n \"temperature\": 0.7,\n \"max_tokens\": 500\n}",
|
|
"options": {}
|
|
},
|
|
"id": "call-openai-1",
|
|
"name": "Call OpenAI",
|
|
"type": "n8n-nodes-base.httpRequest",
|
|
"typeVersion": 3,
|
|
"position": [
|
|
460,
|
|
300
|
|
],
|
|
"credentials": {
|
|
"openAiApi": {
|
|
"id": "openai_api_key",
|
|
"name": "OpenAI API Key"
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"parameters": {
|
|
"mode": "runOnceForEachItem",
|
|
"jsCode": "const aiResponse = $input.item.json.choices[0].message.content;\nconst chatId = $input.item.json.body.chatId;\n\nreturn {\n chatId: chatId,\n text: aiResponse,\n parseMode: 'Markdown'\n};"
|
|
},
|
|
"id": "format-response-1",
|
|
"name": "Format Response",
|
|
"type": "n8n-nodes-base.code",
|
|
"typeVersion": 2,
|
|
"position": [
|
|
680,
|
|
300
|
|
]
|
|
},
|
|
{
|
|
"parameters": {
|
|
"respondWith": "json",
|
|
"responseBody": "={{ JSON.stringify($json) }}"
|
|
},
|
|
"id": "respond-1",
|
|
"name": "Respond",
|
|
"type": "n8n-nodes-base.respondToWebhook",
|
|
"typeVersion": 1,
|
|
"position": [
|
|
900,
|
|
300
|
|
]
|
|
}
|
|
],
|
|
"connections": {
|
|
"Webhook": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Call OpenAI",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Call OpenAI": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Format Response",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Format Response": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Respond",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
}
|
|
},
|
|
"settings": {}
|
|
} |