Each bot needs its own API key for tracking.
Create a bot to get an API key.
npm install --save dashbot
Use the API key created above.
const dashbot = require('dashbot')(process.env.DASHBOT_API_KEY).slack;
request('https://slack.com/api/rtm.start?token=' + process.env.SLACK_BOT_TOKEN, (error, response) => {
const parsedData = JSON.parse(response.body);
// Tell Dashbot when you connect.
<strong>dashbot.logConnect(parsedData);</strong>
const bot = parsedData.self;
const team = parsedData.team;
...
})
connection.on('message', (message) => {
const parsedMessage = JSON.parse(message.utf8Data);
// Tell Dashbot when a message arrives
<strong>dashbot.logIncoming(bot, team, parsedMessage);</strong>
})
const reply = {
type: 'message',
text: 'You are right when you say: ' + parsedMessage.text,
channel: parsedMessage.channel
};
// Tell Dashbot about your response
<strong>dashbot.logOutgoing(bot, team, reply);</strong>
connection.sendUTF(JSON.stringify(reply));
See a complete example.