Getting Started

Deep dive into multichannel

Bot Connector is an API allowing you to connect your bot to several channels simultaneously. TestConnector

Today, we support Slack, Kik, Messenger, Twilio, Telegram and Callr integrations. But many others will soon be added, as the API is open-source! Missing a channel integration? Develop it and implement it. Others will do the same and soon, Bot Connector will be a very powerful tool.

If you already manage API calls and channel integrations like a pro, this tool will be easy to use.

How it works?

When your bot receive a message

IncomingMessage

  1. 1 - When a message is sent to your bot from one of the channels, Bot Connector catches it.
  2. 2 - It turns it into an universal format, the same for every channels, and save it.
  3. 3 - It sends the message to the server where your bot is running

When your bot send a message

IncomingMessage

  1. 1 - You send a message in the universal format (easy to manipulate)
  2. 2 - Bot Connector saves it and converts it to the format supported by the specific channel
  3. 3 - It sends it back to the good sender

How to use it?

We will start by creating a new connector. Once you're logged in Bot Connector, click on the + NEW CONNECTOR button, and follow the steps below.

HomePage

Get your connector url

Your connector will be on a server running online. If you want to do it locally, you can download ngrok and run it on the port you want. Leave the windows running, and use the secured https URL for the next step.

Ngrok

Create your connector

Pick an awesome name for your connector, and fill the url field with the one ngrok generated for you.

Create Bot

Connect a channel

Click on the channel you want to add to open a modal containing steps that will guide you, and a form you'll have to fill to create the connection between your bot and the channel.

Create Channel

Receive and send messages

Now we will build a bot able to receive messages and send back replies.

Open your console and quick-start your project by typing the following commands in your terminal:


$ mkdir myBot && cd myBot
$ npm init -y
$ touch index.js
$ npm install --save recastai express body-parser

We will use the Recast.AI SDK and express, but you can also use koa if you prefer.

Modify the index.js file, so it looks like below.

/* module imports */
var recastai = require('recastai')
var express = require('express')
var bodyParser = require('body-parser')

/* Bot Connector connection */
var connect = new recastai.connect('YOUR_BOT_REQUEST_TOKEN')

/* Server setup */
var app = express()

app.use(bodyParser.json())
app.post('/', function(req, res) {
  connect.handleMessage(req, res, onMessage)
})

// Will be called each time you receive a message
function onMessage(message) {
  // Get the content of the message
  var content = message.content

  // Get the type of the message (text, picture,...)
  var type = message.type

  console.log('A new message has been received: ', content)

  // Set the reply you want to send back...
  message.addReply([{ type: 'text', content: 'Hello world!' }])

  // ... and send it back!
  message.reply()
}

app.listen(5000, () => console.log('Bot running on port', 5000)

Type this command in your terminal...

$ node index.js

...and voila, you have an up and running bot, able to receive messages from the outside world, and to send back super smart responses!

Format message

You can send a lot of different formats of message, from plain text to more elaborated cards. There're some examples below.

1 - Text

BotConnector
const text = {
  type: 'text',
  content: 'my first message',
}