Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
if (!process.env.slack) {
console.log('Error: Specify slack API token in environment');
process.exit(1);
}
if (!process.env.dialogflow) {
console.log('Error: Specify dialogflow in environment');
process.exit(1);
}
const Botkit = require('botkit');
const slackController = Botkit.slackbot({
debug: true,
});
const slackBot = slackController.spawn({
token: process.env.slack,
});
const dialogflowMiddleware = require('../')({
keyFilename: process.env.dialogflow,
});
slackController.middleware.receive.use(dialogflowMiddleware.receive);
slackBot.startRTM();
/* note this uses example middlewares defined above */
slackController.hears(['hello-intent'], 'direct_message', dialogflowMiddleware.hears, function(
console.log('Error: Specify token in environment');
process.exit(1);
}
if (!process.env.wit) {
console.log('Error: Specify wit in environment');
process.exit(1);
}
var Botkit = require('botkit');
var wit = require('./src/botkit-middleware-witai')({
token: process.env.wit,
});
var controller = Botkit.slackbot({
debug: true,
});
var bot = controller.spawn({
token: process.env.token
}).startRTM();
controller.middleware.receive.use(wit.receive);
/* note this uses example middlewares defined above */
controller.hears(['hello'], 'direct_message,direct_mention,mention', wit.hears, function(bot, message) {
bot.reply(message, 'Hello!');
});
var Botkit = require('botkit')
var Witbot = require('../')
var slackToken = process.env.SLACK_TOKEN
var witbot = Witbot(process.env.WIT_TOKEN)
var controller = Botkit.slackbot({ debug: false })
controller.spawn({ token: slackToken }).startRTM(function (err, bot, payload) {
if (err) throw new Error('Error connecting to Slack: ', err)
console.log('Connected to Slack')
})
// wire up DMs and direct mentions to wit.ai
controller.hears('.*', 'direct_message,direct_mention', function (bot, message) {
var wit = witbot.process(message.text, bot, message)
wit.hears('hello', 0.53, function (bot, message, outcome) {
bot.startConversation(message, function (_, convo) {
convo.say('Hello!')
convo.ask('How are you?', function (response, convo) {
witbot.process(response.text)
.hears('good', 0.5, function (outcome) {
constructor (config) {
this.config = config;
this.controller = Botkit.slackbot({
stats_optout: true,
logger: logger
});
this.responded = new Map();
this.lookup = new Map();
this.manualClose = false;
this.autoMarkJob = null;
this.autoMarkChannels = new Map();
this.nextAnnounce = null; // timeout pointer
this.stats = {
responses: 0, // number of responses
users: new Set(), // list of users responded to
// modified version of https://raw.githubusercontent.com/howdyai/botkit/master/examples/slack/slackbutton_bot.js
/* Uses the slack button feature to offer a real time bot to multiple teams */
var Botkit = require('botkit');
require('dotenv').load();
var controller = Botkit.slackbot({
json_file_store: './db_slackbutton_bot/'
}).configureSlackApp(
{
clientId: process.env.SLACK_CLIENT_ID,
clientSecret: process.env.SLACK_CLIENT_SECRET,
scopes: ['bot']
}
);
controller.setupWebserver(3000, function (err, webserver) {
controller.createWebhookEndpoints(controller.webserver);
controller.createOauthEndpoints(controller.webserver, function (err, req, res) {
if (err) {
res.status(500).send('ERROR: ' + err);
} else {
res.send('Success!');
const Botkit = require('botkit')
const token = process.env.SLACK_TOKEN
const controller = Botkit.slackbot({
// reconnect to Slack when connection goes bad
retry: Infinity,
debug: false,
})
controller.spawn({
token,
// eslint-disable-next-line no-unused-vars
}).startRTM((err, bot, payload) => {
if (err) {
throw new Error('Could not connect to Slack')
}
})
controller.on('bot_channel_join', (bot, message) => {
bot.reply(message, 'I\'m here!')
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const Botkit = require('botkit');
const controller = Botkit.slackbot({ clientSigningSecret: process.env.SLACK_SIGNING_SECRET });
const bot = controller.spawn({
token: process.env.SLACK_TOKEN
});
controller.hears(['.*'], ['direct_message', 'direct_mention', 'mention'], async (bot, message) => {
if (message.watsonError) {
console.log(message.watsonError);
bot.reply(message, message.watsonError.description || message.watsonError.error);
} else if (message.watsonData && 'output' in message.watsonData) {
bot.reply(message, message.watsonData.output.text.join('\n'));
} else {
console.log('Error: received message in unknown format. (Is your connection with Watson Assistant up and running?)');
bot.reply(message, 'I\'m sorry, but for technical reasons I can\'t respond to your message');
}
});
/*-----------------------------------------------------------------------------
A bot for managing a users to-do list. See the README.md file for usage
instructions.
-----------------------------------------------------------------------------*/
var Botkit = require('botkit');
var builder = require('../../');
var index = require('./dialogs/index')
var controller = Botkit.slackbot();
var bot = controller.spawn({
token: process.env.token
});
var slackBot = new builder.SlackBot(controller, bot);
slackBot.add('/', index);
slackBot.listenForMentions();
bot.startRTM(function(err,bot,payload) {
if (err) {
throw new Error('Could not connect to Slack');
}
});
configure: function (token, config, onInstallation) {
var controller = Botkit.slackbot(config);
var bot = controller.spawn({
token: token
});
bot.startRTM(function (err, bot, payload) {
if (err) {
die(err);
}
if(onInstallation) onInstallation(bot);
});
constructor(config, logger = console) {
this.config = config;
this.logger = logger;
const slackLogger = {
log: (level, ...other) => (logger[level] || _.noop)(...other),
};
this.controller = Botkit.slackbot({
logger: slackLogger,
logLevel: process.env.LOG_LEVEL,
});
this.bot = this.controller.spawn({ token: process.env.SLACK_TOKEN });
this.emitter = new EventEmitter();
this.startRtm();
this.setupCallbacks();
}