docs: add Telegram & n8n automation guide

This commit is contained in:
mstfyldz
2026-08-16 17:32:30 +03:00
parent e374fd3639
commit 9a3a9f4421
+220
View File
@@ -0,0 +1,220 @@
# 🤖 Telegram & n8n ile Otomatik Not Ekleme Rehberi
Bu rehber, Telegram üzerinden tek bir mesaj atarak `mstfyldz journal` defterinize doğrudan yeni notlar, fikirler, kod parçaları veya polaroid görseller eklemenizi sağlayan **n8n otomasyon mimarisini** açıklar.
---
## 🎯 Mimari Genel Bakış
```
[ Telegram Mesajı ]
▼ (BotFather Webhook)
[ n8n Telegram Trigger ]
▼ (Güvenlik Kontrolü: Yalnızca Sizin Chat ID'niz)
[ n8n Code / AI Node ] ────► (Format, Mood ve Etiketleri Otomatik Algılar)
▼ (HTTP Request Node)
[ POST https://mstfyldz.com/api/posts ] ───► [ PostgreSQL DB ]
▼ (Onay Mesajı)
[ Telegram Bot Cevabı ] ────► "✅ Not Deftere Karalandı!"
```
---
## 📋 Ön Gereksinimler
1. **Telegram Bot Token:** `@BotFather` üzerinden oluşturulmuş bot token'ı.
2. **n8n Sunucusu:** Çalışan bir n8n instance'ı.
3. **Journal API:** Sitenizin `https://mstfyldz.com/api/posts` adresi (veya doğrudan PostgreSQL bağlantısı).
---
## 🛠️ Adım Adım Kurulum Rehberi
### Adım 1: Telegram Bot Oluşturma
1. Telegram'da **@BotFather** kullanıcısını aratın ve başlatın.
2. `/newbot` komutunu gönderin.
3. Botunuza bir isim verin (Örn: `mstfyldz_journal_bot`).
4. BotFather'ın verdiği **HTTP API Token**'ı kopyalayın.
5. BotFather'a `/mybots` yazıp botunuzu seçin ve **Chat ID**'nizi öğrenmek için botunuza ilk mesajı atın.
---
### Adım 2: n8n Workflow Düğümleri (Nodes)
#### 1. Telegram Trigger Node
* **Resource:** `Message`
* **Event:** `Message Received`
* **Credentials:** BotFather'dan aldığınız API Token.
#### 2. Security Switch / If Node (Sadece Sizin Mesajlarınızı Kabul Eder)
* **Condition:** `{{ $json.message.from.id }}` EQUALS `[SİZİN_TELEGRAM_CHAT_ID]`
* *Amacı:* Yabancı kişilerin botunuza mesaj atarak veritabanınıza not eklemesini engeller.
#### 3. Code Node (Format & Payload Dönüştürücü)
Gelen mesaj metnini `mstfyldz journal` API formatına dönüştürür:
```javascript
const msg = $input.item.json.message;
const text = msg.text || msg.caption || "";
// Tarih ve Saat Formatı (Örn: 16 AĞU 2026 • 17:30)
const now = new Date();
const dateStr = now.toLocaleDateString("tr-TR", { day: "2-digit", month: "short", year: "numeric" }).toUpperCase();
const timeStr = now.toLocaleTimeString("tr-TR", { hour: "2-digit", minute: "2-digit" });
// Etiketleri algıla (Örn: #felsefe #kod -> ["felsefe", "kod"])
const tagMatches = text.match(/#[\wĞÜŞİÖÇğüşiöç]+/g) || [];
const tags = tagMatches.map(t => t.replace("#", ""));
if (tags.length === 0) tags.push("telegram");
// Etiketleri içerikten temizle
const cleanContent = text.replace(/#[\wĞÜŞİÖÇğüşiöç]+/g, "").trim();
// Format Tespiti (Kod bloğu, fotoğraf veya standart metin)
let type = "sticky";
let title = undefined;
let codeSnippet = undefined;
if (text.includes("```")) {
type = "code";
const codeMatch = text.match(/```(?:\w+)?\n([\s\S]*?)```/);
codeSnippet = codeMatch ? codeMatch[1] : text;
title = "Telegram Kod Kırıntısı";
} else if (msg.photo) {
type = "polaroid";
} else if (cleanContent.length > 200) {
type = "notebook";
title = cleanContent.split("\n")[0].substring(0, 50);
}
// Mood Tespiti (Rastgele veya içerik bazlı)
const moods = ["spark", "focus", "night", "calm", "visual"];
const moodMap = {
spark: "Fikir Patlaması",
focus: "Aşırı Odak & Kaos",
night: "Gece Melankolisi",
calm: "Sakin & Karalama",
visual: "Polaroid & Kırıntılar"
};
const selectedMood = msg.photo ? "visual" : (type === "code" ? "night" : "spark");
return {
json: {
id: `post-tg-${Date.now()}`,
type,
date: dateStr,
timestamp: timeStr,
mood: selectedMood,
moodLabel: moodMap[selectedMood],
title,
content: cleanContent || "Telegram'dan gönderilen görsel",
marginNotes: ["← Telegram ile atıldı 📱"],
tags,
likes: 1,
stampedText: "TELEGRAM",
codeSnippet
}
};
```
#### 4. HTTP Request Node (Veritabanına Kayıt)
* **Method:** `POST`
* **URL:** `https://mstfyldz.com/api/posts` (veya `http://65.109.236.58:3000/api/posts`)
* **Headers:** `Content-Type: application/json`
* **Body Parameters:** `JSON.stringify($json)`
#### 5. Telegram Response Node (Onay Bildirimi)
* **Resource:** `Message`
* **Operation:** `Send Message`
* **Text:** `✅ *Not Deftere Karalandı!*\n\n📌 *Format:* {{ $json.type }}\n💡 *Mood:* {{ $json.moodLabel }}\n🏷️ *Etiketler:* #{{ $json.tags.join(' #') }}`
---
## ⚡ Telegram Kullanım Örnekleri
### 1. Hızlı Fikir / Post-it Notu
```text
Bugün sade mimarilerin karmaşık mimarilere göre 10 kat daha hızlı bakım sağladığını bir kez daha gördüm. #felsefe #yazılım
```
### 2. Kod Kırıntısı Gönderme
```text
n8n webhook ile gelen veriyi parse eden JS fonksiyonu #js #automation
```javascript
const clean = text.trim();
```
```
### 3. Polaroid Fotoğraf Gönderme
Telegram'dan bir fotoğraf yükleyip altına açıklama yazdığınızda otomatik olarak `polaroid` formatına dönüştürülür.
---
## 📦 n8n Hazır Workflow JSON (Import Edilebilir)
Aşağıdaki JSON verisini n8n'de **Import from JSON** alanına yapıştırarak tüm workflow'u saniyeler içinde oluşturabilirsiniz:
```json
{
"name": "mstfyldz Journal - Telegram Automation",
"nodes": [
{
"parameters": {
"updates": ["message"]
},
"name": "Telegram Trigger",
"type": "n8n-nodes-base.telegramTrigger",
"typeVersion": 1.1,
"position": [250, 300]
},
{
"parameters": {
"conditions": {
"number": [
{
"value1": "={{ $json.message.from.id }}",
"operation": "equal",
"value2": 123456789
}
]
}
},
"name": "Auth Check (Chat ID)",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [450, 300]
},
{
"parameters": {
"method": "POST",
"url": "https://mstfyldz.com/api/posts",
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "Content-Type",
"value": "application/json"
}
]
},
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={{ JSON.stringify($json) }}"
},
"name": "HTTP POST to Journal API",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.1,
"position": [850, 300]
}
],
"connections": {
"Telegram Trigger": {
"main": [[{ "node": "Auth Check (Chat ID)", "type": "main", "index": 0 }]]
}
}
}
```