O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Building Bots with Node.js

Book Description

Automate workflow and internal communication processes and provide customer service without apps using messaging and interactive bots

About This Book

  • Create interactive bots on platforms such as Facebook Messenger, Kik, Telegram, and Skype to automate workflows
  • Create a bot that works with SQL Server and Skype to deal with HR requests within a company
  • Work with some of the most cutting-edge and widely-used APIs and messaging platforms to create interactive customer-facing experiences and automate work

Who This Book Is For

This is a book for Node.js developers who want to build powerful bots for customer-facing and internal workflow automation.

What You Will Learn

  • Create a bot template that responds to e-mails based on certain ruling criteria
  • Interact with SMS and perform some basic Natural Language Processing using the Twilio API for Node.js
  • Work with the Skype Web SDK and Node.js to create a bot that works with SQL Server and Skype
  • Build an automated Flight Information Agent bot using the Twitter and Air France KLM APIs
  • Create a scheduling bot for teams using the Facebook Messenger API
  • Interact with BotKit along with and MongoDB Amazon S3 to create a document management bot in Node.js
  • Leverage ICR and Azure Table Storage from Node.js to create a bug tracking bot
  • Integrate Force.com API and Kik to create a Salesforce CRM bot

In Detail

The bots are taking over and we're all for it! Messenger-based bots will be the dominant software UI for the next generation of applications — even Slack, Telegram, and Facebook are driving a new approach where "threads are the new apps."

This book shows you how to create work automation bots that interact with users through Slack, e-mail, Skype, Twitter, and more using Node.js. You'll learn to create conversational UIs for your Node.js apps, and then use those UIs to provide workflow automation tools.

You will be shown how to handle customer service requests that come in through messenger systems — this includes interpreting the natural language to reveal the user's intent and respond accordingly. You will also learn how to automate processes that involve several people, such as processing holiday requests, arranging meetings, or sending updated reports on time.

By the end of this book you'll have the knowledge to create bots that can handle and manipulate documents, URLs, and other items of content. Harness the power of bots and your organization will reap the benefits.

Style and approach

This fast-paced book is packed with real-world use cases that will help you understand concepts, issues, and solutions while using Node.js to build useful, cross-platform business bots.

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

Table of Contents

  1. Building Bots with Node.js
    1. Building Bots with Node.js
    2. Credits
    3. About the Authors
    4. About the Reviewer
    5. www.PacktPub.com
      1. Why subscribe?
    6. Customer Feedback
    7. Preface
      1. What this book covers 
      2. What you need for this book 
      3. Who this book is for 
      4. Conventions 
      5. Reader feedback
      6. Customer support
        1. Downloading the example code 
        2. Downloading the color images of this book
        3. Errata
        4. Piracy
        5. Questions
    8. 1. The Rise of Bots – Getting the Message Across
      1. Why bots matter and why you should get on the train
      2. Why SMS still matters
      3. Twilio as an SMS platform
        1. Installing Twilio for Node.js
        2. Setting up a Twilio account
        3. Bare-bones Twilio Node.js template
      4. Core bot functionality on Azure
      5. Receiving SMS bot logic
      6. Summary
    9. 2. Getting Skype to Work for You
      1. How a Skype bot works
        1. Wiring up our Skype bot
        2. Registering our Skype bot app
        3. HR Skype bot agent
      2. Azure table storage as a backend
        1. HR agent guidelines
        2. Accessing the Azure table through code
        3. HR agent bot logic
      3. Summary
    10. 3. Twitter as a Flight Information Agent
      1. How a Twitter bot works
      2.  Creating a Twitter app
      3. Posting to Twitter
      4. Listening to tweets
      5. Replying to who tweeted
      6. Flight APIs
        1. Flight status API
        2. Route search API
        3. Adding a REST client library
      7. Making the bot a bit smarter
      8. Summary
    11. 4. A Slack Quote Bot
      1. Getting started
      2. Registering a bot on Slack
      3. Setting up our Node.js app
      4. Slackbots library basics
      5. The They Said So API
      6. Summary
    12. 5. Telegram-Powered Bots
      1. How a Telegram bot works
        1. Setting up a Telegram account
        2. Setting up a bot account using a Telegram bot - @BotFather
        3. What is sentiment analysis?
        4. Creating a Telegram bot
        5. Conversations with our basic Telegram bot
        6. Building a sentiment analysis bot
      2. Summary
    13. 6. BotKit – Document Manager Agent for Slack
      1. Setting up a Slack for your team
        1. Setting up a Slack bot
        2. Botkit and Slack
        3. Creating our first Slack bot using Botkit and Node.js
        4. Enhancing our DocMan bot
          1. What is MongoDB?
          2. MongoDB database for our DocMan bot
            1. MongoDB shell
            2. Create a database
            3. Create a reference documents collection
            4. Create data for our DocMan bot
            5. Indexing for search
            6. Search query
          3. What is MongoJS?
          4. Wiring up DocMan bot with MongoDB
          5. Amazon S3 storage
            1. Amazon S3 console
            2. Create buckets
            3. Store documents in the bucket
          6. Mark documents as public
          7. Update MongoDB data with Amazon S3 document links
          8. Wiring it all up together
          9. Code understanding
      2. Summary
    14. 7. Facebook Messenger Bot, Who's Off – A Scheduler Bot for Teams
      1. Setting up our Facebook Messenger bot
        1. The Facebook Page for our basic bot
        2. Creating a Facebook app for our basic bot
        3. Setting up our bot server in Azure
          1. Setting up a local git repository for our bot server in Azure
          2. Modifying our bot program for Facebook verification
          3. Setting up a Webhook and Facebook verification of our bot program
          4. Deploying a modified bot that returns an echo
          5. Troubleshooting our bot in Azure
        4. Enhancing our Who's Off bot
          1. Building a conversational experience with the Who's Off bot
            1. Setting up a Messenger greeting
            2. Showing the initial options of what a bot can do
          2. What is DocumentDB?
          3. Setting up a DocumentDB for our Who's Off bot
            1. Creating an account ID for the DocumentDB
            2. Creating a collection and database
          4. Wiring up DocumentDB, Moment.js, and Node.js
            1. Utility functions and Node.js
            2. Wiring it all up together
          5. Running our bot - the Who's Off bot
            1. Initial options
            2. Scheduling a meeting
            3. Whos Off When
      2. Summary
    15. 8. A Bug-Tracking Agent for Teams
      1. IRC client and server
        1. IRC web-based client
      2. IRC bots
        1. Creating our first IRC bot using IRC and Node.js
        2. Code understanding of our basic bot
        3. Enhancing our BugTrackerIRCBot
          1. What is DocumentDB?
          2. Setting up a DocumentDB for our BugTrackerIRCBot
            1. Create account ID for DocumentDB
            2. Create a collection and database
            3. Create data for our BugTrackerIRCBot
          3. Wiring up DocumentDB and Node.js
          4. Wiring up all of this together
          5. Code understanding
        4. Running our enhanced BugTrackerIRCBot
      3. Summary
    16. 9. A Kik Salesforce CRM Bot
      1. What is Salesforce?
      2. What is Force.com?
      3. Kik mobile app
      4. Kik bots
      5. Our Kik bot
        1. Creating our first Kik bot
          1. Using the Kik dev platform on a browser
          2. Using the Kik app from a mobile
          3. Setting up our bot server in Azure
          4. Kik bot configuration
          5. Wiring up our bot server with the Kik platform
        2. Understanding the code of our basic Kik bot
        3. Running our basic Kik bot
        4. Enhancing our Kik bot
          1. Salesforce and our bot
            1. Security token to access the Salesforce API
          2. Wiring it up all together
          3. Understanding the code
        5. Running our enhanced Kik Salesforce bot
      6. sforcebot for campaign management
      7. Summary