├── package.json └── index.js /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "slack-bot", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "giphy-api": "^2.0.1", 14 | "slackbots": "^1.2.0" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const SlackBot = require('slackbots'); 2 | const giphy = require('giphy-api')(); 3 | 4 | // create a bot 5 | const bot = new SlackBot({ 6 | token: 'xoxb-488895620903-488687064627-wC9i7hASCu0YlnCOAUgjdsHQ', // One day this should be hidden 7 | name: 'Robutt', 8 | }); 9 | 10 | bot.on('start', () => { 11 | // more information about additional params https://api.slack.com/methods/chat.postMessage 12 | const params = { 13 | icon_emoji: ':cat:', 14 | }; 15 | 16 | // define channel, where bot exist. You can adjust it there https://my.slack.com/services 17 | bot.postMessageToChannel('botwars', 'meow!', params); 18 | 19 | // define existing username instead of 'user_name' 20 | bot.postMessageToUser('user_name', 'meow!', params); 21 | 22 | // If you add a 'slackbot' property, 23 | // you will post to another user's slackbot channel instead of a direct message 24 | bot.postMessageToUser('user_name', 'meow!', { slackbot: true, icon_emoji: ':cat:' }); 25 | 26 | // define private group instead of 'private_group', where bot exist 27 | bot.postMessageToGroup('private_group', 'meow!', params); 28 | 29 | // bot.getChannel('botwars').then(({ members }) => { 30 | // members.map((member) => { 31 | // bot.postMessage(member, 'Hello, world :)'); 32 | // return member; 33 | // }); 34 | // }); 35 | bot.on('message', (data) => { 36 | if (data.text === undefined) { 37 | return; 38 | } 39 | // all ingoing events https://api.slack.com/rtm 40 | /* 41 | setTimeout(() => { 42 | giphy.random(data.text, (err, res) => { 43 | bot.postMessageToChannel('botwars', `${res.data.url} ${data.text} du cul`, params); 44 | }); 45 | }, 3000); 46 | */ 47 | console.log(data); 48 | if (data.text.includes('Robutt')) { 49 | console.log(data.text.includes('Robutt')); 50 | const subString = data.text.replace('Robutt', ''); 51 | giphy.random(subString, (err, res) => { 52 | if (res || res.data) { 53 | bot.postMessageToChannel(data.channel, `${res.data.url} ${subString} du cul`, params); 54 | } 55 | }); 56 | } 57 | }); 58 | }); 59 | --------------------------------------------------------------------------------