Skip to content

Latest commit

 

History

History
87 lines (63 loc) · 2.79 KB

3.md

File metadata and controls

87 lines (63 loc) · 2.79 KB

Create code

TIP: Looking for a good code editor? Check out Notepad++ (Windows) or Atom (Mac)

  1. Copy/paste the code below in your editor
  2. Save the file in the folder you created in the preparation step as "spark_bot.js"
var Botkit = require('botkit');

var controller = Botkit.sparkbot({
    public_address: process.env.public_address,
    ciscospark_access_token: process.env.access_token,
    secret: process.env.secret,
});
var bot = controller.spawn();

// Start Webserver to process incoming webhooks
controller.setupWebserver(process.env.port||3000,function(err,webserver) {
   controller.createWebhookEndpoints(controller.webserver, bot);
});

// Process incoming messages
controller.hears('hello','direct_message,direct_mention', function(bot, message) {
    bot.reply(message, 'Howdy!');
});




Start the Bot code

  • MAC: Run this command that sets the environment variables (non-presistent) and starts the script. In the first terminal window type: access_token=BOT_ACCESS TOKEN public_address=https://xyz.ngrok.io node spark_bot.js

    • replacing BOT_ACCESS_TOKEN with the bot token from the previous step
    • replacing https://xyz.ngrok.io with the unique NGROK URL created in the previous step
  • WINDOWS: Run these commands to set the environment variables (non-persistent) and starts the script. In the first command prompt type:

    First populate the environment variables:
    C:\Documents\Botkit> SET BOT_ACCESS_TOKEN="your_bot_access_token_here" 
    C:\Documents\Botkit> SET PUBLIC_URL="your_unique_ngrok_URL_here" 
    
    Then execute the bot script:
    C:\Documents\Botkit> node spark_bot.js

You should now see the code starting with a message similar to this:

      

NOTE the Starting webserver on port 3000 and SUCCESSFULLY UPDATED CISCO SPARK WEBHOOKS





Test Your Bot

What did we do so far?

  1. Created a Spark Bot account.
  2. Started NGROK to tunnel webhook traffic to our local computer.
  3. Created & started the Bot code.

Let's test our Bot!

  1. Open your Cisco Spark client

  2. Test your bot script by setting up a 1:1 conversation with your bot. Your bot name should be [email protected], example: [email protected]

  3. Send message: hello to your bot Your bot should respond with Howdy!




CONGRATULATIONS! You have a working bot. NOW let's make it smarter!