{"library":"messaging-api-messenger","title":"Messenger Messaging API Client","description":"The `messaging-api-messenger` package offers a comprehensive, TypeScript-rewritten client for interacting with the Facebook Messenger Platform API, enabling developers to build sophisticated chatbots and integrate diverse messaging functionalities. As part of the larger `messaging-apis` monorepo by Yoctol, its current stable version is `1.1.0`. While the monorepo sees regular updates, specific feature additions for `messaging-api-messenger` are less frequent, with the last notable feature (persona support) in `v1.0.2` (September 2020) and a type fix in `v1.0.5` (April 2021). The library distinguishes itself through full TypeScript support, automatic `appsecret_proof` handling for enhanced Graph API security, and a robust error handling system leveraging `axios` and `axios-error`. It covers a wide range of Messenger Platform capabilities including the Send API (for text, attachments, templates, and quick replies), User Profile API, Messenger Profile API (for persistent menus and get started buttons), Handover Protocol, and Persona API.","language":"javascript","status":"maintenance","last_verified":"Sun Apr 19","install":{"commands":["npm install messaging-api-messenger"],"cli":null},"imports":["import { MessengerClient } from 'messaging-api-messenger';","import type { Message } from 'messaging-api-messenger';","import { MessengerError } from 'messaging-api-messenger';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { MessengerClient } from 'messaging-api-messenger';\n\n// It is recommended to use environment variables for sensitive tokens\nconst ACCESS_TOKEN = process.env.MESSENGER_ACCESS_TOKEN ?? 'YOUR_ACCESS_TOKEN';\nconst APP_ID = process.env.MESSENGER_APP_ID ?? 'YOUR_APP_ID';\nconst APP_SECRET = process.env.MESSENGER_APP_SECRET ?? 'YOUR_APP_SECRET';\nconst USER_ID = process.env.MESSENGER_USER_ID ?? 'YOUR_USER_ID'; // Replace with a valid Messenger user ID\n\nif (!ACCESS_TOKEN || !APP_ID || !APP_SECRET || !USER_ID) {\n  console.error('Please set MESSENGER_ACCESS_TOKEN, MESSENGER_APP_ID, MESSENGER_APP_SECRET, and MESSENGER_USER_ID environment variables.');\n  process.exit(1);\n}\n\nconst client = new MessengerClient({\n  accessToken: ACCESS_TOKEN,\n  appId: APP_ID,\n  appSecret: APP_SECRET,\n  version: '6.0' // Explicitly specify the Graph API version\n});\n\nasync function sendSampleMessages() {\n  try {\n    console.log('Sending a simple text message...');\n    const textResponse = await client.sendText(USER_ID, 'Hello from the Messenger API client!');\n    console.log('Text message sent successfully:', textResponse);\n\n    console.log('\\nFetching user profile...');\n    const userProfile = await client.getUserProfile(USER_ID, { fields: ['first_name', 'last_name', 'profile_pic'] });\n    console.log('User Profile:', userProfile);\n\n    console.log('\\nSending a message with quick replies...');\n    const quickReplyResponse = await client.sendText(USER_ID, 'Choose your favorite color:', {\n      quickReplies: [\n        { contentType: 'text', title: 'Red', payload: 'RED_PAYLOAD' },\n        { contentType: 'text', title: 'Blue', payload: 'BLUE_PAYLOAD' }\n      ]\n    });\n    console.log('Quick reply message sent successfully:', quickReplyResponse);\n\n  } catch (error: any) {\n    console.error('\\nAn error occurred during API interaction:');\n    if (error.response) {\n      console.error('Response data:', error.response.data); // Detailed error from Facebook API\n      console.error('Response status:', error.response.status);\n    } else if (error.request) {\n      console.error('No response received:', error.request);\n    } else {\n      console.error('Error message:', error.message);\n    }\n    console.error('Error stack:', error.stack);\n  }\n}\n\nsendSampleMessages();\n","lang":"typescript","description":"This quickstart demonstrates how to initialize the MessengerClient, send a basic text message, fetch a user's profile, and send a message with quick replies, incorporating environment variables for secure token handling and comprehensive error handling.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}