This repository has been archived by the owner on Nov 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 101
Channel Twitter
Jerome Houdan edited this page Jun 28, 2017
·
2 revisions
The Twitter's Account Activity API is still currently in beta. Once you have created your app, ask Twitter for access using this form. The process can take a few days.
Go on Twitter App and click on Create New App.
Fill in the Name, Description and Website fields, and leave the Callback URL empty.
Important: the Twitter's Direct message API is still in beta, ask them for access using this form. The process can take a few days.
Go in the Permissions tab of your application, and enable Read, Write and Access direct messages.
Go in the Keys and Access Tokens tab of your application, and click on Create your Access Token.
Get your Consumer Key, Consumer Secret, Access Token and Access Token Secret and fill in the form below.
- 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 "type=twitter" \
--data "consumerKey=TWITTER_CONSUMER_KEY" --data "consumerSecret=TWITTER_CONSUMER_SECRET" \
--data "accessToken=TWITTER_ACCESS_TOKEN" --date "accessTokenSecret=TWITTER_ACCESS_TOKEN_SECRET" \
"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'))
})