Back

Facebook Messenger API Essential Guide

Aug 1, 20246 minute read

What type of API does Facebook Messenger provide?

Facebook Messenger uses GraphQL as its API type.

GraphQL is a query language for APIs that returns data in JSON format. It uses a type system to define the schema of available data and typically uses a single endpoint for all data requests. GraphQL allows clients to specify exactly the data they need in a query, and the server responds with only that requested data in a single response.

Key characteristics of GraphQL include:

  • Strongly typed schema
  • Flexible data fetching
  • No versioning required

Facebook created GraphQL in 2012 to rebuild their native mobile apps, including Facebook Messenger. They needed a robust data-fetching API that could handle complex data requirements for their mobile apps, reduce the number of API calls, and improve efficiency in data transfer.

Does the Facebook Messenger API have webhooks?

Yes, the official Facebook Messenger API does have webhooks. Here are the key points about Messenger webhooks:

Webhook Events

The Messenger Platform supports a variety of webhook events that you can subscribe to:

  • messages
  • message_deliveries
  • message_reads
  • message_echoes
  • messaging_postbacks
  • messaging_optins
  • messaging_referrals
  • messaging_handovers
  • messaging_policy_enforcement
  • standby

Key Points

  • Webhooks allow you to receive real-time notifications of events in Messenger conversations
  • You need to subscribe your app to the specific webhook events you want to receive
  • Events are sent as POST requests to your webhook endpoint
  • The payload contains information like sender ID, recipient ID, timestamp, and event-specific data
  • Webhooks are essential for building interactive Messenger experiences and chatbots

Best Practices

  • Use the latest API version to receive all available information for each webhook
  • Implement proper security measures like verifying webhook requests
  • Process webhook events asynchronously to handle high volumes
  • Set up error handling and logging for your webhook endpoint

In summary, webhooks are a core part of the Messenger Platform API, allowing you to build responsive and interactive messaging experiences by receiving real-time updates on conversation events.

Rate Limits and other limitations

Here are the key points about the API rate limits for the Facebook Messenger API:

Messenger Profile API Limits

  • Calls to the Messenger Profile API are limited to 10 API calls per 10 minute interval per Page.

General Messenger Platform Limits

  • Rate limits for the Messenger Platform depend on the specific API used and sometimes the message content.

  • For the main Messenger API, the limit is calculated as: Calls within 24 hours = 200 * Number of Engaged Users Where "Number of Engaged Users" is the number of people the business can message via Messenger.

Send API Limits

  • The Send API does not have a fixed rate limit, but you can safely send 250 requests per second.

Page-Level Limits

  • For Pages API calls using a Page access token or system User access token: Calls within 24 hours = 4800 * Number of Engaged Users Where "Number of Engaged Users" is the number of users who engaged with the Page per 24 hours.

Error Codes

  • Error code 32 indicates the user/app has reached its rate limit for Pages API requests.
  • Error code 4 indicates the app has reached its general rate limit.

Key Considerations

  • All API calls count towards limits, not just individual requests. For example, a single request specifying multiple IDs counts as multiple calls.

  • Different access tiers (e.g. development vs standard) have different rate limits.

  • There are separate limits for different types of operations like ads insights, custom audiences, etc.

  • Facebook may apply additional limits to prevent abuse.

Best Practices

  • Monitor rate limit usage via response headers and the App Dashboard.
  • Use system user access tokens when possible for higher limits.
  • Implement proper error handling and backoff when limits are reached.
  • Consider upgrading to higher access tiers if more capacity is needed.

In summary, the Messenger API has various rate limits that depend on factors like the specific API, access level, and user engagement. Carefully monitoring usage and implementing proper throttling is important to stay within the allowed limits.

Latest API Version

Based on the search results provided, I cannot determine the most recent version of the Facebook Messenger API. The search results do not contain specific information about API versions or recent updates to the Messenger Platform.

However, I can provide some general information about the Facebook Messenger Platform:

Key Points

  • The Messenger Platform allows developers to build messaging solutions that connect businesses with their customers, potential customers, and followers.

  • It supports conversations between Facebook Business Pages and Facebook users, as well as between Instagram Professional Accounts and Instagram users.

  • The platform offers various features, including:

    • Messaging: Sending and receiving text, media, and structured templates
    • Webview: Building web-based experiences
    • Discovery: Reaching new people and re-engaging existing contacts
    • IDs & Profile: Personalizing conversations and linking with existing authentication
    • Chat Plugin: Extending reach to every conversation
    • Natural Language Processing (NLP): Adding conversational context
    • Analytics: Gaining insights and monitoring performance

Best Practices

  • Before implementing any solution, developers should familiarize themselves with the Messenger Platform concepts and implement several required components.

  • Developers should stay updated with the latest changes and features by regularly checking the official Facebook for Developers documentation and changelog.

Additional Information

  • On July 23, 2024, Facebook launched a new Instagram API with Instagram Login, allowing Instagram professional accounts to have conversations with customers and manage comments without being linked to a Facebook Page.

To get the most up-to-date information about the Messenger API version, I recommend checking the official Facebook for Developers documentation or contacting Facebook Developer Support directly, as the search results provided do not contain this specific information.

How to get a Facebook Messenger developer account and API Keys?

To get a developer account for Facebook Messenger and create an API integration:

  1. Create a Developer App

    • Go to the Facebook for Developers website and click on "My Apps" > "Create App".
    • Or use an existing app if you have one.
  2. Set Up a Business Manager Account

    • Be an admin of your Business Manager account.
    • Create one on Facebook if you don't have it.
  3. Create a System User

    • Add your app to your Business Manager.
    • Add system users to your Business Manager or use an existing one.
  4. Assign Assets

    • Give your system user admin access to:
      • The app for the Commerce API
      • The test commerce account
      • The Facebook Page backing your test commerce account
      • The catalog connected to your test commerce account
  5. Generate a System User Access Token

    • On Business Manager > System User page, assign the system user as an admin of your app.
    • Click "Generate Token".
    • Request permissions: pages_read_engagement, catalog_management, business_management.
    • Verify permissions using the Access Token Debugger tool.
  6. Generate a Page Access Token

    • Obtain a Page access token using the System User access token.
    • Store this token securely and rotate it regularly.
  7. Connect Your App to a Commerce Account

    • Make an API call to connect your app to your test commerce account.
  8. Start Building and Testing

    • Manage orders using the Order Management API.
    • Submit your app for App Review to manage a real commerce account.

Key Points:

  • The Commerce API is in a closed, invite-only Beta program.
  • Before approval, your app can only access test commerce accounts.
  • For platform integrations, build a Facebook Login flow to generate access tokens for clients' pages.

What can you do with the Facebook Messenger API?

Based on the Facebook Messenger API documentation, here are the key data models you can interact with and what is possible for each:

Messaging

  • Send and receive text messages
  • Send and receive media (images, videos, audio, etc.)
  • Send structured message templates
  • Use quick replies for guided conversations
  • Implement message reactions

Webview

  • Build web-based experiences within Messenger
  • Use existing web development tools and frameworks
  • Create rich, interactive interfaces

Discovery

  • Reach new users through Messenger, Facebook, and the web
  • Re-engage existing users
  • Implement discovery features like m.me links and Messenger codes

IDs & Profile

  • Access user profile information (name, profile picture, etc.)
  • Link conversations to existing authentication systems
  • Create unified experiences across platforms

Chat Plugin

  • Extend Messenger experiences to your website
  • Allow website visitors to start Messenger conversations

Natural Language Processing (NLP)

  • Detect intents and extract entities from messages automatically
  • Identify common traits like greetings, farewells, and sentiment
  • Recognize entities like dates, times, amounts, locations, etc.
  • Customize NLP models for specific use cases

Analytics

  • Gain insights into conversation metrics
  • Monitor performance of messaging experiences
  • Track success of campaigns and features

Webhooks

  • Receive real-time updates on messaging events
  • Get notified of message deliveries, reads, and other activities
  • Implement custom logic based on webhook events

Handover Protocol

  • Enable multiple apps to participate in conversations
  • Implement seamless handoffs between bots and human agents

Conversation Routing

  • Direct conversations to appropriate handlers
  • Implement rules for routing based on user attributes or intents

By leveraging these data models and capabilities, developers can create rich, interactive messaging experiences on the Facebook Messenger platform.