{"id":16870053,"url":"https://github.com/diegorbaquero/node-fb-messenger","last_synced_at":"2025-04-06T09:08:31.354Z","repository":{"id":57233606,"uuid":"56195588","full_name":"DiegoRBaquero/node-fb-messenger","owner":"DiegoRBaquero","description":":envelope: Facebook Messenger Platform Node.js API Wrapper","archived":false,"fork":false,"pushed_at":"2020-04-30T19:58:28.000Z","size":71,"stargazers_count":210,"open_issues_count":4,"forks_count":54,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-03T16:04:48.592Z","etag":null,"topics":["api","bot","facebook","messenger","node","nodejs","wrapper"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DiegoRBaquero.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-14T00:39:43.000Z","updated_at":"2024-10-30T09:56:11.000Z","dependencies_parsed_at":"2022-08-31T14:11:31.708Z","dependency_job_id":null,"html_url":"https://github.com/DiegoRBaquero/node-fb-messenger","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DiegoRBaquero%2Fnode-fb-messenger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DiegoRBaquero%2Fnode-fb-messenger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DiegoRBaquero%2Fnode-fb-messenger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DiegoRBaquero%2Fnode-fb-messenger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DiegoRBaquero","download_url":"https://codeload.github.com/DiegoRBaquero/node-fb-messenger/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247457802,"owners_count":20941906,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","bot","facebook","messenger","node","nodejs","wrapper"],"created_at":"2024-10-13T15:01:57.033Z","updated_at":"2025-04-06T09:08:31.328Z","avatar_url":"https://github.com/DiegoRBaquero.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fb-messenger [![npm](https://img.shields.io/npm/v/fb-messenger.svg)](https://www.npmjs.com/package/fb-messenger) [![npm](https://img.shields.io/npm/dm/fb-messenger.svg)](https://www.npmjs.com/package/fb-messenger) [![npm](https://img.shields.io/npm/l/fb-messenger.svg)](LICENSE) \n#### Facebook Messenger Platform NodeJS API Wrapper\n\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/) [![Greenkeeper badge](https://badges.greenkeeper.io/DiegoRBaquero/node-fb-messenger.svg)](https://greenkeeper.io/) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/b3cbd4666fa54722b38288c98cd5e8c1)](https://www.codacy.com/app/diegorbaquero/node-fb-messenger?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=DiegoRBaquero/node-fb-messenger\u0026amp;utm_campaign=Badge_Grade) [![Code Climate](https://codeclimate.com/github/DiegoRBaquero/node-fb-messenger/badges/gpa.svg)](https://codeclimate.com/github/DiegoRBaquero/node-fb-messenger)\n\n## Installation\n\n**Requires Node 8+**\n\n```bash\nnpm install fb-messenger --save\n```\n\n## API\n\nYou must require fb-messenger and create an instance\n\n```js\n// Constructor\nconst FBMessenger = require('fb-messenger')\nconst messenger = new FBMessenger({token, notificationType})\n// token is optional, if not included, must be sent in each method, notificationType is optional, default = 'REGULAR'\n\nmessenger.setToken(token) // Sets the instance token\n\nmessenger.setNotificationType(notificationType) // Sets the instance notificationType\n\n// Methods (notificationType and token are optional)\nmessenger.sendTextMessage({id, message, notificationType, token}) // Sends a text message\n\nmessenger.sendAudioMessage({id, url, notificationType, token}) // Sends an audio from URL\n\nmessenger.sendVideoMessage({id, url, notificationType, token}) // Sends an video from URL\n\nmessenger.sendImageMessage({id, url, notificationType, token}) // Sends an image from URL\n\nmessenger.sendFileMessage({id, url, notificationType, token}) // Sends an file from URL\n\nmessenger.sendQuickRepliesMessage({id, attachment, quickReplies, notificationType, token}) // Sends a Quick Replies Message\n\nmessenger.sendButtonsMessage({id, message, buttons, notificationType, token}) // Sends a buttons template message\n\nmessenger.sendGenericMessage({id, elements, notificationType, token}) // Sends a generic template message\n\nmessenger.sendListMessage({id, elements, buttons, top_element_type, notificationType, token}) // Sends a list template message\n\nmessenger.sendMediaMessage({id, elements, notificationType, token}) // Sends a media template message\n\nmessenger.sendOpenGraphMessage({id, elements, notificationType, token}) // Sends an open graph template message\n\nmessenger.sendReceiptMessage({id, payload, notificationType, token}) // Sends a receipt template message (No need for template_type in payload) \n\nmessenger.sendAction({id, actionType, token}) // Send an action type (One of 'mark_seen', 'typing_on', 'typing_off')\n\nmessenger.sendMessage({id, data, notificationType, token}) // Send a message from custom data\n\nmessenger.getProfile({id, token}) // Gets user information\n\nmessenger.setWelcomeMessage({pageId, message, token}) // Sets Page's Welcome Message (message can be a text string or a strucuted message)\n\nmessenger.setGreetingText ({pageId, message, token}) // Sets Page's Greeting Text\n\nmessenger.setPersistentMenu ({pageId, menuItems, token}) // Set's Page's Persistent Menu\n\nmessenger.setDomainWhitelist ({pageId, domains, token}) // Set's Page's Whitelisted Domains \n\nmessenger.sendThreadSettingsMessage ({pageId, body, token}) // Send Manually Page's Thread Settings\n```\n\n#### Notification Types:\n - REGULAR\n - SILENT_PUSH\n - NO_PUSH\n\n## Examples\n\n### Basic Example\n\n```js\nconst FBMessenger = require('fb-messenger')\nconst messenger = new FBMessenger({token: '\u003cYOUR TOKEN\u003e'}) // Will always use this page's token for request unless sent on each method\n\nmessenger.sendTextMessage({id: '\u003cID\u003e', text: 'Hello'})\n```\n\n### Catch errors Example\n\n```js\nconst FBMessenger = require('fb-messenger')\nconst messenger = new FBMessenger({token: '\u003cYOUR TOKEN\u003e'})\n\ntry {\n  const response = await messenger.sendTextMessage({id: '\u003cID\u003e', text: 'Hello'})\n  console.log(response)\n} catch (e) {\n  console.error(e)\n}\n```\n\n### No push Example\n\n```js\nconst FBMessenger = require('fb-messenger')\nconst messenger = new FBMessenger({token: '\u003cYOUR TOKEN\u003e'})\n\nmessenger.sendTextMessage({id: '\u003cID\u003e', text: 'Hello', notificationType: 'NO_PUSH'})\n```\n\n### Default to silent push Example\n\n```js\nconst FBMessenger = require('fb-messenger')\nconst messenger = new FBMessenger({token: '\u003cYOUR TOKEN\u003e', notificationType: 'SILENT_PUSH'})\n```\n\n### Complete Example\n\n```js\nconst FBMessenger = require('fb-messenger')\nconst messenger = new FBMessenger({token: '\u003cYOUR TOKEN\u003e', notificationType: 'NO_PUSH'})\n\ntry {\n  await messenger.sendTextMessage({id: '\u003cID\u003e', text: 'Hello'}) // Send a message with NO_PUSH, ignoring response\n  console.log('Sent successfully')\n} catch(e) {\n  console.error(e)\n}\n\n// Send an image overriding default notification type with callback\ntry {\n  const response = await messenger.sendImageMessage({id: '\u003cID\u003e', url: '\u003cIMG URL\u003e', notificationType: 'REGULAR'})\n  console.log('Sent image, response:')\n  console.dir(response)\n} catch(e) {\n  console.error(e)\n}\n\nmessenger.sendTextMessage({id: '\u003cID\u003e', text: 'Hello', token: '\u003cYOUR OTHER TOKEN\u003e'}) // Send message on another page\n```\n\n## License\n\nMIT. Copyright © [Diego Rodríguez Baquero](https://diegorbaquero.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiegorbaquero%2Fnode-fb-messenger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdiegorbaquero%2Fnode-fb-messenger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiegorbaquero%2Fnode-fb-messenger/lists"}