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

Commit

Permalink
[ADD] examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoudan committed Nov 24, 2016
1 parent 14b5722 commit b967053
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
34 changes: 34 additions & 0 deletions example/bot.js
@@ -0,0 +1,34 @@
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', botId: 'yourBotId' }

/* Get the request from the connector */

app.post('/', (req, res) => {
const conversationId = req.body.message.conversation
const message = [{
type: 'text',
content: 'my first message',
}]

/* Send the message back to the connector */
request.post(`${config.url}/bots/${config.botId}/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'))
})
27 changes: 27 additions & 0 deletions example/package.json
@@ -0,0 +1,27 @@
{
"name": "bot-example",
"version": "1.0.0",
"description": "",
"main": "bot.js",
"scripts": {
"start": "node ./node_modules/babel-cli/bin/babel-node.js bot.js"
},
"dependencies": {
"body-parser": "^1.15.2",
"express": "^4.14.0",
"superagent": "^2.3.0"
},
"devDependencies": {
"babel-cli": "^6.11.4",
"babel-eslint": "^6.1.2",
"babel-preset-es2015": "^6.9.0",
"babel-preset-stage-0": "^6.5.0",
"babel-register": "^6.11.5"
},
"babel": {
"presets": [
"es2015",
"stage-0"
]
}
}

0 comments on commit b967053

Please sign in to comment.