Facebook Graph API integration built on Val Town.
- Webhook receiver — Verifies and receives real-time events from Facebook (page messages, lead ads, etc.)
- Graph API helpers — Post to Pages, get page info, get recent posts, exchange tokens
- Live endpoint — https://ziadamrme--b6e280ce8f6c11f1bf611607ee4eb77e.web.val.run
Go to developers.facebook.com/apps and create a new app. Note the App ID and App Secret from App Settings → Basic.
| Key | Description |
|---|---|
FB_APP_ID | Your Meta App ID |
FB_APP_SECRET | Your Meta App Secret |
FB_PAGE_ACCESS_TOKEN | Page Access Token (from Graph API Explorer or Page settings) |
FB_VERIFY_TOKEN | Any random string you choose (used for webhook verification) |
👉 Add FB_APP_ID here: https://www.val.town/x/ziadamrme/Facebook_mcb/environment-variables?key=FB_APP_ID
👉 Add FB_APP_SECRET here: https://www.val.town/x/ziadamrme/Facebook_mcb/environment-variables?key=FB_APP_SECRET
👉 Add FB_PAGE_ACCESS_TOKEN here: https://www.val.town/x/ziadamrme/Facebook_mcb/environment-variables?key=FB_PAGE_ACCESS_TOKEN
👉 Add FB_VERIFY_TOKEN here: https://www.val.town/x/ziadamrme/Facebook_mcb/environment-variables?key=FB_VERIFY_TOKEN
In your Meta App dashboard, go to Webhooks, add the live endpoint URL above as the callback URL, and use the same FB_VERIFY_TOKEN you set as the env var.
| Function | Description |
|---|---|
graphGet(path, params) | Generic Graph API GET request |
graphPost(path, body) | Generic Graph API POST request |
postToPage(pageId, message) | Post a text message to a Page's feed |
postLinkToPage(pageId, link, message?) | Post a link (with optional message) to a Page's feed |
getPageInfo(pageId) | Get Page info (name, fans, about, etc.) |
getPagePosts(pageId, limit?) | Get recent posts from a Page |
getLongLivedToken(appId, appSecret, shortToken) | Exchange a short-lived token for a long-lived one |
main.ts — HTTP endpoint (webhook verification + event receiver)
lib/facebook.ts — Graph API helper functions