{"id":15368008,"url":"https://github.com/anonrig/sourcebot","last_synced_at":"2025-04-15T12:52:45.702Z","repository":{"id":57366517,"uuid":"66973209","full_name":"anonrig/sourcebot","owner":"anonrig","description":"SourceBot is a platform independent bot framework","archived":false,"fork":false,"pushed_at":"2018-02-19T11:38:49.000Z","size":52,"stargazers_count":15,"open_issues_count":6,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-28T20:23:53.467Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/anonrig.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-30T19:57:20.000Z","updated_at":"2024-10-02T12:25:40.000Z","dependencies_parsed_at":"2022-08-23T19:40:38.916Z","dependency_job_id":null,"html_url":"https://github.com/anonrig/sourcebot","commit_stats":null,"previous_names":["sourcebot/sourcebot"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anonrig%2Fsourcebot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anonrig%2Fsourcebot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anonrig%2Fsourcebot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anonrig%2Fsourcebot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anonrig","download_url":"https://codeload.github.com/anonrig/sourcebot/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248309259,"owners_count":21082178,"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":[],"created_at":"2024-10-01T13:27:42.330Z","updated_at":"2025-04-15T12:52:45.684Z","avatar_url":"https://github.com/anonrig.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![SourceBot Framework](https://avatars0.githubusercontent.com/u/21346235?v=3\u0026s=200)\n\nSourceBot\n==\n\n[![David](https://img.shields.io/david/sourcebot/sourcebot.svg)](https://david-dm.org/sourcebot/sourcebot)\n[![Code Climate](https://codeclimate.com/github/sourcebot/sourcebot/badges/gpa.svg)](https://codeclimate.com/github/sourcebot/sourcebot)\n[![Build Status](https://travis-ci.org/sourcebot/sourcebot.svg?branch=master)](https://travis-ci.org/sourcebot/sourcebot)\n[![Coverage Status](https://coveralls.io/repos/github/sourcebot/sourcebot/badge.svg)](https://coveralls.io/github/sourcebot/sourcebot)\n[![Greenkeeper badge](https://badges.greenkeeper.io/sourcebot/sourcebot.svg)](https://greenkeeper.io/)\n\n\nSourceBot is a platform independent chat bot framework. It aims to connect Facebook Messenger, Slack and Skype with the same code.\n\nBenefits of SourceKit:\n- Uses EcmaScript 6 class architecture.\n- Easily debuggable.\n- Uses Promises, catches uncaught exceptions on the way.\n\nIn order to install:\n\n```\nnpm install sourcebot --save\n```\n\nIn order to debug (Example):\n```\nDEBUG=* node index.js\n```\n* For Windows: Before running the app, run this command in order to debug: ```set Debug=slack:core,slack:websocket,slack:conversation```\n\n[![sourcebot_cmd.jpg](https://s14.postimg.org/o7rf82ki9/sourcebot_cmd.jpg)](https://postimg.org/image/bt4n7qszx/)\n\nExamples\n==\n\n### Typical 'hello world':\n\n```javascript\nlet SlackCore = require('sourcebot').Slack;\nlet SlackBot = new SlackCore({\n  token: 'xoxb-17065016470-0O9T0P9zSuMVEG8yM6QTGAIB'\n});\n\n\nSlackBot\n  .connect()\n  .then((bot) =\u003e {\n    bot\n      .listen('hello', (response) =\u003e {\n        bot.send({\n          channel: response.channel,\n          text: 'world'\n        });\n      })\n  })\n  .catch((err) =\u003e console.error(err.message))\n```\n\n### An example conversation:\n\n```javascript\nSlackBot\n  .connect()\n  .then((bot) =\u003e {\n    bot\n      .listen(new RegExp('start convo', 'i'), (response) =\u003e {\n\n        bot\n          .startConversation(response.channel, response.user)\n          .then((conversation) =\u003e {\n            return conversation\n              .ask('How are you?')\n              .then((reply) =\u003e {\n                return conversation\n                  .say('Good!')\n                  .then(() =\u003e {\n                    return conversation.ask('What are you doing now?')\n                  })\n                  .then((response) =\u003e {\n                    return conversation.askSerial(['What?', 'Where?', 'When?']);\n                  })\n              })\n          });\n      })\n  }).catch((err) =\u003e console.error(err.message));\n```\n\n### An example private conversation\n\n\n```javascript\nSlackBot\n  .connect()\n  .then((bot) =\u003e {\n    bot\n      .listen(new RegExp('start convo', 'i'), (response) =\u003e {\n        bot\n          .startPrivateConversation(response.user)\n          .then((conversation) =\u003e {\n            conversation\n              .ask('Hello world')\n              .then((response) =\u003e {\n                conversation.say('You said ' + response.text);\n              })\n          })\n      })\n  }).catch((err) =\u003e console.error(err.message));\n\n```\n\n### Query Slack's API\n\n```javascript\nSlackBot\n  .connect()\n  .then((bot) =\u003e {\n    bot\n      .listen(new RegExp('start convo', 'i'), (response) =\u003e {\n\n        SlackBot\n          .requestSlack()\n          .getChannelInfo(response.channel)\n          .then((channelInfo) =\u003e {\n            bot.send({\n              channel: response.channel,\n              text: 'Wow, wow, wow! We have ' + channelInfo.channel.members.length + ' users in here!'\n            });\n\n            const tasks = channelInfo.channel.members.map((member) =\u003e {\n              return SlackBot.requestSlack().getUserInfo(member)\n            });\n\n            Promise\n              .all(tasks)\n              .then((users) =\u003e {\n                users.forEach((item) =\u003e {\n                  bot.send({\n                    channel: response.channel,\n                    text: 'Welcome \u003c@' + item.user.id +'|' + item.user.name +'\u003e, I\\'ve missed you!'\n                  });\n                })\n              })\n          })\n      })\n  }).catch((err) =\u003e console.error(err.message));\n```\n\n#### Ask series of questions\n\n\n\n```javascript\nSlackBot\n  .connect()\n  .then((bot) =\u003e {\n    bot\n      .listen(new RegExp('start convo', 'i'), (response) =\u003e {\n\n        bot\n          .startConversation(response.channel, response.User)\n          .then((conversation) =\u003e {\n            return conversation\n              .askSerial([\n                {\n                  text: 'How are you?',\n                  replyPattern: new RegExp('\\\\bfine\\\\b', 'i') //Asks until the given response contains 'fine'.\n                },\n                {\n                  text: 'Where are you?',\n                  replyPattern: new RegExp('\\\\bistanbul\\\\b', 'i'),\n                  callback: (faultyReply) =\u003e { //Fires up if the response does not contain 'istanbul'.\n                    return conversation.say('Please indicate your city.');\n                  }\n                }\n              ]).then((responses) =\u003e {\n                console.log(responses);\n              });\n          });\n      })\n  }).catch((err) =\u003e console.error(err.message));\n```\n\n\n\nMethods\n===\n#### SlackBot\n* ```constructor(opts)```\n   * Constructs the SlackCore class with ```opts.token```\n   * If ```opts.debug``` is defined, SlackBot will enter in debug mode.\n* ```connect()```\n   * Connects to Slack Web API\n* ```requestSlack()```\n   * Returns Slack API endpoint.\n        * ```rtmStart()```\n        * ```getChannelInfo(channelId)```\n        * ```getUserInfo(userId)```\n        * ```openDirectMessageChannel(userId)```\n\n#### Bot\n* ```listen(message, callback)```\n  * Listens for the message. The message can be an instance of RegExp or a plain String. Returns promise containing the response.\n* ```send(opts)```\n  * Sends a message to specified channel, Takes ```opts``` object as a parameter containing text and channel fields. Returns empty promise.\n* ```startConversation(channelName, userId)```\n  * Starts a conversation with the specified user in a specified channel. Takes user's slack id and the id of the channel. Returns promise containing a ```conversation``` object.\n* ```startPrivateConversation(user)```\n  * Starts private conversation between a user. Returns promise containing a ```conversation``` object.\n* ```disconnect()```\n  * Disconnects and removes all event listeners.\n\n#### Conversation\n* ```ask(opts||message, callback)```\n  * Sends the given ```opts``` Object or  ```question``` String and waits for a response. If ```opts.replyPattern``` is provided asks until the RegExp test succeeds, fires callback upon faulty replies with the ```faultyReply```. Returns a promise containing the ```response```.\n  * ```let opts = {text: 'Question', replyPattern: new RegExp('')}```\n* ```say(message)```\n  * Sends the given String ```message```. Returns empty promise.\n* ```askSerial(opts)```\n  * Behaves same as ```ask()``` but this method takes an array of objects that are asked sequentially.\n```javascript\nlet opts = {\n   text: 'Question',\n   replyPattern: new RegExp(''),\n   callback: (faultyReply) =\u003e {\n     return Promise.resolve()\n   }\n }\n```\n\n\nThe MIT License\n===\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanonrig%2Fsourcebot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanonrig%2Fsourcebot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanonrig%2Fsourcebot/lists"}