Skip to content
This repository has been archived by the owner on Nov 26, 2019. It is now read-only.

Channel Slack

Jerome Houdan edited this page Apr 3, 2017 · 12 revisions

Set up your Slack account

Create a Slack App

Create a new Slack app using this link. Slack app credentials Fill the form with your App Name and your Development Slack Team name. If you don't have a team yet, create one. Slack app credentials

Get your credentials

Go to Settings > Basic Information, scroll down and coy your Client Id and Client Secret available on the App Credentials section. Slack app credentials

Add a new bot user

In the Bot Users tab, create a new bot user. tabs slack app

Now you can run your Bot Connector locally, and make a request with your Client ID and your Client Secret available on the App Credentials section.

Set the OAuth redirect URL

In the OAuth & Permission tab, fill the Redirect URL with the OAuth URL of your channel. tabs slack app

Enable interactive messages

In the Interactive Messages tab, enable and fill the Request URL with the Events URL of your channel. tabs slack app

Fill the Events redirect URL

In the Event Subcription tab, enable and fill the Request URL with the Events URL of your channel. tabs slack app Scroll down to the Subcribe to Bot Events section, and enable the following events:

  • message.channels
  • message.im tabs slack app

Start your bot in local

Ngrok

  • Download on your computer the appropriate version of Ngrok
  • Open a new tab in your terminal:
./ngrok http 8080
  • Copy past the https://*******ngrok.io you get, you will need it for the next step
  • Leave your Ngrok serveur running

Start Connector in local

  • Clone and install Connector
$ git clone https://github.com/RecastAI/bot-connector.git
$ cd bot-connector
$ yarn install
$ yarn start-dev
  • Create your connector
$ curl -X POST "http://localhost:8080/connectors/" --data "url=connector_url"
  • Create your channel
$ curl -X  POST \
  --data "slug=YOUR_CHANNEL_SLUG" --data "isActivated=true" --data "type=kik" \
  --data "apiKey=YOUR_API_KEY" --data "webhook=YOUR_NGROK_URL" --data "userName=YOUR_BOT_NAME" \
  "http://localhost:8080/connectors/:connector_id/channels"

Your bot

A small example of bot:

 import express from 'express'
 import bodyParser from 'body-parser'
 import request from 'superagent'
 
 const app = express()
 app.set('port', process.env.PORT || 5000)
 app.use(bodyParser.json())
 
 const config = { url: 'http://localhost:8080', connectorId: 'yourConnectorId' }
 
   /* Get the request from the connector */
 
 app.post('/', (req, res) => {
   const conversationId = req.body.message.conversation
   const messages = [{
     type: 'text',
     content: 'my first message',
   }]
 
   /* Send the message back to the connector */
   request.post(`${config.url}/connectors/${config.connectorId}/conversations/${conversationId}/messages`)
     .send({ messages, senderId: req.body.senderId })
     .end((err, res) => {
       if (err) {
         console.log(err)
       } else {
         console.log(res)
       }
     })
 })
 
 app.listen(app.get('port'), () => {
   console.log('Our bot is running on port', app.get('port'))
 })
Clone this wiki locally