I am starting slack development with node. Following a tutorial I got an error message . I tried several sources but I still cannot spot my mistake
I am simply trying to print the bot and channel names
the version of node installed is 10 however the examples are based on version 5
could that be the source of the error?
'use strict';
const RtmClient = require('@slack/client').RtmClient;
const MemoryDataStore = require('@slack/client').MemoryDataStore;
const RTM_EVENTS = require('@slack/client').RTM_EVENTS;
const CLIENT_EVENTS = require('@slack/client').CLIENT_EVENTS;
const token = 'myTokenGoesHere';
let slack = new RtmClient(token, {
logLevel: 'debug',
dataStore: new MemoryDataStore(),
autoReconnect: true,
autoMark: true});
slack.on(CLIENT_EVENTS.RTM.RTM_CONNECTION_OPENED, () => {
// Get the user's name
let user = slack.dataStore.getUserById(slack.activeUserId);
// Get the team's name
let team = slack.dataStore.getTeamById(slack.activeTeamId);
// Log the slack team name and the bot's name, using ES6's
// template
// string syntax
console.log(`Connected to ${team.name} as ${user.name}`);
});
// Start the login process
slack.start();
I get this error message
> TypeError: MemoryDataStore is not a constructor
> at Object.<anonymous> (C:\Users\ToughBook\appdir\index.js:33:16)
> at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at startup (internal/bootstrap/node.js:282:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)
Use version 2 of the slack client if you really want to follow the tutorials in the book by Paul. Also, Visit https://your-workspace.slack.com/apps/new/bot-name to get API token but make sure you have a slack workspace already.
"dependencies": {
"@slack/client": "^2.1.0"
}