{"id":16979363,"url":"https://github.com/marcl/chatfuel-broadcast","last_synced_at":"2025-04-12T01:42:38.912Z","repository":{"id":31461486,"uuid":"127969096","full_name":"MarcL/chatfuel-broadcast","owner":"MarcL","description":"A simplified HTTP client for calling the Chatfuel broadcast API","archived":false,"fork":false,"pushed_at":"2023-01-06T01:57:32.000Z","size":1124,"stargazers_count":7,"open_issues_count":7,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-12-06T20:16:46.647Z","etag":null,"topics":["chatbot","chatfuel","http-client","marketing","messenger"],"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/MarcL.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":"2018-04-03T21:08:44.000Z","updated_at":"2024-01-28T20:29:29.000Z","dependencies_parsed_at":"2023-01-14T19:15:42.357Z","dependency_job_id":null,"html_url":"https://github.com/MarcL/chatfuel-broadcast","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarcL%2Fchatfuel-broadcast","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarcL%2Fchatfuel-broadcast/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarcL%2Fchatfuel-broadcast/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarcL%2Fchatfuel-broadcast/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MarcL","download_url":"https://codeload.github.com/MarcL/chatfuel-broadcast/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248505802,"owners_count":21115353,"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":["chatbot","chatfuel","http-client","marketing","messenger"],"created_at":"2024-10-14T01:45:35.846Z","updated_at":"2025-04-12T01:42:38.884Z","avatar_url":"https://github.com/MarcL.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# chatfuel-broadcast\n\n[![Build Status](https://github.com/MarcL/chatfuel-broadcast/actions/workflows/runTests.yml/badge.svg)](https://travis-ci.org/MarcL/chatfuel-broadcast)\n\nA simplified client for using the [Chatfuel broadcast API](http://docs.chatfuel.com/broadcasting/broadcasting-documentation/broadcasting-api) which includes rate limiting.\n\n## Installation\n\nThe module is installed via `npm` or `yarn`:\n\n```\nnpm install chatfuel-broadcast\n```\n\nor\n\n```\nyarn add chatfuel-broadcast\n```\n\n## Usage\n\nImport or require the module in order to use it:\n\n```javascript\n// For ES6 modules\nimport chatfuelBroadcast from 'chatfuel-broadcast';\n```\n\n```javascript\n// For CommonJS modules\nconst chatfuelBroadcast = require('chatfuel-broadcast');\n```\n\nCreate an options object which contains the mandatory parameters of `botId`, `token` and `userId`. You will find your `botId` in the Chatfuel dashboard URL for your bot and the `token` is defined in your dashboard. Note that you can only set either `blockId` or `blockName` but you can't pass both parameters. The `blockId` can be seen in the URL of the Chatfuel bot, or you can just use the block name that you define.\n\nFacebook message tags are now mandatory and an error will be thrown if one isn't passed. See [Facebook's message tags](https://developers.facebook.com/docs/messenger-platform/send-messages/message-tags) documentation for a list of valid tags. You can also supply the `NON_PROMOTIONAL_SUBSCRIPTION` tag but your page must be an approved new page under the [Facebook News Page Index (NPI)](https://www.facebook.com/help/publisher/316333835842972).\n\n_**Note:** In addition to a the valid Facebook Messenger tags, there is a single Chatfuel-specific tag called `UPDATE`. You can **ONLY** use this tag with the broadcast API to send a message if you have recieved an interaction from your user within the previous 24 hours. Your chatbot will get banned if you fail to adhere to this rule._\n\nAdd in the attributes property for the Chatfuel user attributes you want to set:\n\n```javascript\nconst options = {\n    // Mandatory options\n    botId: '\u003cchatfuel-bot-id\u003e',\n    token: '\u003cchatfuel-token\u003e',\n    userId: '\u003cchatfuel-user-id\u003e',\n    messageTag: '\u003cfacebook-message-tag\u003e',\n\n    // Only one of these is needed\n    // An error will be thrown if both are passed\n    blockName: '\u003cchatfuel-block-name-to-return-to\u003e',\n    blockId: '\u003cchatfuel-block-id-to-return-to\u003e',\n\n    // User attributes which will be set in Chatfuel\n    attributes: {\n        myAttribute: 'myValue',\n        anotherAttribute: 'anotherValue'\n    }\n};\n```\n\nFinally, call the broadcast function. It's Promise-based so it expects a then-able function. Add a `catch` function for error handling.\n\n```javascript\n// Promise-based response\nchatfuelBroadcast(options)\n    .then((responseMessage) =\u003e {\n        // responseMessage will be 'ok'\n        console.log('Call succeeded');\n    })\n    .catch(error =\u003e {\n        console.log(error.message);\n    });\n```\n\n## Expected responses\n\nIf the request is successful the API will return an `ok` string (which is the response from Chatfuel's API).\n\nIf an API request is malformed, for example if you have an invalid block name or block ID, or you supply an incorrect Messenger tag or are missing request data, then the API will throw an error. The error message will inform you of the incorrect or missing data.\n\n## Rate limiting\n\nThe Chatfuel documentation states that you can broadcast up to 25 request per second (RPS) using their [broadcast API](https://docs.chatfuel.com/en/articles/790461-broadcasting-api). This package sets this rate limit for you and avoids you having to add additional rate limiting logic in your own code. Note that the broadcast API can still fail if you pass incorrect data (e.g. a bad block name or block ID) so ensure you use an error handler.\n\n## Running the tests\n\nThe unit tests can be run using `npm` or `yarn`:\n\n```\nnpm test\nyarn test\n```\n\n## Licence\n\nThis project is licensed under the MIT Licence - see the [LICENCE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcl%2Fchatfuel-broadcast","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarcl%2Fchatfuel-broadcast","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcl%2Fchatfuel-broadcast/lists"}