1. Home
  2. LangChain
  3. ফেইসবুক পোস্ট অটো পোস্টিং
  4. প্রজেক্ট সেটআপ

প্রজেক্ট সেটআপ

# Groq API Key (Free: https://console.groq.com)
GROQ_API_KEY=your_groq_api_key_here

# Facebook Page Access Token (From Facebook Developer Portal)
FACEBOOK_ACCESS_TOKEN=your_facebook_access_token_here

# Facebook Page ID (Your Facebook Page ID)
FACEBOOK_PAGE_ID=your_facebook_page_id_here

📁 Project Structure:

facebook_bot/
├── 📄 facebook_bot.py      # মেইন পাইথন ফাইল (একই ফোল্ডারে)
├── 📄 .env                 # API keys (একই ফোল্ডারে)
└── 📁 fb_content/          # অটোমেটিক তৈরি হবে
    ├── 📁 images/          # AI generated ছবি
    ├── 📁 posts/           # পোস্ট JSON ডাটা
    ├── 📁 logs/            # লগ ফাইল
    ├── 📄 post_queue.json  # পোস্ট কিউ
    └── 📄 posted_history.json # পোস্ট হিস্ট্রি

🔧 Step 1: Library Installation

# terminal/cmd এ এই commands গুলো run করো

pip install langchain langchain-core langchain-community langchain-groq python-dotenv requests schedule pydantic

pip install langchain langchain-groq python-dotenv requests

প্রতিটি লাইব্রেরির কাজ:

লাইব্রেরিকাজ
langchain-groqAI দিয়ে বাংলা কন্টেন্ট তৈরি করতে
python-dotenv.env ফাইল থেকে API keys পড়তে
requestsFacebook API এবং Image API এ request পাঠাতে
scheduleঅটোমেটিক সময়মতো পোস্ট করতে
pydanticডাটা validation করতে

📝 Step 2: Create facebook_bot.py

# facebook_bot.py - STEP 1: FOLDER SETUP
import os
from pathlib import Path

print("🚀 Facebook Auto-Poster - Step 1: Folder Setup")
print("=" * 50)

def setup_folders():
    """ফোল্ডার এবং ফাইল তৈরি করা"""
    print("\n📁 Creating folder structure...")
    
    # মূল ফোল্ডার
    base_dir = Path("fb_content")
    
    # ফোল্ডার লিস্ট
    folders = [
        base_dir,
        base_dir / "images",
        base_dir / "posts", 
        base_dir / "logs"
    ]
    
    # ফোল্ডার তৈরি
    for folder in folders:
        folder.mkdir(parents=True, exist_ok=True)
        print(f"   ✅ Created: {folder}/")
    
    # JSON ফাইল তৈরি
    json_files = {
        base_dir / "post_queue.json": "পোস্ট কিউ",
        base_dir / "posted_history.json": "পোস্ট হিস্ট্রি"
    }
    
    for file_path, description in json_files.items():
        if not file_path.exists():
            file_path.write_text("[]", encoding='utf-8')
        print(f"   📄 Created: {file_path.name}")
    
    print("🎉 Folder structure created successfully!")
    
    # ফোল্ডার ট্রি দেখানো
    print("\n📂 Folder Structure Created:")
    print("fb_content/")
    print("├── images/")
    print("├── posts/")
    print("├── logs/")
    print("├── post_queue.json")
    print("└── posted_history.json")
    
    return base_dir

# ফোল্ডার সেটআপ চালাও
base_dir = setup_folders()

print("\n" + "=" * 50)
print("✅ STEP 1 COMPLETED!")
print("📁 Check: fb_content/ folder created with all subfolders")
print("🚀 Now run Step 2: Groq API Test")

এই কোডটি কপি করে facebook_bot.py ফাইলে পেস্ট করুন এবং রান করুন:

python facebook_bot.py

আউটপুট চেক করুন:

🚀 Facebook Auto-Poster - Step 1: Folder Setup
==================================================

📁 Creating folder structure...
   ✅ Created: fb_content/
   ✅ Created: fb_content/images/
   ✅ Created: fb_content/posts/
   ✅ Created: fb_content/logs/
   📄 Created: post_queue.json
   📄 Created: posted_history.json
🎉 Folder structure created successfully!

📂 Folder Structure Created:
fb_content/
├── images/
├── posts/
├── logs/
├── post_queue.json
└── posted_history.json

==================================================
✅ STEP 1 COMPLETED!
📁 Check: fb_content/ folder created with all subfolders
🚀 Now run Step 2: Groq API Test

ফোল্ডার চেক করুন যে এই স্ট্রাকচার তৈরি হয়েছে কিনা:

fb_content/
├── images/
├── posts/
├── logs/
├── post_queue.json
└── posted_history.json
# facebook_bot.py - STEP 2: GROQ API TEST
import os
from pathlib import Path
from dotenv import load_dotenv

# LangChain imports
from langchain_groq import ChatGroq
from langchain.schema import HumanMessage, SystemMessage

# Load environment variables
load_dotenv()

print("🚀 Facebook Auto-Poster - Step 2: Groq API Test")
print("=" * 50)

def test_groq_api():
    """Groq API টেস্ট করা"""
    print("\n🤖 Testing Groq API Connection...")
    
    # API key চেক করা
    groq_api_key = os.getenv("GROQ_API_KEY", "your-groq-key-here")
    
    if groq_api_key == "your-groq-key-here":
        print("❌ GROQ_API_KEY not set in .env file!")
        print("💡 Get FREE API key from: https://console.groq.com")
        return False
    
    try:
        # LangChain Groq client তৈরি করা
        llm = ChatGroq(
            groq_api_key=groq_api_key,
            model_name="llama-3.3-70b-versatile",
            temperature=0.7
        )
        
        # Simple test prompt - বাংলায়
        system_prompt = SystemMessage(content="তুমি একজন সহায়ক AI। বাংলায় উত্তর দাও।")
        user_prompt = HumanMessage(content="বাংলায় বলো: 'গ্রোক এআই কাজ করছে!'")
        
        response = llm.invoke([system_prompt, user_prompt])
        
        print(f"✅ Groq API Connected Successfully!")
        print(f"🤖 AI Response: {response.content}")
        print(f"🔧 Model: llama-3.3-70b-versatile")
        return True
        
    except Exception as e:
        print(f"❌ Groq API Error: {e}")
        print("💡 Check your API key and internet connection")
        return False

# Groq API টেস্ট চালাও
groq_test_result = test_groq_api()

print("\n" + "=" * 50)
if groq_test_result:
    print("✅ STEP 2 COMPLETED!")
    print("🤖 Groq API is working perfectly!")
    print("🚀 Now run Step 3: Image Generation Test")
else:
    print("❌ STEP 2 FAILED!")
    print("💡 Fix the Groq API issue before proceeding")

এখন পুরো কোডটি একসাথে দেখতে হবে এমন:

How can we help?