{"id":22111573,"url":"https://github.com/thalesdavila/chatloop","last_synced_at":"2025-06-19T12:34:18.959Z","repository":{"id":57197295,"uuid":"106565481","full_name":"ThalesDavila/chatloop","owner":"ThalesDavila","description":"Chatbot framework designed taking user context as a priority. ","archived":false,"fork":false,"pushed_at":"2021-09-03T02:41:17.000Z","size":2586,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-24T04:40:27.474Z","etag":null,"topics":["chatbot","chatbot-facebook","chatbot-fb","chatbot-framework","messenger","messenger-api","messenger-bot","messenger-chatbots"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/chatloop","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ThalesDavila.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-11T14:31:35.000Z","updated_at":"2021-09-03T02:41:20.000Z","dependencies_parsed_at":"2022-09-16T13:10:32.401Z","dependency_job_id":null,"html_url":"https://github.com/ThalesDavila/chatloop","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ThalesDavila/chatloop","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThalesDavila%2Fchatloop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThalesDavila%2Fchatloop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThalesDavila%2Fchatloop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThalesDavila%2Fchatloop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ThalesDavila","download_url":"https://codeload.github.com/ThalesDavila/chatloop/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThalesDavila%2Fchatloop/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260751705,"owners_count":23057200,"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","chatbot-facebook","chatbot-fb","chatbot-framework","messenger","messenger-api","messenger-bot","messenger-chatbots"],"created_at":"2024-12-01T10:49:14.235Z","updated_at":"2025-06-19T12:34:13.948Z","avatar_url":"https://github.com/ThalesDavila.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"#### Chatbot framework designed taking user context as a priority. \n* Created mixing game loop and web routing concepts.\n* Chatloop has a very easy to use a function to keep the user context under development. So, you don't need to worry about databases in the beginning.\n* Supports Facebook Messenger.\n\n\n\n## Usage\n##### How it works:\n\nEvery time user sends an input, the loopsRoutes file will be called. Then, based on the user context, will define the correct conversational loop to call.\n\n\n\n##### Exemple of conversational loop:\n\n```js\n///loops/getStarted-loop.js\nconst send = require('chatloop').Send;\nconst context = require('chatloop').Development.context;\n\nmodule.exports = function(event, context) {\n        send.Text(event.senderId, 'Hi');\n\n        let buttons = [\n        {\n            type:\"postback\",\n            title:\"Yes\",\n            payload:\"DONT_LIKE_PIZZA_PAYLOAD\"\n        },\n        {\n            type:\"postback\",\n            title:\"No\",\n            payload:\"LIKE_PIZZA_PAYLOAD\"\n        }\n        ];\n        send.Button(event.senderId, 'Do You like pizza?', buttons)\n\n        if(event.payload === \"LIKE_PIZZA_PAYLOAD\") {\n            context('likePizzaLoop')\n            //change the loop to be called to likePizzaLoop\n            send.Text(event.senderId, 'Me too')\n            send.Text(event.senderId, 'What pizza flavour do you prefer?')\n        }\n         else if(event.payload === \"DONT_LIKE_PIZZA_PAYLOAD\") {\n            context('dontLikePizzaLoop') \n            //change the loop to be called to dontLikePizzaLoop\n            send.Text(event.senderId, 'I do not belive')\n            senD.Text(event.senderId, 'Do you like hamburguer?')\n        }\n}\n```\nBased on user context, /loops/likePizza-loop.js or \n/loops/dontlikePizza-loop.js will be called. \n\n\n\n```js\n///loops/loopsRoutes.js\nconst Loop = require('chatloop').Loop;\nconst context = require('chatloop').Development.context;\n\nconst getStartedLoop = require('./getStarted-loop');\nconst likePizza = require('./likePizza-loop');\nconst dontlikePizza = require('./dontlikePizza-loop');\n\nmodule.exports = async function (event) {    \n  /*\n  Will return the current context. \n  If does not have loopToBeCalled defined,\n  will call the getStartedLoop.\n  */\n    const read_context = await context();\n  if(read_context \u0026\u0026 read_context.loopToBeCalled) {\n    loopToBeCalled = read_context.loopToBeCalled\n  } else {\n    await context('getstartedLoop');\n    loopToBeCalled = 'getstartedLoop'\n  }\n\n//ArrayOfLoops have all conversational loops\n  let ArrayOfLoops = [];\n  ArrayOfLoops.push(new Loop(\n      'getStartedLoop',\n      function() {\n        getStartedLoop(event, context)\n      }\n));\n  ArrayOfLoops.push(new Loop(\n      'likePizza',\n      function() {\n        likePizza(event, context)\n      }\n));\n  ArrayOfLoops.push(new Loop(\n      'dontLikePizza',\n      function() {\n        dontlikePizza(event, context)\n      }\n));\n\nLoop.findCurrentLoop(\n    loopToBeCalled,\n    ArrayOfLoops\n)\n}\n```\n\n\nSend the loopRoutes to chatloop:\n```js\nconst chatloop = require('chatloop');\nconst loopsRoutes = require('./loops/loopsRoutes');\n\nchatloop.Connect(\n    loopsRoutes\n    //The default port is 3000\n    //Can put here any port number you want\n);\n```\n\n\nCreate a /.env file to put config data\n```.env\nPAGE_ACESS_TOKEN = \u003cmessenger page token\u003e\nVERIFICATION = \u003clarge string\u003e\n```\n\n\nUnder Production, you can easily substitute the context \nfunctions for database functions. \n\n\n\n### Functions\n#### Send Functions\n```js\nsend.Text(event.senderId, 'some_text')\nsend.Image(event.senderId, 'url')\nsend.RequestLocation(event.senderId, 'some_text')\nsend.Button(event.senderId, 'some_text', buttons)\nsend.QuickReply(event.senderId, 'some_text', quick_reply)\nsend.GenericTemplate(event.senderId, elements,\n    /*\n    image_aspect_ratio can be:\n    'horizontal' or 'square'\n    default is 'horizontal'\n    */\n    /*\n    sharable \n    default is true\n    */\n)\nsend.ListTemplate(event.senderId, elements,\n    /*\n    top_element_style can be 'large' or 'compact'\n    default is 'large'\n    */\n)\nsend.Typing(event.senderId)\nsend.GetProfileData(event.senderId)\n    /*\n    Returns a promise. The parameters are:\n    first_name, last_name, profile_pic, locale, timezone,\n    gender, is_payment_enabled, last_ad_referral\n    */\nsend.Random(\n    //Will send random between 'text_1' and 'text_2' \n    [\n        function() {\n            send.Text(event.senderId, 'text_1');\n        },\n        function() {\n            send.Text(event.senderId, 'text_2');\n        }\n    ]\n)\n    //the send. funtions became from require('chatloop').Send;\n```\n\n\n#### Messenger Profile API Functions\nThe Messenger Profile API can provide the following features:\n* account_linking_url\n* get_started\n* greeting\n* home_url\n* payment_settings\n* persistent_menu\n* target_audience\n* whitelisted_domains\n\nUsing the MessengerProfileApi function, you can easily access this API.\n\nExample of how to add a Get Started Button  to your Chatbot using Chatloop:\n\nWe want to execute this only one time, so in a new file, just add the following code, changing \u003cGET_STARTED_PAYLOAD\u003e):\n```js\nconst chatloop = require('chatloop');\n\nchatloop.MessengerProfileApi({ \n        \"get_started\":{\n          \"payload\":\"\u003cGET_STARTED_PAYLOAD\u003e\"\n        }\n })\n```\nJust run this file. If it's working, you will find the \"Sending the POST request to the Profile API\" message into the console, and your Button will be available quickly.\n\nTo add any other feature provided by the API , you need to know the correct parameters, it's into the [Facebook developers site](https://developers.facebook.com/docs/messenger-platform/reference/messenger-profile-api)\n\n\n#### Context Functions\n```js\ncontext() \n    //will return the current context\ncontext('someLoop') \n    /*\n    will store {\"loopToBeCalled\": \"likePizzaLoop\"}\n    in a local file\n    */\ncontext(undefined, 'some_position')\n    /* second element are used for some position inside\n    the loop, will store {\"position\": \"not choose a flavor\"}\n    undefined in a parameter results in no change\n    (only in parameter field) \n    */\ncontextDelete()\n    //\"reboot\" the local file\n\n    /*\n    the context functions become from: \n    require('chatloop').Development.context\n\n    contextDelete from: \n    require('chatloop').Development.contextDelete\n    */\n```\n\n\n\n### Examples, Tutorials\n[Build your first Chatbot with Chatloop](https://medium.com/@thalesmdav/build-your-first-chatbot-with-chatloop-ddd21e47e21)\n\n### Contributing\nDid you find a bug? If it is a security vulnerability, please don't open a GitHub issue, instead contact me: thalesmdav@gmail.com\n\nDid you solve a bug, rewrite part of the code, or write a new feature?\nOpen a GitHub pull request.\n\nIf you have never contributed to an open source project, I suggest reading [this article.](https://codeburst.io/a-step-by-step-guide-to-making-your-first-github-contribution-5302260a2940)\n\n### Some issue?\n\nFeel free to open a Github issue. I will really like to help.\n\n\n### License\n\nMIT","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthalesdavila%2Fchatloop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthalesdavila%2Fchatloop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthalesdavila%2Fchatloop/lists"}