UNPKG

chatbot-constructor

Version:

A chatbot constructor/builder that can help you develop chatbots in no time either using javascript and nodejs or without programming using excel sheet or JSON format. And it can also easily integrate with AI services like LUIS, Watson, Lex, Octane.AI, Wi

78 lines (51 loc) 2.31 kB
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ______ ______ ______ __ __ __ ______ /\ == \ /\ __ \ /\__ _\ /\ \/ / /\ \ /\__ _\ \ \ __< \ \ \/\ \ \/_/\ \/ \ \ _"-. \ \ \ \/_/\ \/ \ \_____\ \ \_____\ \ \_\ \ \_\ \_\ \ \_\ \ \_\ \/_____/ \/_____/ \/_/ \/_/\/_/ \/_/ \/_/ This is a sample Slack Button application that provides a custom Slash command. This bot demonstrates many of the core features of Botkit: * * Authenticate users with Slack using OAuth * Receive messages using the slash_command event * Reply to Slash command both publicly and privately # RUN THE BOT: Create a Slack app. Make sure to configure at least one Slash command! -> https://api.slack.com/applications/new Run your bot from the command line: clientId=<my client id> clientSecret=<my client secret> port=3000 node bot.js Note: you can test your oauth authentication locally, but to use Slash commands in Slack, the app must be hosted at a publicly reachable IP or host. # EXTEND THE BOT: Botkit has many features for building cool and useful bots! Read all about it here: -> http://howdy.ai/botkit ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ var Botkit = require('../lib/Botkit.js'); if (!process.env.clientId || !process.env.clientSecret || !process.env.port) { console.log('Error: Specify clientId clientSecret and port in environment'); process.exit(1); } var controller = Botkit.slackbot({ json_file_store: './db_slackbutton_slashcommand/', }).configureSlackApp({ clientId: process.env.clientId, clientSecret: process.env.clientSecret, scopes: ['commands'], }); controller.setupWebserver(process.env.port,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!'); } }); }); controller.on('slash_command',function(bot,message) { bot.replyPublic(message,'<@' + message.user + '> is cool!'); bot.replyPrivate(message,'*nudge nudge wink wink*'); });