Facebook Messenger Auto-Reply AI Bot (Special Episode)
Messenger AI Bot ၏ Architecture
Section titled “Messenger AI Bot ၏ Architecture”graph LR A[Customer on Messenger] -->|1. Send Message| B[Meta Webhook Node] B -->|2. Extract Sender ID & Text| C[Set / Edit Fields Node] C -->|3. Prompt AI with Polite Persona| D[AI Agent / LLM Chain Node] D -->|4. Post Response| E[HTTP Request Node - Graph API] E -->|5. Instant Reply| A1. Meta Webhook Verification Setup
Section titled “1. Meta Webhook Verification Setup”Facebook Developer Portal မှ n8n Webhook သို့ ချိတ်ဆက်ရာတွင် Meta မှ GET Request ဖြင့် hub.verify_token စစ်ဆေးပါသည်:
- n8n Webhook Node (GET & POST):
- HTTP Method:
GET(Verification အတွက်) နှင့်POST(Incoming Messages အတွက်)။ - Path:
facebook-webhook
- HTTP Method:
- Verification Response (Code / Switch Node):
// Verify Meta Webhook Tokenif ($input.item.json.query['hub.verify_token'] === 'YOUR_SECRET_VERIFY_TOKEN') {return { json: { body: parseInt($input.item.json.query['hub.challenge']) } };}
2. Incoming Payload Data Extraction
Section titled “2. Incoming Payload Data Extraction”Customer မက်ဆေ့ချ် ဝင်ရောက်လာပါက Set Node (Edit Fields) ဖြင့် Data သန့်စင်ပါ:
- Sender Page-Scoped ID (PSID):
{{ $json.body.entry[0].messaging[0].sender.id }} - Message Text:
{{ $json.body.entry[0].messaging[0].message.text }}
3. AI Persona & Prompting
Section titled “3. AI Persona & Prompting”AI Agent ၏ System Instructions (Prompt) တွင် အောက်ပါအတိုင်း ညွှန်ကြားပါ:
“မင်းက ကျွန်တော်တို့ ဆိုင်ရဲ့ ဖော်ရွေ ယဉ်ကျေးလှတဲ့ Customer Support Specialist ဖြစ်ပါတယ်။ ဝင်လာတဲ့ မက်ဆေ့ချ်က ဘယ်လောက်ပဲ ဒေါသပါနေပါစေ၊ ရိုင်းစိုင်းစွာ ပေတေဆဲဆိုနေပါစေ၊ စိတ်ရှည်စွာဖြင့် ယဉ်ကျေးပျူငှာစွာ တောင်းပန်၍ ဆိုင်၏ ဂုဏ်သိက္ခာကို ထိန်းသိမ်းပြီး မြန်မာလို အတိုချုံး ပြန်လည် ဖြေရှင်း ဖြေကြားပေးပါ။“
4. HTTP Request Node ဖြင့် Messenger ထံ စာပြန်ပို့ခြင်း
Section titled “4. HTTP Request Node ဖြင့် Messenger ထံ စာပြန်ပို့ခြင်း”AI မှ ထုတ်ပေးလိုက်သော တုံ့ပြန်မှုကို HTTP Request Node ဖြင့် Facebook Graph API ထံ POST ပို့ပါ:
- Method:
POST - URL:
https://graph.facebook.com/v25.0/me/messages - Authentication: Header Auth / Query Parameter
access_token(Page Access Token) - JSON Body:
{"recipient": {"id": "={{ $json.sender_id }}"},"messaging_type": "RESPONSE","message": {"text": "={{ $json.ai_response }}"}}