Make a bot for Chatlio

You can add bots to all visitor conversations on Chatlio. Here is how to add them:

  1. Open the Chatlio dashboard.
  2. Select the widget for which you would like setup an Integration.
  3. Select the Integrations tab.

The sky is the limit what you can use this for, but here is a sample bot that listens for search term(s) in strings and then responds to visitors with response if term was found in visitor message.

The example below was written in nodejs, but could be done in any language.

// pass in your bot token from ENV variable when start node.
// Create your bot and get token here. https://slack.com/apps/manage/custom-integrations
// eg. SLACK_BOT_TOKEN=<your bot's token> server.js
var botToken = process.env.SLACK_BOT_TOKEN;

// change me
// to get bot_id, go to https://api.slack.com/methods/users.list/test look for @chatlio bot_id
var chatlioBotID = "B12MTP71A"; // replace this value found using api call above

var RtmClient = require('@slack/client').RtmClient;
var RTM_EVENTS = require('@slack/client').RTM_EVENTS;

var rtm = new RtmClient(botToken);

// If users says <key>, return the <value> to them.
// eg. How can I reset password?, bot sends => To reset your password....
var botResponses = {
  "pricing": "Here is a link to our pricing page. https://yoursite.com/#pricing",
  "reset password": "To reset your password, go to the sign in page and follow instructions."
}

// Docs for lib https://slackapi.github.io/node-slack-sdk/
// rtm client docs https://slackapi.github.io/node-slack-sdk/reference/RTMClient
rtm.on(RTM_EVENTS.MESSAGE, function handleRtmMessage(message) {
  // Check if message is from @chatlio bot (visitor messages), if not ignore it.
  if (message.bot_id === chatlioBotID) {  (not user id)
    var keys = Object.keys(botResponses);
    keys.forEach(function(key) {
      if (message.text && message.text.includes(key)) {
        rtm.sendMessage(botResponses[key], message.channel);
        return; // feature or bug? If this matches 2..n strings, it returns 2..n responses to visitor
      }
    });
  }
});

rtm.start();

It listens for all messages from visitors, and responds to any term that is matched. Example:



Running this app

Running locally assuming you have node/npm installed

mkdir chatlio-bots
cd chatlio-bots
npm init
npm install @slack/client --save
touch server.js # add content from file above, changing chatlio bot id as described in above
# create bot here https://slack.com/apps/manage/custom-integrations and note bot token
# to run locally
SLACK_BOT_TOKEN=<bot token created earlier> node server.js

There are many, many different ways to deploy a node js app, but one of the easiest is to deploy to fly.io. We won’t go into detail here how to deploy to fly.io, but if you do, deploy it as a worker, no web access needed.

Let us know in chat window below if you have questions about this or would like more info!

Happy botting!

:(
Your browser is out-of-date!

This website is built using latest technogies. Unfortunately your browser doesn't support those. Please update your browser to view this website correctly. Thank you.Update my browser now