This repository has been archived by the owner on Nov 26, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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')) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
] | ||
} | ||
} |