-
Notifications
You must be signed in to change notification settings - Fork 101
Channel Slack
Create a new Slack app using this link. Fill the form with your App Name and your Development Slack Team name. If you don't have a team yet, create one.
Go to Settings > Basic Information, scroll down and coy your Client Id and Client Secret available on the App Credentials section.
In the Bot Users tab, create a new bot user.
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.
In the OAuth & Permission tab, fill the Redirect URL with the OAuth URL of your channel.
In the Interactive Messages tab, enable and fill the Request URL with the Events URL of your channel.
In the Event Subcription tab, enable and fill the Request URL with the Events URL of your channel. Scroll down to the Subcribe to Bot Events section, and enable the following events:
- message.channels
- message.im
- 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
- 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"
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'))
})